Docs · Provider
Qwen in Claude Code, Codex, Gemini CLI and OpenCode
Alibaba serves Qwen through DashScope, on Alibaba Cloud Model Studio, Bailian and Qwen Cloud, pay as you go or on a Token Plan. Every one of them speaks OpenAI Chat Completions and Anthropic Messages. Add your key to magpie once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use Qwen through magpie’s gateway at 127.0.0.1:3425.
Add Qwen
- Get a keyPay as you go: Model Studio (international) or Bailian (China). A Token Plan’s key comes from its own plan page.
- Add the providerIn magpie’s Providers tab, press + Add provider, pick the Qwen preset your key is from (the table below), paste the key and save. magpie asks the endpoint which models it serves.
- Pick it for an agentIn the Agents tab, click the model on the agent’s row and choose a Qwen model such as
qwen3.8-max.
magpie provider add qwen sk-… # Model Studio, international magpie provider add qwen-cn sk-… # Bailian, China magpie provider add bailian-token-plan sk-sp-… # Bailian Token Plan magpie provider add qwencloud sk-ws-… region=us-east-1
sk-sp-…) is refused by pay-as-you-go endpoints and by the other Token Plans, and a Qwen Cloud key is refused outside its region. If a request comes back 401, check that the key sits under the preset it was made for.Plans and endpoints
| Preset | Plan and key | Endpoints (Chat Completions, Anthropic Messages) |
|---|---|---|
| Qwen qwen | pay as you go, international (Model Studio) | https://dashscope-intl.aliyuncs.com/compatible-mode/v1https://dashscope-intl.aliyuncs.com/apps/anthropic |
| Qwen (China) qwen-cn | pay as you go, China (Bailian) | https://dashscope.aliyuncs.com/compatible-mode/v1https://dashscope.aliyuncs.com/apps/anthropic |
| Qwen Token Plan qwen-token-plan | subscription, sk-sp- | https://token-plan.maas.qianwenaiapi.com/compatible-mode/v1https://token-plan.maas.qianwenaiapi.com/apps/anthropic |
| Bailian Token Plan bailian-token-plan | subscription, sk-sp- | https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1https://token-plan.cn-beijing.maas.aliyuncs.com/apps/anthropic |
| Qwen Cloud qwencloud | pay as you go, sk-ws-, six regions, Singapore the default | https://{region}.maas.qwencloudapi.com/compatible-mode/v1https://{region}.maas.qwencloudapi.com/apps/anthropic |
| Qwen Cloud Token Plan qwencloud-token-plan | subscription, sk-sp-, Singapore | https://token-plan.maas.qwencloudapi.com/compatible-mode/v1https://token-plan.maas.qwencloudapi.com/apps/anthropic |
When a Token Plan’s host gives no model list, magpie offers the plan’s text models as its overview lists them: auto, qwen3.8-max, qwen3.8-flash, qwen3.7-max, qwen3.7-plus, qwen3.6-flash, and the DeepSeek and GLM models the plan includes. The Bailian Token Plan also serves a decision model that can classify turns for intent routing.
In each agent
Pick the model on an agent’s row in the Agents tab, or from a terminal. Each guide says what magpie writes in that agent’s config and how to switch back.
magpie claude qwen/qwen3.8-max magpie codex qwen/qwen3.8-max magpie gemini model qwen/qwen3.7-plus magpie opencode qwen/qwen3.8-max
- Claude Code speaks Anthropic Messages, and so does Qwen’s Anthropic endpoint, so its requests are passed on as they are. Every tier (opus, sonnet, haiku) runs on the model you pick unless you give one its own. Models in Claude Code.
- Codex speaks only OpenAI Responses. DashScope serves Chat Completions and Anthropic Messages but not Responses, so magpie translates each request and the reply, streaming and tool calls included. The model shows in Codex’s
/modelwith its reasoning efforts. Models in Codex. - Gemini CLI speaks Gemini’s API. magpie points it at its gateway and translates. Models in Gemini CLI.
- OpenCode gets the model in
opencode.json, with its reasoning variants and cost. Models in OpenCode.
Qwen Code is one of the agents magpie connects too: its row takes Qwen’s models or any other vendor’s.
Thinking and images
- Whole replies. DashScope answers a thinking Qwen model only as a stream, and turns away a request for one whole reply. When an agent or a routing group’s classifier asks for one, magpie asks DashScope for a stream and gives the agent the whole reply, thinking included.
- Models that always think. Some models on DashScope refuse to have thinking turned off, such as its
glm-5.3. When an agent asks for it off and the model refuses, magpie asks again with thinking left on. - Images. The Qwen-Image and
wan2.7-imagemodels draw through DashScope’s own image API, on any of the six presets. Choose one in magpie’s Settings → Images. Give a size asWIDTHxHEIGHT, at most 2048×2048.
Balance and usage
magpie shows no balance or plan card for Qwen: DashScope has no API for a key’s balance, and neither Token Plan has one for its credits, which the plan’s subscription page in Alibaba’s console shows. The Usage tab counts tokens, cache hits and cost for each agent and model that went through magpie.
FAQ
How do I use Qwen in Claude Code?
Add your key in magpie (Providers, Add provider, then the Qwen preset your key is from), then pick a Qwen model such as qwen3.8-max on Claude Code’s row, or run magpie claude qwen/qwen3.8-max. magpie writes Claude Code’s settings.json and passes its requests to DashScope’s Anthropic endpoint.
Can Codex use Qwen, Qwen3 Coder included?
Yes. magpie lists the models DashScope gives your key, coder models included, and Codex can use any of them: magpie translates Codex’s Responses requests to Chat Completions and the replies back. Pick the model on Codex’s row or run magpie codex qwen/qwen3.8-max; it shows in Codex’s /model list.
Which preset do I pick for my key?
The one whose site the key is from. A Token Plan key (sk-sp-…) works only on its own plan’s host, and a Qwen Cloud pay-as-you-go key (sk-ws-…) only in its own region, so a key added to another preset is turned away with 401.
Can Qwen Code use other models?
Yes. Qwen Code is one of the agents magpie connects, so its row in the Agents tab takes any model you have added, Qwen’s or another vendor’s.
Why does a Qwen request without streaming work in magpie?
DashScope turns away a thinking Qwen model asked for one whole reply (enable_thinking must be false for non-streaming calls). magpie asks for it streamed and hands the agent the whole reply, thinking included.
Does magpie show my Token Plan credits?
No. Neither Token Plan has an API for its credits; the plan’s subscription page in Alibaba’s console shows them. magpie’s Usage tab still counts the tokens each agent spent.
Every agent: Models in Claude Code, Models in Codex, Models in Gemini CLI, Models in OpenCode. Ask on Discord if you get stuck.