contenox

Qwen coding agent: API key, models and setup

Updated

MODEL PROVIDERS Qwen

To set up a Qwen coding agent, get an API key from Alibaba Cloud Model Studio and give it to your agent. Alibaba makes its own open-source agent, Qwen Code, and publishes setups for Claude Code, Codex CLI and OpenCode that point at its endpoints. Any agent that takes an OpenAI-compatible base URL works too, and Contenox is one of them. Billing is per token, or a subscription called Token Plan.

Qwen is Alibaba’s model family. Some of it is open weights under Apache-2.0, such as Qwen3.8-27B and Qwen3-Coder-Next, so you can also run Qwen on your own machine.

Use Qwen with your agent

AgentSupported?HowNote
Qwen CodeYes, Alibaba’s ownqwen, then /auth → Alibaba ModelStudioApache-2.0. Takes Token Plan, Coding Plan or a pay-as-you-go key
Claude CodeWorks, not supported by AnthropicANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKENAlibaba documents it
Codex CLIYes, by Alibaba’s docs[model_providers.*] in ~/.codex/config.tomlCodex 0.94.0 or later uses the Responses API
OpenCodeYes, by Alibaba’s docsA custom provider in opencode.jsonNot in OpenCode’s built-in list
Cline, KiloYesOpenAI Compatible provider with a Base URLSame key and URL as above
ContenoxYesBackends → Providers → Alibaba Cloud Model StudioUnder Recommended; thinking switch and streamed reasoning for the hybrid models

Alibaba’s plan pages also list Cursor, Qoder, Trae and others. Each plan has its own key and its own URL, and they are not interchangeable: Alibaba Cloud Model Studio for coding agents has the full table.

Qwen Code

Qwen Code reads and edits files, runs commands, and has sub-agents, skills, MCP, hooks, a headless mode (qwen -p "...") and approval modes. It runs in VS Code, Zed and JetBrains, and has a desktop app.

Install, with Node.js 22 or later for the npm route:

npm install -g @qwen-code/qwen-code@latest

Or brew install qwen-code, or the standalone installer. Windows PowerShell:

irm https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen-standalone.ps1 | iex

Run qwen, choose Alibaba ModelStudio, pick your plan, choose the Singapore region and paste the key. Check it with qwen -p "Hello". Or run /auth inside a session. The menu also offers QwenCloud, third-party providers such as DeepSeek and OpenRouter, and a custom provider for a local server.

The free-tier trap: older guides tell you to sign in with Qwen OAuth for a free daily allowance. That sign-in is discontinued, and its free tier ended on 15 April 2026. You need a key.

Claude Code

Alibaba’s Anthropic-compatible endpoint lets Claude Code run on Qwen models. Anthropic doesn’t support routing Claude Code to non-Claude models; Alibaba documents it. This is the Token Plan setup. Windows PowerShell:

$env:ANTHROPIC_BASE_URL="https://token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic"
$env:ANTHROPIC_AUTH_TOKEN="<your Token Plan key>"
$env:ANTHROPIC_MODEL="auto"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL="qwen3.6-flash"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL="qwen3.8-flash"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL="qwen3.8-max"
$env:CLAUDE_CODE_SUBAGENT_MODEL="auto"
claude

macOS or Linux:

export ANTHROPIC_BASE_URL=https://token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic
export ANTHROPIC_AUTH_TOKEN=<your Token Plan key>
export ANTHROPIC_MODEL=auto
export ANTHROPIC_DEFAULT_HAIKU_MODEL=qwen3.6-flash
export ANTHROPIC_DEFAULT_SONNET_MODEL=qwen3.8-flash
export ANTHROPIC_DEFAULT_OPUS_MODEL=qwen3.8-max
export CLAUDE_CODE_SUBAGENT_MODEL=auto
claude

Check with claude -p "Hello". The same variables go under env in ~/.claude/settings.json if you want them to persist. If Claude Code asks you to log in to Anthropic, set hasCompletedOnboarding to true in ~/.claude.json.

For a pay-as-you-go key, the base URL is https://<WorkspaceId>.ap-southeast-1.maas.aliyuncs.com/apps/anthropic and the model names change. Alibaba’s Claude Code page has the table for each plan.

Codex CLI

Codex takes a custom provider in ~/.codex/config.toml (C:\Users\<you>\.codex\config.toml on Windows). Codex ignores model_providers in a project’s .codex/config.toml, so put it in the user file. Token Plan:

model_provider = "Token_Plan"
model = "auto"

[model_providers.Token_Plan]
name = "Token_Plan"
base_url = "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"

