ModelScope Gallery OpenAPI
When to use
Use this skill when a user wants to:
- Upload a local file to ModelScope OpenAPI
- Create a gallery item from uploaded file IDs
- Get reusable curl commands for gallery publishing
Required inputs
MS_TOKEN: ModelScope Bearer token, format likems-xxxxxOWNER: gallery owner nameNAME: gallery nameFILE_PATH: local file path to upload
API summary
1) Upload file
- URL:
https://modelscope.cn/openapi/v1/files/upload - Method:
POST - Form field:
file(required): file object, max 5 MB
Expected response shape:
{
"success": true,
"request_id": "...",
"data": {
"id": "uploaded-file-id"
}
}
2) Create gallery
- URL:
https://modelscope.cn/openapi/v1/galleries - Method:
POST - JSON fields:
name(string, required)owner(string, required)files(string[], required, currently max 1 file ID)private(bool, optional, defaultfalse)category(string, optional, defaultnotebook)labels(string[], optional, max 10)source_link(string, optional)
Expected response shape:
{
"success": true,
"request_id": "...",
"data": {
"id": "gallery-id",
"url": "https://.../gallery/<owner>/<gallery-id>"
}
}
Default workflow
- Validate that
FILE_PATHexists and size is <= 5 MB. - Upload file and extract
data.idasFILE_ID. - Create gallery with
name,owner, andfiles: [FILE_ID]. - Return the final gallery URL from
data.url. - If API returns
success: false, includerequest_idand raw error payload.
Commands
Step 1: upload
curl -sS -X POST "https://modelscope.cn/openapi/v1/files/upload" \
-H "Authorization: Bearer $MS_TOKEN" \
-F "file=@$FILE_PATH"
Step 2: create gallery
curl -sS -X POST "https://modelscope.cn/openapi/v1/galleries" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $MS_TOKEN" \
-d "{
\"name\": \"$NAME\",
\"owner\": \"$OWNER\",
\"files\": [\"$FILE_ID\"]
}"
Response handling rules
- Treat
success: trueas completion. - Always capture and report
request_id. - If
data.idis missing after upload, stop and ask user to retry. - If gallery creation succeeds, always return
data.urlto user.
Minimal example
MS_TOKEN="ms-xxxxx"
OWNER="kongyi1"
NAME="kongyi-test-3"
FILE_PATH="/Users/huanghongda/Desktop/qwen-demo.ipynb"
UPLOAD_JSON=$(curl -sS -X POST "https://modelscope.cn/openapi/v1/files/upload" \
-H "Authorization: Bearer $MS_TOKEN" \
-F "file=@$FILE_PATH")
FILE_ID=$(python -c 'import json,sys; print(json.load(sys.stdin).get("data", {}).get("id", ""))' <<< "$UPLOAD_JSON")
curl -sS -X POST "https://modelscope.cn/openapi/v1/galleries" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $MS_TOKEN" \
-d "{\"name\":\"$NAME\",\"owner\":\"$OWNER\",\"files\":[\"$FILE_ID\"]}"
Scan to contact