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.
Requirements
Section titled “Requirements”| Requirement | Value |
|---|---|
| Node.js | Required by Qwen Code CLI |
| OdiRouter API key | Create one in the OdiRouter console |
| Base URL | https://www.odirouter.ai/v1 |
| Auth type | openai |
| Protocol | openai |
Install Qwen Code CLI
Section titled “Install Qwen Code CLI”npm install -g @qwen-code/qwen-codenpm install -g @qwen-code/qwen-codeDifferent 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.
Create The Config File
Section titled “Create The Config File”mkdir -p ~/.qwennano ~/.qwen/settings.jsonNew-Item -ItemType Directory -Force "$env:USERPROFILE\.qwen"notepad "$env:USERPROFILE\.qwen\settings.json"Set The API Key
Section titled “Set The API Key”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"$env:ODIROUTER_API_KEY = "YOUR_API_KEY"Paste The OdiRouter Model
Section titled “Paste The OdiRouter Model”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.
Start Qwen Code
Section titled “Start Qwen Code”cd /path/to/your/projectqwenIf 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.
Verify The API Key
Section titled “Verify The API Key”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.Troubleshooting
Section titled “Troubleshooting”| Symptom | Fix |
|---|---|
401 or invalid key | Confirm ODIROUTER_API_KEY is available in the current shell |
| Model not found | Query GET https://www.odirouter.ai/v1/models and copy the exact model ID |
| Config ignored | Confirm the file path is ~/.qwen/settings.json on macOS/Linux/WSL or %USERPROFILE%\.qwen\settings.json on Windows |
Model does not appear in /model | Confirm the modelProviders key is openai and the model is inside the models array |
Context hard limit is 0 | Set contextWindowSize in the model’s generationConfig |
| Streaming issues | Try another OdiRouter model or disable streaming if Qwen Code exposes that option |