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:

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

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.