Qwen Code
Point Qwen Code at RouteMux with three environment variables, or a provider entry in settings.json.
Qwen Code speaks four protocols and picks one via its auth type. The OpenAI-compatible path is the shortest route to RouteMux.
Environment variables
export OPENAI_API_KEY="sk-..." # your RouteMux key
export OPENAI_BASE_URL="https://api.routemux.com/v1"
export OPENAI_MODEL="openai/gpt-5.5" # alias: QWEN_MODELThen run qwen in your project. Exporting OPENAI_API_KEY is what selects the
OpenAI-compatible auth type — a provider-specific key variable alone will not.
Or define a provider in settings.json
Keep it at user scope, ~/.qwen/settings.json, which the docs recommend to avoid merge
conflicts:
{
"modelProviders": [
{
"id": "routemux",
"name": "RouteMux",
"baseUrl": "https://api.routemux.com/v1",
"envKey": "ROUTEMUX_API_KEY"
}
],
"security": { "auth": { "selectedType": "openai" } },
"model": { "name": "routemux" }
}model.name must match a provider id. With this saved, qwen starts without the
interactive /auth step. Inside the CLI, /model switches between configured models grouped
by protocol, and /doctor prints the resolved auth state.
Where the key comes from, in priority order
- CLI flags such as
--openai-api-key— always wins - The shell environment
- A
.envfile — only sets what is not already in the environment settings.json→env— lowest priority, and stores the key in plaintext
Only one .env file is read
Qwen Code loads the first .env it finds and does not merge across files. It walks
upward from the working directory checking .qwen/.env then .env, and falls back to
~/.qwen/.env then ~/.env. Put project secrets in .qwen/.env — it avoids clashing with
other tools and is easy to keep out of version control.
Other protocols
/auth → Custom Provider also connects Anthropic, Gemini and other compatible endpoints.
If you want Claude models, that is the path you need: they are served only on Anthropic
Messages here, and the base URL convention differs — see the
compatibility matrix.
Verify
curl https://api.routemux.com/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"openai/gpt-5.5","messages":[{"role":"user","content":"ping"}]}'Troubleshooting
| Symptom | Cause |
|---|---|
| Wrong auth type selected | A provider-specific key variable was exported instead of OPENAI_API_KEY. |
| Key changes have no effect | Something higher in the priority list is winning — a CLI flag or an already-exported shell variable overrides .env. |
Variables in a second .env ignored | Only the first file found is read; they are not merged. |
| 404 on every request | OPENAI_BASE_URL is missing /v1. |
400 MODEL_PROTOCOL_UNSUPPORTED | A Claude model over the OpenAI-compatible auth type. Use a Custom Provider on the Anthropic protocol. |
| Model rejected | Id does not match GET /v1/models. |
422 BILLING_INSUFFICIENT_CREDITS | Wallet lacks credit. Failed requests are not billed. |