Qwen Code: modelProviders in settings.json
Configure Qwen Code for uttapen: a modelProviders block in settings.json with baseUrl and envKey, a max_tokens ceiling, or the quick env-var route.
Updated: 22 Sep 2026
Qwen Code is a terminal coding agent whose openai provider type speaks Chat Completions by default — exactly what uttapen serves. This page was checked against the repository's official docs in September 2026.
The quick route
export OPENAI_BASE_URL="https://api.uttapen.ir/v1"
export OPENAI_API_KEY="sk-up-..."
export OPENAI_MODEL="anthropic/claude-sonnet-5"
qwen
For something more permanent — several models, token ceilings, switching with /model — write a modelProviders block in ~/.qwen/settings.json.
settings.json
{
"modelProviders": {
"openai": [
{
"id": "anthropic/claude-sonnet-5",
"name": "Claude Sonnet 5",
"envKey": "UTTAPEN_API_KEY",
"baseUrl": "https://api.uttapen.ir/v1",
"generationConfig": {
"contextWindowSize": 200000,
"samplingParams": { "max_tokens": 8192 }
}
},
{
"id": "qwen/qwen3-coder",
"name": "Qwen3 Coder",
"envKey": "UTTAPEN_API_KEY",
"baseUrl": "https://api.uttapen.ir/v1",
"generationConfig": {
"contextWindowSize": 262144,
"samplingParams": { "max_tokens": 8192 }
}
}
]
},
"security": { "auth": { "selectedType": "openai" } },
"model": { "name": "anthropic/claude-sonnet-5" }
}
idis the uttapen model id; ids containing/are fine. Copy them from the model list.envKeyis the name of an environment variable, not the key itself. Export yoursk-up-…key under that name, or put it in the project's.envand keep.envin.gitignore.samplingParams.max_tokensis the per-request output ceiling and the number we reserve against (pricing).8192is sensible for code work; a bigger number just locks up your balance.- Set
contextWindowSizeto the model's real context, or lower. - Don't add
wireApi: leaving it out means Chat Completions. WithwireApi: "responses"the request goes to a path uttapen doesn't serve and returns404.
After that, switch models with /model inside the tool.
Keeping cost in check
- Give Qwen Code its own key with a monthly cap (API keys) so its spend shows separately in Dashboard → Usage.
- For light work, add a second entry with a cheap model such as
openai/gpt-5-nanoorgoogle/gemini-2.5-flash-liteand a smallmax_tokens, then switch to it with/model.
Troubleshooting
| Error | Cause in Qwen Code | Fix |
|---|---|---|
401 invalid_api_key | The variable named in envKey is empty | Export it, or put it in .env |
404 model_not_found | id doesn't match a real id | Copy it from /en/models (the 404 also lists the closest ids it guessed, in uttapen.suggestions) |
404 not_found | wireApi is set to responses | Remove it |
| Model missing from the list | The entry sits under a provider id other than openai with no providerProtocol | Move it under modelProviders.openai |
402 insufficient_balance | Balance below the required hold | Top up, or lower max_tokens |
429 | The key's rate or monthly limit (rate limits) | Wait, or raise the limit |
If your available balance can't cover the full max_tokens, uttapen trims the ceiling to fit rather than refusing (floor 1,024 tokens) and returns the granted value in the X-Uttapen-Max-Tokens header; the reply may then end with finish_reason: "length". 402 appears only when even that floor doesn't fit.
Other tools are in integrations; error codes are in errors.
Sign up with a phone number, top up your wallet from 100,000 toman and create a key. Free models work without a top-up — up to 50 requests a day. Create an API key →