Skip to main content

Qwen (Alibaba Cloud)

Connect AISIX AI Gateway to Alibaba Cloud Qwen so applications can call Qwen models through the gateway's OpenAI-compatible API. AISIX keeps the DashScope credential on the gateway side. It authorizes model access with caller API keys and allowlists, and applies the same rate-limit and usage-accounting controls as other model aliases.

Alibaba Cloud Model Studio, also known as DashScope, exposes an OpenAI-compatible endpoint. Qwen uses the openai adapter with a DashScope api_base.

Prerequisites

The following examples use a self-hosted AISIX gateway. Before configuring the upstream, prepare the following:

Configure the Qwen Upstream

Create a provider key, model alias, and caller API key for the Qwen-backed chat-completions route. The examples use the Singapore regional endpoint.

Create a Provider Key

DashScope API keys are region-specific. Pair the key with the OpenAI-compatible API root for the same region:

  • Singapore: https://dashscope-intl.aliyuncs.com/compatible-mode/v1
  • Beijing: https://dashscope.aliyuncs.com/compatible-mode/v1

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.

Alibaba Cloud is also rolling out per-workspace endpoints, so confirm the current base URL for your account in the Model Studio console and Alibaba Cloud's OpenAI-compatible reference.

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

# Replace with your values
export AISIX_ADMIN_KEY="YOUR_ADMIN_KEY"
export DASHSCOPE_API_KEY="YOUR_PROVIDER_API_KEY"

curl -sS -X POST "http://127.0.0.1:3001/admin/v1/provider_keys" \
-H "Authorization: Bearer ${AISIX_ADMIN_KEY}" \
-H "Content-Type: application/json" \
--data-binary @- <<EOF
{
"display_name": "qwen-prod",
"provider": "qwen",
"adapter": "openai",
"secret": "${DASHSCOPE_API_KEY}",
"api_base": "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
}
EOF

provider is qwen.

adapter is openai, because DashScope's compatible mode accepts OpenAI chat-completions requests.

secret stores the DashScope API key. It follows the credential-handling behavior in Provider Credentials.

api_base is required, and it already includes the /compatible-mode/v1 path. Use the root that matches your DashScope region.

Copy the returned provider key ID.

Create a Model

Create the model alias callers will send in requests:

# Replace with your values
export PROVIDER_KEY_ID="YOUR_PROVIDER_KEY_ID"

curl -sS -X POST "http://127.0.0.1:3001/admin/v1/models" \
-H "Authorization: Bearer ${AISIX_ADMIN_KEY}" \
-H "Content-Type: application/json" \
--data-binary @- <<EOF
{
"display_name": "qwen-plus-prod",
"provider": "qwen",
"model_name": "qwen-plus",
"provider_key_id": "${PROVIDER_KEY_ID}"
}
EOF

display_name is the alias callers send in model.

model_name is the Qwen model ID, for example qwen-plus, qwen-max, or qwen-turbo.

provider_key_id attaches the alias to the Qwen provider key.

Create a Caller API Key

Choose the caller API key value that the application will send to AISIX, then hash it for the admin resource:

# Replace with your values
export AISIX_API_KEY="YOUR_CALLER_API_KEY"

CALLER_KEY_HASH=$(printf '%s' "${AISIX_API_KEY}" | shasum -a 256 | awk '{print $1}')

Create the caller API key resource that can access the model alias:

curl -sS -X POST "http://127.0.0.1:3001/admin/v1/apikeys" \
-H "Authorization: Bearer ${AISIX_ADMIN_KEY}" \
-H "Content-Type: application/json" \
--data-binary @- <<EOF
{
"key_hash": "${CALLER_KEY_HASH}",
"allowed_models": ["qwen-plus-prod"]
}
EOF

The allowed_models value must match the model alias you created.

Verify the Provider Connection

Send a chat-completions request through the AISIX proxy:

curl -sS -X POST "http://127.0.0.1:3000/v1/chat/completions" \
-H "Authorization: Bearer ${AISIX_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-plus-prod",
"messages": [
{
"role": "user",
"content": "Say hello from Qwen."
}
]
}'

The gateway returns an OpenAI-compatible response that echoes the caller-facing alias qwen-plus-prod. Confirm the request on the Model Studio usage page. If the request fails with an upstream authentication error, check the provider key secret and confirm that the key and base URL use the same region.

Next Steps

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