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" }
}
  • id is the uttapen model id; ids containing / are fine. Copy them from the model list.
  • envKey is the name of an environment variable, not the key itself. Export your sk-up-… key under that name, or put it in the project's .env and keep .env in .gitignore.
  • samplingParams.max_tokens is the per-request output ceiling and the number we reserve against (pricing). 8192 is sensible for code work; a bigger number just locks up your balance.
  • Set contextWindowSize to the model's real context, or lower.
  • Don't add wireApi: leaving it out means Chat Completions. With wireApi: "responses" the request goes to a path uttapen doesn't serve and returns 404.

After that, switch models with /model inside the tool.

Keeping cost in check

Troubleshooting

ErrorCause in Qwen CodeFix
401 invalid_api_keyThe variable named in envKey is emptyExport it, or put it in .env
404 model_not_foundid doesn't match a real idCopy it from /en/models (the 404 also lists the closest ids it guessed, in uttapen.suggestions)
404 not_foundwireApi is set to responsesRemove it
Model missing from the listThe entry sits under a provider id other than openai with no providerProtocolMove it under modelProviders.openai
402 insufficient_balanceBalance below the required holdTop up, or lower max_tokens
429The 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.

No API key yet?

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 →