Qwen / DashScope API key setup
Published 2026-10-12 · Updated 2026-10-19
Alibaba’s Model Studio (百炼 / Bailian) issues Qwen API keys as sk- plus 32 lowercase alphanumeric characters. Newer workspace-scoped keys can carry sk-ws- or sk-sp- prefixes, same idea, pinned to a workspace and a region.
Setup
export DASHSCOPE_API_KEY="sk-..."
The OpenAI-compatible base URL depends on the region the key was created in:
- Singapore (international):
https://dashscope-intl.aliyuncs.com/compatible-mode/v1 - Beijing (China):
https://dashscope.aliyuncs.com/compatible-mode/v1
Keys are region-locked. Wrong region, 401.
Verify
curl https://dashscope-intl.aliyuncs.com/compatible-mode/v1/models \
-H "Authorization: Bearer $DASHSCOPE_API_KEY"
Python
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["DASHSCOPE_API_KEY"],
base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)
resp = client.chat.completions.create(
model="qwen3.8-max",
messages=[{"role": "user", "content": "Say hello"}],
)
print(resp.choices[0].message.content)
Notes
- Two SDKs, one key. The same key works with the OpenAI SDK (compatible mode) and Alibaba’s own
dashscopeSDK. Pick the OpenAI path unless you need DashScope-only features. - Workspace URLs. Some regions expose workspace-scoped endpoints like
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1, if your console shows one, use exactly that. - Model catalog is huge. Qwen ships dense, MoE, coder and VL variants;
qwen3.8-maxis the flagship chat model. Check/modelsfor what your tier unlocks. - Extra parameters. Features like thinking mode are enabled via
extra_body={"enable_thinking": True}in the OpenAI SDK, they don’t map onto standard OpenAI parameters.
The compatible-mode endpoint is the path of least resistance: existing OpenAI code works, and the key is the only thing that’s region-sensitive.