# Qwen (Alibaba Cloud)

[Qwen](https://www.alibabacloud.com/help/en/model-studio/) is Alibaba Cloud's family of language and multimodal models, served through Model Studio, also known as DashScope. Applications call Qwen through stable AISIX aliases while the gateway holds the DashScope credential.

This guide covers Qwen Chat Completions and native Responses, plus Wan video tasks, through a single Model Studio provider key.

## 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 DashScope API key for the region you plan to use, from the [international Model Studio console](https://bailian.console.alibabacloud.com/) or the [mainland China Model Studio console](https://bailian.console.aliyun.com/).

* `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 Qwen-backed Chat Completions and native Responses. The examples use the Singapore regional endpoint.

Because Alibaba Cloud Model Studio exposes an OpenAI-compatible endpoint, AISIX connects through the `openai` adapter and uses the DashScope API root for the region where you created the credential.

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

DashScope API keys and endpoints are region-specific. The AISIX catalog has separate international and mainland China provider IDs, with these default API roots:

| Provider ID  | Default API root                                         | Scope                                       |
| ------------ | -------------------------------------------------------- | ------------------------------------------- |
| `alibaba`    | `https://dashscope-intl.aliyuncs.com/compatible-mode/v1` | International, using the Singapore endpoint |
| `alibaba-cn` | `https://dashscope.aliyuncs.com/compatible-mode/v1`      | Mainland China, using the Beijing endpoint  |

An API key issued for one region does not work with another region's endpoint. Create one provider key per region when routing to both. Use `alibaba` for international traffic and `alibaba-cn` for mainland China so usage records and cost reports attribute traffic to the matching catalog.

Alibaba Cloud recommends a [workspace-dedicated domain](https://www.alibabacloud.com/help/en/model-studio/regions/) for production. The shared DashScope roots above remain available for existing integrations, but a dedicated domain provides workspace isolation and higher concurrency. The example below uses the Singapore form; replace `YOUR_WORKSPACE_ID` with the workspace that issued the API key. For another region, use the matching domain from the Model Studio console.

Create the provider key that stores the DashScope credential and API root, and capture its ID:

```
# Replace with your value

export DASHSCOPE_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": "qwen-prod",

    "provider": "alibaba",

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

    "api_base": "https://YOUR_WORKSPACE_ID.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",

    "apis": {

      "responses": {}

    },

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

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

❶ `provider` is `alibaba`, the catalog provider ID for the international Model Studio region. Use `alibaba-cn` for the mainland China region. The AISIX Cloud Admin API derives the adapter from the catalog provider; the adapter field is only accepted on BYO provider keys.

❷ `api_key` stores the DashScope API key. It follows the credential-handling behavior in [Provider Keys](https://docs.api7.ai/ai-gateway/models/provider-keys.md#credential-handling).

❸ `api_base` already includes the `/compatible-mode/v1` path. Use the workspace and region that issued the API key. If you omit this field, the AISIX Cloud Admin API uses the shared international root for `alibaba` and the shared Beijing root for `alibaba-cn`; those catalog defaults do not select your workspace-dedicated domain.

❹ `apis.responses` declares that Model Studio serves the Responses API at the same regional root. AISIX then uses Qwen's native format instead of translating the request through Chat Completions.

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

Create the model alias callers will send in requests, and capture its ID:

```
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": "qwen-plus-prod",

    "model_name": "qwen3.7-plus",

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

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

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

❷ `model_name` is the Qwen model ID. This example uses the current `qwen3.7-plus` model; check the [Model Studio model list](https://www.alibabacloud.com/help/en/model-studio/models) for availability in your region before creating the alias.

❸ `provider_key_id` attaches the alias to the Qwen 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 resource that can access the model alias. The plaintext key is generated by the server and returned once in the response:

```
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": "qwen-caller",

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

  }' | jq -r '.plaintext')
```

The `allowed_models` value must reference the model ID you captured. Store the plaintext key securely; it cannot be retrieved again.

The new resources project to attached gateways automatically, so the route is ready to call almost immediately.

## 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 DASHSCOPE_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: 728da2c2-6b8d-4320-ab32-3ee9bebb6831

    display_name: "qwen-prod"

    provider: "alibaba"

    adapter: "openai"

    api_key: ${DASHSCOPE_API_KEY}

    api_base: "https://YOUR_WORKSPACE_ID.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"

    apis:

      responses: {}



models:

  - id: de5c3b3e-d38b-458f-9c9c-10bf501de1f1

    display_name: "qwen-plus-prod"

    provider: "alibaba"

    model_name: "qwen3.7-plus"

    provider_key_id: 728da2c2-6b8d-4320-ab32-3ee9bebb6831



api_keys:

  - id: 36b90166-c4c7-4d79-b2f4-3b5dc81ecdda

    display_name: "qwen-caller"

    key_hash: ${CALLER_API_KEY_SHA256}

    allowed_models:

      - "qwen-plus-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 Responses request through the AISIX proxy:

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

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

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

  -d '{

    "model": "qwen-plus-prod",

    "input": "Say hello from Qwen."

  }'
```

AISIX sends the request to Qwen's native Responses endpoint, replaces the alias with the Model Studio model ID upstream, and restores the alias in the response. Confirm the request on the Model Studio usage page. If it fails with an upstream authentication error, check the provider key credential and confirm that the key and base URL use the same region.

The native Responses path supports streaming, `previous_response_id`, reasoning effort, and provider-hosted tools, although availability varies by model and region.

## Use Native Messages Through Passthrough[​](#use-native-messages-through-passthrough "Direct link to Use Native Messages Through Passthrough")

Model Studio also publishes an Anthropic-compatible Messages API under a different regional `/apps/anthropic` base. It accepts bearer or `x-api-key` authentication, but documents only `/v1/messages`, not `/v1/messages/count_tokens`. Leave `apis.messages` out of this provider key because the declaration covers both routes in AISIX.

When an application needs Qwen's native Messages format, configure a dedicated [passthrough route](https://docs.api7.ai/ai-gateway/endpoints/provider-passthrough.md) instead of reusing the general provider prefix. Bind the route to the Qwen provider key for the same region so AISIX can inject its credential. For the international example, claim `/passthrough/alibaba-messages` and target `https://YOUR_WORKSPACE_ID.ap-southeast-1.maas.aliyuncs.com/apps/anthropic`. For mainland China, claim `/passthrough/alibaba-cn-messages` and target `https://YOUR_WORKSPACE_ID.cn-beijing.maas.aliyuncs.com/apps/anthropic`. The [China-region endpoint reference](https://help.aliyun.com/zh/model-studio/regions) lists the shared and workspace-specific bases.

Call `/passthrough/alibaba-messages/v1/messages` or `/passthrough/alibaba-cn-messages/v1/messages` and send the upstream model ID, such as `qwen3.7-plus`, because passthrough does not rewrite the AISIX alias. Count Tokens remains unavailable.

## Generate Videos with Wan and HappyHorse[​](#generate-videos-with-wan "Direct link to Generate Videos with Wan and HappyHorse")

The same provider key drives the gateway's modeled [video routes](https://docs.api7.ai/ai-gateway/endpoints/video-generation.md). Create a second alias that points at a Model Studio text-to-video model — a [Wan 2.7](https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference) model, or a [HappyHorse](https://www.alibabacloud.com/help/en/model-studio/happyhorse-text-to-video-api-reference) text-to-video model such as `happyhorse-1.1-t2v`. Both families answer on the same asynchronous DashScope endpoints, so the workflow below is identical; only the upstream model name changes.

In AISIX Enterprise and AISIX Cloud, create the video alias and a caller key scoped to it:

```
VIDEO_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": "wan-video-prod",

    "model_name": "wan2.7-t2v",

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

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



echo "$VIDEO_MODEL_ID"



VIDEO_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": "qwen-video-caller",

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

  }' | jq -r '.plaintext')
```

For the open-source AISIX gateway, add `wan-video-prod` to the existing `models` collection. Replace the existing `qwen-caller` entry with the updated entry below so it allows both model aliases. Preserve unrelated entries and collections:

resources.yaml (video model access)

```
models:

  - id: 98d43fb2-143c-4388-80e5-4f21e604c073

    display_name: "wan-video-prod"

    provider: "alibaba"

    model_name: "wan2.7-t2v"

    provider_key_id: 728da2c2-6b8d-4320-ab32-3ee9bebb6831



api_keys:

  - id: 36b90166-c4c7-4d79-b2f4-3b5dc81ecdda

    display_name: "qwen-caller"

    key_hash: ${CALLER_API_KEY_SHA256}

    allowed_models:

      - "qwen-plus-prod"

      - "wan-video-prod"
```

Validate and reload or restart the declarative resources file as described above, then use the existing caller key for the video request:

```
export VIDEO_API_KEY="$CALLER_API_KEY"
```

Submit a task:

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

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

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

  -d '{

    "model": "wan-video-prod",

    "prompt": "A paper boat drifts down a rain-soaked street at dusk.",

    "seconds": 5

  }'
```

Six provider-specific behaviors are worth knowing before you script around this route:

* **Only the `alibaba` provider value is dispatched.** `alibaba-cn` is outside the video route's allowlist, so a mainland China alias returns a not-implemented error on submit. Reach the mainland China video API through a passthrough route whose `target_url` is the native Model Studio base for that region.
* **The chat `api_base` is reused as-is.** AISIX strips one `/compatible-mode/v1`, `/api/v1`, or `/v1` suffix, derives the vendor root, and composes DashScope's native task paths underneath. A provider key already configured for Qwen chat traffic works on the video routes without change, and the gateway sets the mandatory asynchronous submission header for you.
* **`size` targets the earlier Wan protocol.** `seconds` is forwarded as the integer `parameters.duration`, and `size` is forwarded as `parameters.size` in the provider's `WIDTH*HEIGHT` spelling. That parameter belongs to Wan 2.6 and earlier. Wan 2.7 models replaced it with `resolution` and `ratio` tiers, and AISIX does not check which family the alias names — it forwards whatever you send. Omit `size` yourself on a Wan 2.7 alias, as the example above does, and let the provider default apply.
* **HappyHorse text-to-video works on the same route.** `happyhorse-1.1-t2v` and `happyhorse-1.0-t2v` use the same submission endpoint, poll endpoint, and task states as Wan, and express output dimensions as `resolution` and `ratio` tiers — so, as with Wan 2.7, omit `size` and let the provider default apply. The image-to-video (`happyhorse-1.1-i2v`), reference-to-video, and video-editing variants are separate Model Studio APIs with reference-media inputs the modeled route does not carry; reach them through a passthrough route, like the other provider-native fields below. Runway also hosts HappyHorse models on its own platform — see [RunwayML](https://docs.api7.ai/ai-gateway/providers/runwayml.md) for that integration.
* **Provider-native video fields require a passthrough route.** The normalized request models only `prompt`, `seconds`, and `size`; extra fields are ignored. To send native fields such as `negative_prompt`, `seed`, or Wan 2.7's `resolution` and `ratio`, use a [passthrough route](https://docs.api7.ai/ai-gateway/endpoints/provider-passthrough.md) pointed at the native DashScope root, which differs from the OpenAI-compatible root the `/passthrough/alibaba` examples on this page assume. A route claiming `/passthrough/alibaba-video` with `https://dashscope-intl.aliyuncs.com/api/v1` as its `target_url` submits at `/passthrough/alibaba-video/services/aigc/video-generation/video-synthesis` and polls at `/passthrough/alibaba-video/tasks/{id}`. Send the native body with the exact upstream model ID, and set the provider's asynchronous submission header yourself. Passthrough does not return the unified AISIX video object or gateway-encoded task ID.
* **Finished videos are delivered by redirect.** `GET /v1/videos/{id}/content` returns `302` with a `Location` header pointing at the provider's signed download URL. The bytes travel from Model Studio storage to the client and do not pass through the gateway, so follow redirects when downloading, for example with the `-L` flag in `curl`.

For the full submit, poll, and download workflow, including status semantics and rate-limit behavior on polling, see [Video Generation](https://docs.api7.ai/ai-gateway/endpoints/video-generation.md).

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

A Qwen provider key uses the `openai` adapter, but route support also depends on AISIX provider rules and the APIs available on the configured Model Studio base:

| Route                                                            | Behavior with a Qwen model alias                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `/v1/chat/completions`                                           | Supported, buffered and streaming.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `/v1/messages`                                                   | Supported through translation to chat completions on the key in this guide. For the native format, use the region-specific Messages passthrough route described above. Treat `/v1/messages/count_tokens` as unavailable because Model Studio does not document that route.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `/v1/responses`                                                  | Sent to Alibaba's [native Responses API](https://www.alibabacloud.com/help/en/model-studio/qwen-api-via-openai-responses) because this guide declares `apis.responses`. Without the declaration, AISIX uses the [Responses bridge](https://docs.api7.ai/ai-gateway/endpoints/responses-api.md).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `/v1/embeddings`                                                 | Supported when the alias names a [text embedding model](https://www.alibabacloud.com/help/en/model-studio/embedding) available in the same region, such as `text-embedding-v4`. AISIX appends `/embeddings` to the configured OpenAI-compatible base.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `/v1/videos` and its status and content routes                   | Supported only when the model's provider value is exactly `alibaba`; `alibaba-cn` is outside the video route's allowlist. AISIX maps the request to DashScope's asynchronous [text-to-video API](https://www.alibabacloud.com/help/en/model-studio/text-to-video-api-reference), which serves both Wan and HappyHorse text-to-video models. For current Wan 2.7 and HappyHorse models, omit `size`, because the AISIX `size` mapping targets earlier Wan APIs. See [Generate Videos with Wan and HappyHorse](#generate-videos-with-wan). Use a passthrough route when you need native `resolution`, `ratio`, or multimodal fields; for `alibaba-cn`, this requires a route targeting the native Model Studio base.                                                                                                                                           |
| `/v1/audio/*`                                                    | Not supported on the OpenAI-compatible base configured on this page. Model Studio audio APIs use provider-native routes and request shapes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `/v1/images/generations`                                         | Not supported. This 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)); Model Studio image APIs require a passthrough route.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `/v1/rerank`                                                     | Not supported. This route accepts only the `openai`, `cohere`, and `jina` provider values; Model Studio rerank models use a provider-native API.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `/passthrough/alibaba/*rest` and `/passthrough/alibaba-cn/*rest` | Available through configured [passthrough routes](https://docs.api7.ai/ai-gateway/endpoints/provider-passthrough.md) for native Model Studio APIs under the OpenAI-compatible roots. A passthrough route does not rewrite a caller-facing alias inside the body and relays upstream SSE incrementally. 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). Native DashScope APIs, such as native rerank and multimodal embedding, use the `/api/v1` root instead; see the [Alibaba Cloud native rerank example](https://docs.api7.ai/ai-gateway/endpoints/provider-passthrough.md#example-meter-alibaba-cloud-native-rerank). Native Messages and video use separate prefixes because their APIs have different roots. |

The `/passthrough/alibaba` and `/passthrough/alibaba-cn` prefixes assume the matching OpenAI-compatible Model Studio roots. The `/passthrough/alibaba-messages` and `/passthrough/alibaba-cn-messages` prefixes assume their regional `/apps/anthropic` roots, while `/passthrough/alibaba-video` assumes the DashScope video root described above. Configure and grant each route separately in the caller key's `allowed_routes`.

See [Provider Compatibility](https://docs.api7.ai/ai-gateway/providers/compatibility.md) for the full endpoint and provider matrix.

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

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

* [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 between Qwen regions or between Qwen and another provider.
* [Video Generation](https://docs.api7.ai/ai-gateway/endpoints/video-generation.md): follow the submit, poll, and download workflow for supported Wan text-to-video models.
* [Provider-Specific Overrides](https://docs.api7.ai/ai-gateway/models/provider-keys.md#configure-provider-specific-overrides): adapt request and response shapes when an upstream API differs from its adapter.
* [Provider Compatibility](https://docs.api7.ai/ai-gateway/providers/compatibility.md): review supported proxy endpoints and provider-specific boundaries.
