Tool Setup · As of 2026-11-25

Qwen Code CLI Setup (Nov 2026): settings.json modelProviders, Environment Variables in bash and PowerShell, and Using Qwen, GPT and Claude

To run Qwen Code CLI on your own API key, install it with npm install -g @qwen-code/qwen-code@latest, then declare models in ~/.qwen/settings.json under modelProviders: an openai array with baseUrl: https://api.qcode.cc/openai/v1 for qwen3.8-max, GPT-6.2 and other OpenAI-compatible models, and an anthropic array with baseUrl: https://api.qcode.cc/api for Claude. Set security.auth.selectedType and model.name, start qwen, and switch models with /model. This guide targets the Qwen Code 0.28.x settings format; run qwen --version after installing to see your build. Qwen4-Max is not on QCode /models as of 2026-11-26; check /models for changes, and see Qwen Code's own documentation for using it there. QCode is an independent third-party API service and is not affiliated with Alibaba, the Qwen team, OpenAI or Anthropic.

Updated 2026-11-26

Key facts

  • Install: npm install -g @qwen-code/qwen-code@latest. This guide follows the 0.28.x settings format; qwen --version shows the build you installed.
  • Config file: ~/.qwen/settings.json (Windows: %USERPROFILE%\.qwen\settings.json). The recommended keys are modelProviders, env, security.auth.selectedType and model.name. security.auth.apiKey and security.auth.baseUrl are deprecated.
  • Two protocols, one key: OpenAI-compatible models (qwen3.8-max, gpt-6.2-sol, deepseek-v4.1-flash, glm-5.3, kimi-k3.1-pro) go under openai; Claude (claude-opus-5-5, claude-sonnet-5-5) goes under anthropic. On QCode, Claude only works on the Anthropic path and GPT only on the OpenAI path.
  • Environment variables: OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_MODEL, and ANTHROPIC_API_KEY, ANTHROPIC_BASE_URL, ANTHROPIC_MODEL. Syntax differs: bash uses export, PowerShell uses $env:NAME = "...", cmd uses set.
  • Precedence: a selected modelProviders entry outranks CLI flags and environment variables, so an OPENAI_BASE_URL in your shell won't override the baseUrl of the model you picked.
  • Qwen4-Max: not on QCode /models as of 2026-11-26; check /models before relying on it.

What Qwen Code is

Qwen Code is an open-source terminal coding agent from Alibaba's Qwen team, originally adapted from Google's Gemini CLI. It reads and edits your repository, runs shell commands, and keeps a plan for multi-step tasks. Recent releases added sign-in with a Qwen subscription on the CLI, VS Code and desktop (2026-11-12), /autofix-pr, which watches a pull request and fixes failed checks (2026-10-29), and Agent Collaboration, which lets you @-mention Claude Code or Codex into a conversation (2026-10-15).

What matters for a custom API is its provider system. Qwen Code speaks four built-in protocols (openai, anthropic, gemini, vertex-ai), and you can declare as many models per protocol as you like. That makes it a convenient single terminal for Qwen models, GPT models, Claude and other Chinese models behind one QCode key.

Prerequisites

Item Requirement
Runtime Node.js (a current LTS release) and npm; check the Qwen Code README for the minimum version
Shell bash/zsh on macOS and Linux; PowerShell 7 or Windows PowerShell on Windows
API key A QCode key starting with cr_
Endpoints OpenAI-compatible: https://api.qcode.cc/openai/v1; Anthropic: https://api.qcode.cc/api. asia.qcode.cc and us.qcode.cc take the same paths. No trailing slash, no /chat/completions or /v1/messages

Step 1: Install Qwen Code

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

On Windows, run the same commands in PowerShell. If qwen is "not recognized" right after installing, close and reopen the terminal so it picks up the updated PATH. An npm warn install-scripts line about @qwen-code/audio-capture is a non-blocking npm 11 warning.

Step 2: Create settings.json

Create the folder and open the file. The commands differ by shell, which is where many guides go wrong:

# macOS / Linux
mkdir -p ~/.qwen
nano ~/.qwen/settings.json
# Windows PowerShell
New-Item -ItemType Directory -Force "$env:USERPROFILE\.qwen" | Out-Null
notepad "$env:USERPROFILE\.qwen\settings.json"

Paste this, replacing cr_your_key:

