Skip to main content
kRouter
All integrations

Use Qwen Code with any AI provider

Alibaba Qwen Code CLI — supports OpenAI, Anthropic & Gemini providers via kRouter. Pointing Qwen Code at kRouter gives it 100+ providers behind a single local endpoint — free tiers, subscriptions you already pay for, and paid APIs — with automatic failover when one runs out. Qwen Code is configured through its own settings UI.

Note: Qwen Code supports multiple provider types (openai, anthropic, gemini) via modelProviders in settings.json. kRouter works as an OpenAI-compatible endpoint.

Note: Any model available in kRouter can be used — not just Qwen models. Select from Qwen, Claude, Gemini, GPT, and more.

Heads up: Config path: Linux/macOS ~/.qwen/settings.json • Windows %USERPROFILE%\.qwen\settings.json

Note: Qwen OAuth free tier was discontinued on 2026-04-15. Use kRouter with alicode/openrouter/anthropic/gemini providers instead.

Setup

  1. Install Qwen Code

    npm install -g @qwen-code/qwen-code

  2. API Key

  3. Base URL

    {{baseUrl}}
  4. Select Model

  5. Save Config

    Copy the JSON below to your ~/.qwen/settings.json file.

Commands

jsonbash
{
  "security": {
    "auth": {
      "selectedType": "openai",
      "apiKey": "{{apiKey}}",
      "baseUrl": "{{baseUrl}}"
    }
  },
  "model": {
    "name": "{{model}}"
  }
}

Model slots Qwen Code exposes

Each slot maps to whichever provider model you choose, so Qwen Code keeps its own naming while the request goes wherever you point it.

  • Coder Model (Qwen 3.6 Plus)
  • Qwen 3 Coder Plus
  • Qwen 3 Coder Flash
  • Vision Model (Multimodal)
  • Claude Sonnet 4.6
  • Claude Opus 4.6 Thinking
  • Gemini 3.1 Pro High
  • Gemini 3 Flash

Qwen Code documentation

What changes for Qwen Code

Nothing about how you use Qwen Code changes — same interface, same workflow. What changes is where its requests land. Instead of being tied to one vendor and one bill, every request goes through your own machine first and out to whichever provider you mapped: a free tier for routine edits, a subscription you already pay for on the heavy turns, a paid API only when nothing else fits. When one account hits a limit, the next takes over mid-session rather than failing the task. And because the router runs locally, your prompts are not passing through a third-party service on the way.

Troubleshooting Qwen Code

Qwen Code rejects the endpoint URL

Most editors validate the URL by calling it. Make sure kRouter is running first (`krouter -t`), and that you entered the /v1 suffix — the base URL is http://localhost:20128/v1.

It works locally but not from another machine

The default endpoint is loopback-only by design. Enable the tunnel or a cloud endpoint in Settings if the tool needs to reach kRouter over the network.

Qwen Code + kRouter FAQ

Can Qwen Code use providers other than its default?

Yes — that is the point of routing it through kRouter. kRouter presents one OpenAI-compatible endpoint that fans out to 100+ providers, so Qwen Code can reach any of them without knowing they exist.

How is Qwen Code pointed at kRouter?

Through its own settings UI. Nothing about Qwen Code itself changes — it still speaks the same API.

Does routing Qwen Code through kRouter cost anything?

kRouter is free and MIT-licensed and adds nothing to your bill. What you pay is whatever the provider you routed to charges — which is often nothing, if you route to a free tier or a subscription you already hold.

What happens when a provider runs out of quota mid-session?

kRouter parks that account until its real reset time and fails over to the next one you have connected, so Qwen Code keeps working instead of erroring out mid-task.

Get Qwen Code routing in two minutes

kRouter is free, MIT-licensed, and runs entirely on your machine — no account, no proxy in the middle.

Install kRouter