Skip to content
Home

Qwen Code CLI

Qwen Code CLI can use OdiRouter as an OpenAI-compatible provider under the openai auth type. Declare the model in ~/.qwen/settings.json and provide the OdiRouter API key through an environment variable.

RequirementValue
Node.jsRequired by Qwen Code CLI
OdiRouter API keyCreate one in the OdiRouter console
Base URLhttps://www.odirouter.ai/v1
Auth typeopenai
Protocolopenai
Окно терминала
npm install -g @qwen-code/qwen-code

Different Qwen Code versions may support different CLI flags. Prefer configuring the provider and model in ~/.qwen/settings.json; if you see context hard limit errors, first confirm the model entry includes generationConfig.contextWindowSize.

Окно терминала
mkdir -p ~/.qwen
nano ~/.qwen/settings.json

Do not hardcode the API key in settings.json. Qwen Code modelProviders entries can read credentials through envKey.

Окно терминала
export ODIROUTER_API_KEY="YOUR_API_KEY"

Replace the model ID with the OdiRouter model ID you want to expose in Qwen Code. Use a Qwen Code supported auth type as the modelProviders key, here openai; do not invent an odirouter auth type.

{
"modelProviders": {
"openai": {
"protocol": "openai",
"models": [
{
"id": "gpt-5.5",
"name": "GPT 5.5 via OdiRouter",
"baseUrl": "https://www.odirouter.ai/v1",
"envKey": "ODIROUTER_API_KEY",
"generationConfig": {
"contextWindowSize": 128000,
"samplingParams": {
"max_tokens": 1024
}
}
}
]
}
}
}

contextWindowSize tells Qwen Code the context window for this custom model. Without it, some Qwen Code versions may treat an unknown model’s hard limit as 0 and reject the request before sending it.

Окно терминала
cd /path/to/your/project
qwen

If Qwen Code asks you to choose a model, select the OdiRouter model from the configured provider. You can also run /model inside Qwen Code and choose GPT 5.5 via OdiRouter.

Before debugging Qwen Code, confirm that the key and model work outside the CLI:

Окно терминала
curl -sS "https://www.odirouter.ai/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.5",
"messages": [
{
"role": "user",
"content": "Reply with: Qwen Code connected to OdiRouter"
}
]
}'

Start with a read-only task:

Explain the structure of this repository and list the main entry points.

Then try a scoped edit:

Update the README with a short local development section. Show the diff before applying changes.
SymptomFix
401 or invalid keyConfirm ODIROUTER_API_KEY is available in the current shell
Model not foundQuery GET https://www.odirouter.ai/v1/models and copy the exact model ID
Config ignoredConfirm the file path is ~/.qwen/settings.json on macOS/Linux/WSL or %USERPROFILE%\.qwen\settings.json on Windows
Model does not appear in /modelConfirm the modelProviders key is openai and the model is inside the models array
Context hard limit is 0Set contextWindowSize in the model’s generationConfig
Streaming issuesTry another OdiRouter model or disable streaming if Qwen Code exposes that option