# ModelScope

[ModelScope](https://modelscope.cn/docs/model-service/API-Inference/intro) is a model community and hosted inference platform for open-weight models. AISIX gives applications one OpenAI-compatible API for those models while managing credentials, caller access, rate limits, and usage accounting.

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

Before starting, prepare the following:

* One AISIX setup:

  <!-- -->

  * For AISIX Enterprise or AISIX Cloud, an environment with an attached gateway and a write-scoped admin token. For AISIX Enterprise, follow the [AISIX Enterprise getting-started guide](https://docs.api7.ai/ai-gateway/getting-started/aisix-cloud-quickstart.md). To request AISIX Cloud access, [contact API7](https://api7.ai/contact).
  * For the open-source AISIX gateway, prepare either a local AISIX installation or the Docker setup from the [AISIX OSS getting-started guide](https://docs.api7.ai/ai-gateway/getting-started/gateway-quickstart.md). Configure the gateway to load a declarative resources file.

* A ModelScope API token from your ModelScope account. The ModelScope [API-Inference documentation](https://modelscope.cn/docs/model-service/API-Inference/intro) describes the account activation and quota rules that apply before a token can serve inference requests.

* `curl` and `jq`.

## Configure with AISIX Enterprise or AISIX Cloud[​](#configure-with-aisix-enterprise-or-aisix-cloud "Direct link to Configure with AISIX Enterprise or AISIX Cloud")

Export the control-plane connection details:

```
# AISIX_CP is the Admin API base URL; include /api and omit a trailing slash

# The local AISIX Enterprise quickstart uses http://localhost:8080/api

export AISIX_CP="YOUR_AISIX_CONTROL_PLANE_API_URL"

export AISIX_TOKEN="YOUR_ADMIN_TOKEN"

export ENV_ID="YOUR_ENVIRONMENT_ID"
```

Create a provider key, model alias, and caller API key for the ModelScope-backed chat-completions route.

ModelScope is a community catalog provider with an OpenAI-compatible API-Inference service. AISIX connects through the `openai` adapter, authenticates upstream requests with a bearer token, and uses the ModelScope API root as `api_base`. Review [Supply the Wire Details AISIX Does Not Curate](#supply-the-wire-details-aisix-does-not-curate) before sending production traffic.

### Create a Provider Key[​](#create-a-provider-key "Direct link to Create a Provider Key")

Create the provider key that stores the ModelScope credential and API root:

```
# Replace with your value

export MODELSCOPE_API_KEY="YOUR_PROVIDER_API_KEY"



PROVIDER_KEY_ID=$(curl -sS -X POST "$AISIX_CP/provider_keys" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "display_name": "modelscope-prod",

    "provider": "modelscope",

    "api_key": "'"${MODELSCOPE_API_KEY}"'",

    "api_base": "https://api-inference.modelscope.cn/v1",

    "allowed_environments": ["'"${ENV_ID}"'"]

  }' | jq -r '.provider_key.id')



echo "$PROVIDER_KEY_ID"
```

❶ `provider` is `modelscope`. The AISIX Cloud Admin API accepts this value because the ID exists in the cached models.dev catalog, and it applies the catalog's default rule: the `openai` adapter and HTTP bearer authentication. Do not set the `adapter` field, which the AISIX Cloud Admin API accepts only on BYO provider keys.

❷ `api_key` stores the ModelScope API token. The `openai` adapter sends it in an `Authorization: Bearer` header. The value follows the credential-handling behavior in [Provider Keys](https://docs.api7.ai/ai-gateway/models/provider-keys.md#credential-handling).

❸ `api_base` is `https://api-inference.modelscope.cn/v1`, the API root that ModelScope's OpenAI-compatible chat-completions endpoint, `https://api-inference.modelscope.cn/v1/chat/completions`, hangs off. AISIX appends the endpoint path, such as `/chat/completions`, to the value you store. For `modelscope` this field is optional, because the control plane fills in this same root from the catalog when you omit it. The examples set it explicitly so the root each key targets stays visible in the configuration.

caution

Store the API root, not the full endpoint URL and not the bare host. AISIX strips a trailing `/chat/completions` if you paste one, but it never synthesizes the `/v1` segment for a non-OpenAI host. An `api_base` of `https://api-inference.modelscope.cn` produces upstream requests to `https://api-inference.modelscope.cn/chat/completions`, a path ModelScope does not serve.

These examples target the ModelScope China service. ModelScope's international service uses `https://api-inference.modelscope.ai/v1`; set that root explicitly when your token and model come from `modelscope.ai`. The catalog default remains the `.cn` root, so omitting `api_base` does not select the international service automatically.

The command captures the returned provider key ID in `PROVIDER_KEY_ID`.

### Create a Model[​](#create-a-model "Direct link to Create a Model")

ModelScope model IDs are organization-namespaced. Each ID repeats the `organization/model` path of the model page on ModelScope, including its capitalization. Current IDs in the AISIX provider catalog include the following:

| Model ID                             | Context window | Notes                                                 |
| ------------------------------------ | -------------- | ----------------------------------------------------- |
| `Qwen/Qwen3-235B-A22B-Instruct-2507` | 262,144 tokens | Instruction model. Does not emit reasoning.           |
| `Qwen/Qwen3-235B-A22B-Thinking-2507` | 262,144 tokens | Reasoning variant of the same weights.                |
| `Qwen/Qwen3-Coder-30B-A3B-Instruct`  | 262,144 tokens | Coding and software-agent model.                      |
| `ZhipuAI/GLM-4.6`                    | 202,752 tokens | GLM flagship served under the `ZhipuAI` organization. |

Confirm the ID on the model's ModelScope page before you create an alias, because the set of models that API-Inference serves changes over time.

Create the model alias callers will send in requests:

```
MODEL_ID=$(curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/models" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "display_name": "modelscope-qwen-prod",

    "model_name": "Qwen/Qwen3-235B-A22B-Instruct-2507",

    "provider_key_id": "'"${PROVIDER_KEY_ID}"'"

  }' | jq -r '.model.id')



echo "$MODEL_ID"
```

❶ `display_name` is the alias callers send in `model`.

❷ `model_name` is the full ModelScope model ID, organization prefix included. Dropping the prefix, or reusing an unprefixed ID such as `qwen3-235b-a22b-instruct-2507` from another host of the same weights, produces an upstream model-not-found error.

❸ `provider_key_id` attaches the alias to the ModelScope provider key.

### Create a Caller API Key[​](#create-a-caller-api-key "Direct link to Create a Caller API Key")

Create the caller API key that can access the model alias. The plaintext key is server-generated and returned once in the create response, so capture it now:

```
AISIX_API_KEY=$(curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/api_keys" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "display_name": "modelscope-caller",

    "allowed_models": ["'"${MODEL_ID}"'"]

  }' | jq -r '.plaintext')



echo "$AISIX_API_KEY"
```

The `allowed_models` value must reference the model ID captured in the previous step. After the write, the configuration projects to attached gateways automatically.

## Configure with AISIX OSS[​](#configure-with-aisix-oss "Direct link to Configure with AISIX OSS")

Export the upstream credential and choose the caller API key that applications will send to the gateway:

```
export MODELSCOPE_API_KEY="YOUR_PROVIDER_API_KEY"

export CALLER_API_KEY="YOUR_CALLER_API_KEY"

export CALLER_API_KEY_SHA256="$(printf '%s' "$CALLER_API_KEY" | sha256sum | cut -d ' ' -f 1)"
```

For a new gateway, use this complete resources file. For an existing gateway, merge the entries into its [current file](https://docs.api7.ai/ai-gateway/reference/resources-file.md#apply-resource-examples-safely), preserving its other resources:

resources.yaml

```
_format_version: "2"



provider_keys:

  - id: cd030c4d-a79f-4950-8645-c83bc8f4ce8a

    display_name: "modelscope-prod"

    provider: "modelscope"

    adapter: "openai"

    api_key: ${MODELSCOPE_API_KEY}

    api_base: "https://api-inference.modelscope.cn/v1"



models:

  - id: 930323df-7036-4575-b5f3-7b825e393991

    display_name: "modelscope-qwen-prod"

    provider: "modelscope"

    model_name: "Qwen/Qwen3-235B-A22B-Instruct-2507"

    provider_key_id: cd030c4d-a79f-4950-8645-c83bc8f4ce8a



api_keys:

  - id: 143fc5c0-13d6-4244-916e-6bfd75e476b2

    display_name: "modelscope-caller"

    key_hash: ${CALLER_API_KEY_SHA256}

    allowed_models:

      - "modelscope-qwen-prod"
```

If AISIX is installed locally, validate the file before loading it:

```
aisix validate --resources resources.yaml
```

After validation, start the gateway with the referenced environment variables in its process environment. Reload an existing gateway only if those variables are already available to the process; otherwise, restart it with the updated environment.

If you use Docker, adapt the validation and startup commands in the [AISIX OSS getting-started guide](https://docs.api7.ai/ai-gateway/getting-started/gateway-quickstart.md). Mount this `resources.yaml` file and pass every environment variable it references with `-e` in both commands. After the resources load, prepare the shared verification request below:

```
export AISIX_API_KEY="$CALLER_API_KEY"
```

## Verify the Provider Connection[​](#verify-the-provider-connection "Direct link to Verify the Provider Connection")

Export the AISIX gateway origin:

```
# AISIX_PROXY has no trailing slash or endpoint path

# The local quickstarts use http://127.0.0.1:3000

export AISIX_PROXY="YOUR_AISIX_GATEWAY_URL"
```

Send a chat-completions request through the AISIX proxy:

```
curl -sS -X POST "$AISIX_PROXY/v1/chat/completions" \

  -H "Authorization: Bearer ${AISIX_API_KEY}" \

  -H "Content-Type: application/json" \

  -d '{

    "model": "modelscope-qwen-prod",

    "messages": [

      {

        "role": "user",

        "content": "Say hello from ModelScope."

      }

    ]

  }'
```

The gateway returns an OpenAI-compatible response that echoes the caller-facing alias `modelscope-qwen-prod`. If the request fails, check the provider key `api_key`, the `api_base` root, and the organization-prefixed model ID in `model_name`.

## Choose Between ModelScope and Alibaba Cloud Model Studio[​](#choose-between-modelscope-and-alibaba-cloud-model-studio "Direct link to Choose Between ModelScope and Alibaba Cloud Model Studio")

ModelScope and Alibaba Cloud Model Studio both serve Qwen models, but they are separate upstreams with separate provider IDs in AISIX. Selecting the wrong one produces an upstream authentication or model-not-found error rather than a configuration error at create time, so confirm which service issued your credential first.

|                            | ModelScope                                                                            | Alibaba Cloud Model Studio                                                |
| -------------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| Provider ID                | `modelscope`                                                                          | `alibaba`                                                                 |
| Catalog tier               | Community                                                                             | Curated                                                                   |
| Setup guide                | This page                                                                             | [Qwen (Alibaba Cloud)](https://docs.api7.ai/ai-gateway/providers/qwen.md) |
| API root                   | `https://api-inference.modelscope.cn/v1`                                              | Region-specific DashScope OpenAI-compatible root                          |
| Credential                 | ModelScope API token                                                                  | DashScope API key, issued per region                                      |
| Model ID form              | Organization-namespaced repository path, such as `Qwen/Qwen3-235B-A22B-Instruct-2507` | Model Studio model name, such as `qwen-plus`                              |
| Modeled `/v1/videos` route | Rejected                                                                              | Supported                                                                 |

The same distinction applies to GLM. ModelScope serves GLM weights under the `ZhipuAI` organization, but a GLM alias backed by the `modelscope` provider is not equivalent to one backed by the curated `zhipuai` provider described in [Zhipu AI (GLM)](https://docs.api7.ai/ai-gateway/providers/zhipuai.md). Gateway surfaces that dispatch by provider label, such as the modeled [video-generation route](https://docs.api7.ai/ai-gateway/endpoints/video-generation.md), key off the provider recorded on the model, not off which weights the upstream happens to serve.

## Supply the Wire Details AISIX Does Not Curate[​](#supply-the-wire-details-aisix-does-not-curate "Direct link to Supply the Wire Details AISIX Does Not Curate")

For a provider with an AISIX-curated adapter mapping, the catalog records the adapter, authentication scheme, default API root, and any request or response quirks. ModelScope has no such mapping. It resolves through the catalog's default rule, which grants the `openai` adapter and bearer authentication and marks the provider as community-sourced, with wire compatibility assumed to be OpenAI-shaped unless the operator overrides it per key. Everything beyond that assumption is yours to configure.

In practice:

* **No parameter renames are registered.** AISIX forwards the top-level chat-completions parameters exactly as the caller sent them. Some curated providers carry a rename for a field such as `max_completion_tokens`; ModelScope carries none, so a body that works against a renamed provider is not automatically portable here, and the reverse is also true.
* **No response field remapping is registered.** AISIX already normalizes reasoning that arrives at `message.reasoning_content`, `delta.reasoning_content`, or `message.reasoning` into the canonical `reasoning_content` field. Reasoning delivered on any other streaming `delta` path is not remapped unless you map it.
* **No provider-wide reasoning control applies.** ModelScope does not publish a shared reasoning toggle, effort level, or thinking-token budget that spans the models it serves, so reasoning behavior follows the individual model. Validate it per model ID: `Qwen/Qwen3-235B-A22B-Thinking-2507` reasons by design, while `Qwen/Qwen3-235B-A22B-Instruct-2507` does not.

Both kinds of adjustment are provider-key fields. Add them to the provider key create request, or to the provider key entry in a declarative resources file:

```
{

  "request": {

    "param_renames": {

      "max_completion_tokens": "max_tokens"

    }

  },

  "response": {

    "reasoning_field": "delta.thinking"

  }

}
```

Use `request.param_renames` only when a specific ModelScope-served model rejects a parameter name your clients already send, and `response.reasoning_field` only when a streaming response carries reasoning on a path other than `delta.reasoning_content`. See [Provider-Specific Overrides](https://docs.api7.ai/ai-gateway/models/provider-keys.md#configure-provider-specific-overrides) for the field catalog and the adapters each override applies to.

An override on the provider key applies to every model that references it, so validate a change against a non-production alias first. For the same reason, consider one provider key per organization namespace when the models you serve behave differently: `Qwen/*` and `ZhipuAI/*` share one endpoint but are different model families. Send both a buffered and a streaming request through each new alias, and confirm the fields your clients read are present before you route traffic to it.

## Account for Cost and Shared Quota[​](#account-for-cost-and-shared-quota "Direct link to Account for Cost and Shared Quota")

For normalized model requests, the managed control plane resolves per-request cost by the exact `(provider, model name)` pair, falling back to the models.dev catalog default when no organization override matches. The ModelScope catalog entries publish an input and output price of zero, so these usage events record their token counts and resolve to `$0.00` spend. Budgets evaluated against that spend never advance, and a `least_cost` routing group treats the alias as free.

If cost reporting or budgets must reflect what ModelScope traffic actually costs your organization, add an organization pricing override for provider `modelscope` and the model name exactly as configured, organization prefix included. See [Model Pricing](https://docs.api7.ai/ai-gateway/cloud/model-pricing.md).

One upstream ModelScope account backs every caller behind the gateway, so an upstream quota rejection reaches every caller at once. Set gateway-side caps so a single caller cannot exhaust the shared account: attach a rate limit to the model alias, to the caller API key, or to both. See [API Key and Model Rate Limits](https://docs.api7.ai/ai-gateway/traffic-controls/rate-limits.md).

## Endpoint Coverage[​](#endpoint-coverage "Direct link to Endpoint Coverage")

ModelScope API-Inference exposes several OpenAI- and Anthropic-shaped endpoints, but only part of the normalized AISIX proxy surface applies to a ModelScope-backed alias. A supported route below describes what AISIX does with the request; it does not imply that AISIX uses ModelScope's native endpoint of the same name.

| Route                                                                 | Behavior with a ModelScope alias                                                                                                                                                                                                                                                                                                                                 |
| --------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `/v1/chat/completions`                                                | Supported, including `stream: true`.                                                                                                                                                                                                                                                                                                                             |
| `/v1/completions`                                                     | Not supported. ModelScope API-Inference does not expose the legacy completions path.                                                                                                                                                                                                                                                                             |
| `/v1/responses`                                                       | Supported through the [Responses bridge](https://docs.api7.ai/ai-gateway/endpoints/responses-api.md) over the chat adapter path. It does not call ModelScope's native `/v1/responses` endpoint, and Responses fields without a chat equivalent are ignored. Use a passthrough route when native Responses semantics are required.                                |
| `/v1/messages`                                                        | Supported for Anthropic-shaped callers through translation to chat completions. It does not call ModelScope's native `/v1/messages` endpoint.                                                                                                                                                                                                                    |
| `/v1/messages/count_tokens`                                           | Rejected for the `modelscope` configuration in this guide because the normalized counter requires an Anthropic-backed model. ModelScope's native counter is reachable through a passthrough route.                                                                                                                                                               |
| `/v1/embeddings`                                                      | Dispatches through the `openai` adapter, so it works only when the configured model is served at the upstream `/v1/embeddings` path. The ModelScope entries in the AISIX provider catalog are text chat models. See [Embeddings](https://docs.api7.ai/ai-gateway/endpoints/embeddings.md).                                                                       |
| `/v1/audio/*`, `/v1/files`, `/v1/batches`, and `/v1/fine_tuning/jobs` | Not available with this provider. ModelScope API-Inference does not expose compatible paths beneath the configured API root.                                                                                                                                                                                                                                     |
| `/v1/images/generations`                                              | Rejected with a 400 error. The route accepts only models whose provider is `openai` or whose provider key uses the `azure-openai` adapter (see [Provider Requirement](https://docs.api7.ai/ai-gateway/endpoints/image-generation.md#provider-requirement)). ModelScope's native asynchronous image-generation workflow is reachable through a passthrough route. |
| `/v1/rerank`                                                          | Rejected with a 400 error. The route accepts only the `openai`, `cohere`, and `jina` provider values.                                                                                                                                                                                                                                                            |
| `/v1/videos`                                                          | Rejected with `501 not_implemented`. The route dispatches by provider label, and `modelscope` is not one of the labels it accepts, including for GLM weights that the `zhipuai` provider can drive on this route.                                                                                                                                                |
| `/passthrough/modelscope/*`                                           | Available through a configured [passthrough route](https://docs.api7.ai/ai-gateway/endpoints/provider-passthrough.md) for provider-native routes, including `/responses`, `/messages`, `/messages/count_tokens`, `/images/generations`, and `/tasks/{task_id}`.                                                                                                  |

ModelScope's native API surface is not the same as the normalized AISIX surface. For example, ModelScope image generation starts an asynchronous job at `/v1/images/generations` and returns a task ID. The application then polls `/v1/tasks/{task_id}`. With a passthrough route targeting this guide's API root, call those routes at `/passthrough/modelscope/images/generations` and `/passthrough/modelscope/tasks/{task_id}`. Send `X-ModelScope-Async-Mode: true` when starting the job, `X-ModelScope-Task-Type: image_generation` when polling it, and the exact ModelScope image model ID in the native request body.

These paths assume a [passthrough route](https://docs.api7.ai/ai-gateway/endpoints/provider-passthrough.md) claiming the `/passthrough/modelscope` prefix with `https://api-inference.modelscope.cn/v1` as its `target_url` and the ModelScope provider key for credential injection; grant the route name on the caller key's `allowed_routes`. A duplicated leading `/v1` is removed when it matches the target's trailing segment, so adding it after `/passthrough/modelscope` reaches the same upstream URL. The gateway does not rewrite an AISIX alias in the request body, and the native `model` field does not select a credential — the route binds one target and provider key, so use separate routes for different ModelScope accounts or roots. For the request shapes that record token usage, see [Envelope Detection and Usage](https://docs.api7.ai/ai-gateway/endpoints/provider-passthrough.md#envelope-detection-and-token-usage). AISIX relays provider SSE incrementally rather than buffering events.

## Next Steps[​](#next-steps "Direct link to Next Steps")

You have now connected AISIX to ModelScope and verified the model alias. Continue with these guides:

* [Provider-Specific Overrides](https://docs.api7.ai/ai-gateway/models/provider-keys.md#configure-provider-specific-overrides): adapt request and response shapes when this upstream differs from the `openai` adapter's assumptions.
* [Model Aliases](https://docs.api7.ai/ai-gateway/models/model-aliases.md): configure routing, retry behavior, or cost metadata for this alias.
* [Routing and Failover](https://docs.api7.ai/ai-gateway/routing/routing-and-failover.md): fail over from ModelScope to a second provider that serves comparable weights.
* [Qwen (Alibaba Cloud)](https://docs.api7.ai/ai-gateway/providers/qwen.md): configure the curated Alibaba Cloud Model Studio upstream instead when your credential comes from Model Studio.
* [Provider Compatibility](https://docs.api7.ai/ai-gateway/providers/compatibility.md): review supported proxy endpoints and provider-specific boundaries.