Set OPENAI_API_KEY to your Token Plan key, then check with codex exec "Hello". This is Alibaba’s config for Codex 0.94.0 or later, which speaks only the Responses API. A mismatched base_url or wire_api gives a 404.

Coding Plan is the exception: Alibaba’s page says it needs Chat Completions and Codex 0.93.0 or earlier, while its own quick-start block shows responses. If you have a Coding Plan, read that page before you pin an old Codex version.

OpenCode

Alibaba Cloud isn’t in OpenCode’s built-in provider list, so define it in opencode.json (~/.config/opencode/opencode.json, or C:\Users\<you>\.config\opencode\opencode.json on Windows). Alibaba’s config uses the Anthropic-compatible endpoint:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "bailian-token-plan": {
      "npm": "@ai-sdk/anthropic",
      "name": "Alibaba Cloud Model Studio",
      "options": {
        "baseURL": "https://token-plan.ap-southeast-1.maas.aliyuncs.com/apps/anthropic/v1",
        "apiKey": "{env:BAILIAN_TOKEN_PLAN_API_KEY}"
      },
      "models": {
        "auto": { "name": "auto" },
        "qwen3.8-max": { "name": "Qwen3.8 Max" },
        "qwen3.8-flash": { "name": "Qwen3.8 Flash" }
      }
    }
  }
}

Start opencode and pick the model with /models. If a model is missing, upgrade OpenCode first. Note the /v1 on the end of the OpenCode URL; the Claude Code URL has none.

Cline and Kilo Code

Both treat Alibaba as a generic OpenAI-compatible provider. In Cline, open settings, set API Provider to OpenAI Compatible, and enter the Base URL, your key and a Model ID. In Kilo, use Settings → Providers → Custom provider and choose OpenAI Compatible as the Provider API. Token Plan’s Base URL is https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1.

Which Qwen model should I pick?

Model Studio currently lists these for text and code:

  • qwen3.8-max: Alibaba’s pick for complex reasoning and coding. Use it for changes across many files and for planning.
  • qwen3.7-plus: balanced between quality, speed and cost.
  • qwen3.8-flash: fast and cheap. Good for small edits and questions.

Names have to match exactly, and they are case-sensitive. A wrong name returns a 404.

Best Qwen model for coding has the longer list, by job.

Run Qwen on your own machine

The open-weight Qwen models run in Ollama. With a 24 GB GPU, ollama pull qwen3.8:27b downloads 18 GB with a 256K context. qwen3-coder-next is 52 GB and qwen3-coder:30b is 19 GB. The tags, memory and context settings are in best Ollama models for coding, and the agent setup is on the Ollama page. Nothing leaves your computer.

Common errors

  • 401, invalid key or token: the key doesn’t match the base URL. Token Plan, Coding Plan and pay-as-you-go keys each need their own URL. Plan keys start with sk-sp-.
  • 403, invalid api-key: a plan key sent to the general Model Studio URL. Use the plan’s URL.
  • 404, model not found: the model name is misspelled, or in Codex the wire_api doesn’t match the URL.
  • 429: too many requests at once. Wait about a minute and run fewer agents in parallel. On Token Plan, insufficient_quota means the monthly allowance is used up.
  • 403 AccessDenied on a model: Alibaba retires models. Ones marked as upcoming deprecation in its Model Gallery return this. Switch to a current name.

Where does my code go?

Keys are tied to a region. Alibaba says each region has its own endpoint, API key and model list, and they can’t be used across regions. Request data is stored in the region you select. The plan setups above use the Singapore region; the pay-as-you-go endpoints exist for Beijing and Singapore, among others, and Beijing keys won’t work against Singapore URLs. Read Alibaba Cloud’s terms for your plan, and your employer’s rules, before you connect.

If code must stay home, run the open-weight models locally as above, or use OpenRouter and check which provider serves your requests.

Contenox

Contenox has Alibaba Cloud Model Studio as a provider of its own, next to DeepSeek, and lets you switch between Qwen and other providers per session.

  1. Open Backends → Providers and, under Recommended, choose Alibaba Cloud Model Studio.
  2. Select Create key, create a key in Model Studio and copy it.
  3. Paste it into API Key. For the China region or a Coding Plan key (it starts with sk-sp-), open Advanced and set Base URL to that endpoint; the international endpoint is the default.
  4. Select Connect and wait for Connected. The Model chip then lists the models your key can reach.

To keep the key out of the app, enter DASHSCOPE_API_KEY under Advanced in Environment variable name and set the variable on your system instead.

On releases before the provider shipped, the same works through More providers → OpenAI with the Model Studio key and the endpoint in Base URL; type the model name in the Model chip.

contenox-runtime backend add alibaba --type alibaba-cloud --api-key-env DASHSCOPE_API_KEY

Related

Esc to close