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:
- A running AISIX gateway with the Admin API and proxy API available. Commands use the Quickstart listener addresses; substitute your configured addresses if needed.
- The admin key from the gateway
config.yaml. - A DashScope API key from Alibaba Cloud Model Studio for the region you plan to use.
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:
- Model Aliases: add routing, cost metadata, and rate limits for this alias.
- Routing and Failover: fail over between Qwen regions or between Qwen and another provider.
- Provider-Specific Overrides: adapt request and response shapes when an upstream API differs from its adapter.
- Provider Compatibility: review supported proxy endpoints and provider-specific boundaries.