Back to skills
extension
Category: Development & EngineeringNo API key required

modelscope-gallery-openapi

modelscope-gallery-openapi

personAuthor: kongyi1hubModelScope

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 like ms-xxxxx
  • OWNER: gallery owner name
  • NAME: gallery name
  • FILE_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, default false)
    • category (string, optional, default notebook)
    • 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

  1. Validate that FILE_PATH exists and size is <= 5 MB.
  2. Upload file and extract data.id as FILE_ID.
  3. Create gallery with name, owner, and files: [FILE_ID].
  4. Return the final gallery URL from data.url.
  5. If API returns success: false, include request_id and 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: true as completion.
  • Always capture and report request_id.
  • If data.id is missing after upload, stop and ask user to retry.
  • If gallery creation succeeds, always return data.url to 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\"]}"