{
  "env": {
    "OPENAI_API_KEY": "cr_your_key",
    "ANTHROPIC_API_KEY": "cr_your_key"
  },
  "modelProviders": {
    "openai": [
      { "id": "qwen3.8-max", "name": "Qwen3.8-Max (QCode)", "envKey": "OPENAI_API_KEY", "baseUrl": "https://api.qcode.cc/openai/v1" },
      { "id": "qwen3.8-flash", "name": "Qwen3.8-Flash (QCode)", "envKey": "OPENAI_API_KEY", "baseUrl": "https://api.qcode.cc/openai/v1" },
      { "id": "gpt-6.2-sol", "name": "GPT-6.2 Sol (QCode)", "envKey": "OPENAI_API_KEY", "baseUrl": "https://api.qcode.cc/openai/v1" },
      { "id": "deepseek-v4.1-flash", "name": "DeepSeek V4.1 Flash (QCode)", "envKey": "OPENAI_API_KEY", "baseUrl": "https://api.qcode.cc/openai/v1" },
      { "id": "glm-5.3", "name": "GLM-5.3 (QCode)", "envKey": "OPENAI_API_KEY", "baseUrl": "https://api.qcode.cc/openai/v1" },
      { "id": "kimi-k3.1-pro", "name": "Kimi K3.1 Pro (QCode)", "envKey": "OPENAI_API_KEY", "baseUrl": "https://api.qcode.cc/openai/v1" }
    ],
    "anthropic": [
      { "id": "claude-sonnet-5-5", "name": "Claude Sonnet 5.5 (QCode)", "envKey": "ANTHROPIC_API_KEY", "baseUrl": "https://api.qcode.cc/api" },
      { "id": "claude-opus-5-5", "name": "Claude Opus 5.5 (QCode)", "envKey": "ANTHROPIC_API_KEY", "baseUrl": "https://api.qcode.cc/api" }
    ]
  },
  "security": { "auth": { "selectedType": "openai" } },
  "model": { "name": "qwen3.8-max" }
}

How it fits together:

  • Each key under modelProviders is a protocol, and its value is an array of models. Qwen Code reverted an older wrapped shape ({ "protocol": ..., "models": [...] }), so don't copy that from old posts.
  • envKey names the variable that holds the key. Here both protocols read the same cr_ key under two names.
  • security.auth.selectedType picks the protocol at startup and model.name the default model; it must match an id you declared.
  • modelProviders is replaced, not merged, between project settings (.qwen/settings.json in a repo) and user settings. If a project file defines modelProviders, your user list disappears in that folder.
  • Edits apply to a running session after a short debounce (about 300 ms). Reopen /model to see new entries.

Step 3: Keep the key out of settings.json (optional)

Instead of the env block, you can use a .env file. Qwen Code searches, starting in the current directory and walking upward: .qwen/.env, then .env, then ~/.qwen/.env, then ~/.env, and loads only the first file it finds. That has a sharp edge: if your project has its own .env (very common in web apps), ~/.qwen/.env is never read. Either keep the key in the env block of your user settings, or put a .qwen/.env in the project (and add it to .gitignore).

# ~/.qwen/.env  (or <project>/.qwen/.env)
OPENAI_API_KEY=cr_your_key
ANTHROPIC_API_KEY=cr_your_key

Step 4: Environment variables for a quick test or CI (bash vs PowerShell)

If you only need one OpenAI-compatible model, for example in CI, start with the protocol variables. Write them in the syntax of the shell you are actually in; if Qwen Code still asks you to choose an auth type on first run, run /auth once and pick one.

Shell Session only Persistent
bash / zsh export OPENAI_API_KEY="cr_your_key" add the line to ~/.bashrc or ~/.zshrc
PowerShell $env:OPENAI_API_KEY = "cr_your_key" setx OPENAI_API_KEY "cr_your_key", then open a new terminal
cmd.exe set OPENAI_API_KEY=cr_your_key setx OPENAI_API_KEY "cr_your_key"

Full bash example:

export OPENAI_API_KEY="cr_your_key"
export OPENAI_BASE_URL="https://api.qcode.cc/openai/v1"
export OPENAI_MODEL="qwen3.8-max"
qwen

The same in PowerShell:

$env:OPENAI_API_KEY  = "cr_your_key"
$env:OPENAI_BASE_URL = "https://api.qcode.cc/openai/v1"
$env:OPENAI_MODEL    = "qwen3.8-max"
qwen

Typical mix-ups: export in PowerShell fails with "The term 'export' is not recognized"; $env:OPENAI_API_KEY=... in bash does nothing useful; setx doesn't change the terminal you ran it in; and a value set with setx is truncated if it exceeds 1,024 characters (not an issue for a key, but it is for long PATH edits). Remember the precedence rule: once a modelProviders entry is selected, these variables don't override its baseUrl.

Step 5: Pick models for each kind of task

Task Suggested QCode model Protocol Notes
Everyday coding in Qwen's own style qwen3.8-max openai Alibaba's flagship before Qwen4-Max; 1M context per reports
Quick edits, scripts, explanations qwen3.8-flash or deepseek-v4.1-flash openai Cheapest and fastest options
Hard refactors and architecture claude-opus-5-5 anthropic $4 / $20 per million input/output tokens on /models
Balanced daily driver outside Qwen claude-sonnet-5-5 or gpt-6.2-sol anthropic / openai Both $2 / $10 on /models
Second opinion, long agentic runs kimi-k3.1-pro or glm-5.3 openai Strong open-weight coding models
Qwen4-Max not on QCode /models as of 2026-11-26 — Check /models for changes; use Qwen Code's own setup if you need it there

Billing on QCode is the official price × the service multiplier, currently ×1.0 for Anthropic and OpenAI models; see /models for live per-model rates, including Chinese models.

Step 6: Verify

  1. qwen --version prints the installed version.
  2. Inside Qwen Code, run /doctor. Authentication and Configuration should pass. On Windows, warnings such as "npm version not found" or "Git not available" don't affect the API connection.
  3. Run /model. You should see [openai] and [anthropic] entries with the base URLs you set.
  4. Send one message to qwen3.8-max, switch to claude-sonnet-5-5, and send another.
  5. If a model fails, test the endpoint directly. bash:
curl https://api.qcode.cc/openai/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"qwen3.8-max","messages":[{"role":"user","content":"Reply with pong"}],"max_tokens":16}'

PowerShell (no bash quoting or backslashes):

$headers = @{ Authorization = "Bearer $env:OPENAI_API_KEY" }
$body = @{ model = "qwen3.8-max"; max_tokens = 16; messages = @(@{ role = "user"; content = "Reply with pong" }) } | ConvertTo-Json -Depth 5
Invoke-RestMethod -Uri "https://api.qcode.cc/openai/v1/chat/completions" -Method Post -Headers $headers -ContentType "application/json" -Body $body

A reply with a choices array means the key and endpoint work; any remaining issue is in settings.json.

Common errors and fixes

Error Cause Fix
No auth type is selected settings.json missing, in the wrong folder, invalid JSON, or no selectedType Check the path, add security.auth.selectedType, validate the JSON
Model '<id>' is not available on this endpoint Model declared under the wrong protocol Claude under anthropic; GPT and Chinese models under openai
401 Unauthorized Wrong key, empty envKey variable, or a project .env shadowing yours Check the key; remember only the first .env found is loaded
404 Not Found baseUrl with a trailing slash or a full path such as /chat/completions Use exactly https://api.qcode.cc/openai/v1 or https://api.qcode.cc/api
My OPENAI_BASE_URL is ignored A selected modelProviders entry has its own baseUrl Edit the entry, or drop modelProviders for env-only use
Models missing from /model in one repo That repo's .qwen/settings.json replaces your modelProviders Add the models there too, or remove the project block
export : The term 'export' is not recognized bash syntax in PowerShell Use $env:NAME = "value"
qwen is not recognized PATH not refreshed after install Reopen the terminal; reinstall if needed

FAQ

Does Qwen Code work with non-Qwen models?

Yes. Any model behind an OpenAI-compatible endpoint works under openai, and Claude works under anthropic. With QCode you can mix qwen3.8-max, gpt-6.2-sol, deepseek-v4.1-flash, glm-5.3, kimi-k3.1-pro and claude-opus-5-5 in one settings.json and switch with /model.

Where is Qwen Code's settings.json?

~/.qwen/settings.json on macOS and Linux and %USERPROFILE%\.qwen\settings.json on Windows. A project can also have .qwen/settings.json, which replaces your user modelProviders in that folder.

What base URL do I use for Qwen Code?

https://api.qcode.cc/openai/v1 for OpenAI-compatible models and https://api.qcode.cc/api for Claude, with no trailing slash. The regional hosts asia.qcode.cc and us.qcode.cc take the same paths.

Can I use Qwen4-Max in Qwen Code through QCode?

No. Qwen4-Max is not on QCode /models as of 2026-11-26; check /models for changes. Use qwen3.8-max via QCode for now.

How do I set environment variables for Qwen Code in PowerShell?

Use $env:OPENAI_API_KEY = "cr_your_key" for the current session and setx OPENAI_API_KEY "cr_your_key" to persist it for new terminals. export is bash syntax and doesn't work in PowerShell.

Is security.auth.apiKey still supported?

It is marked deprecated. Declare models in modelProviders, point each at an envKey, and put the key in the env block or a .env file.

Why does /model show my models but requests fail with 401?

Usually the variable named in envKey is empty. Check the env block, and check whether a project .env was loaded instead of ~/.qwen/.env.

Pay only for what you use

If you use Qwen Code a few times a week, QCode's pay-as-you-go packs fit better than a subscription: no monthly plan, packs from $4 for $30 of usage, valid 7 days and stackable, with one cr_ key for Qwen, GPT, Claude and other Chinese models. See /pay-as-you-go for current packs and /models for rates.

Sources: Qwen Code docs (Model Providers, Authentication) and weekly update blog (2026-10-15, 2026-11-12, 2026-11-19); QCode docs page for Qwen Code; QCode /models. All read 2026-11-25.

Pay only for what you use

One key for both the Anthropic Messages API and OpenAI-compatible APIs. Claude and GPT are billed at the official price ×1.0; live rates are on /models.

Not sure where to start?

Try it for a week

Small Pack: $4 for $30 of quota, valid 7 days

Use it every day

Starter: $9.00/month with $5 of quota every day — just $0.060 per $1 of quota, vs about $0.113 for the Medium Pack