Skip to main content
kRouter
All integrations

Use Claude Code with any AI provider

Anthropic Claude Code CLI. Pointing Claude 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. Claude Code is configured through environment variables.

Setup

  1. Install kRouter

    Install globally, then start it in the background.

  2. Connect a provider

    Open the dashboard and connect whichever providers you want Claude Code to reach.

  3. Point Claude Code at kRouter

    Set the base URL to http://localhost:20128/v1 and paste a kRouter API key.

Claude Code environment variables

kRouter writes these into ~/.claude/settings.json for you, or set them yourself:

envbash
ANTHROPIC_BASE_URL=http://localhost:20128/v1
ANTHROPIC_MODEL=<provider/model-id>
ANTHROPIC_DEFAULT_OPUS_MODEL=<provider/model-id>
ANTHROPIC_DEFAULT_SONNET_MODEL=<provider/model-id>
ANTHROPIC_DEFAULT_HAIKU_MODEL=<provider/model-id>

Model slots Claude Code exposes

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

  • Claude Opus
  • Claude Sonnet
  • Claude Haiku

What changes for Claude Code

Nothing about how you use Claude 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 Claude Code

Claude Code still calls the original provider

The environment variable is set in your shell but not in the process that actually launched the tool. Restart the terminal (or the editor) after setting it, and confirm with `env | grep ANTHROPIC` in the same shell the tool runs from.

401 Unauthorized after pointing at kRouter

The auth token has to be a kRouter API key, not the upstream provider's key. Create one in the dashboard under API Keys and use that value.

Claude Code + kRouter FAQ

Can Claude 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 Claude Code can reach any of them without knowing they exist.

How is Claude Code pointed at kRouter?

Through environment variables (~/.claude/settings.json). Nothing about Claude Code itself changes — it still speaks the same API.

Does routing Claude 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 Claude Code keeps working instead of erroring out mid-task.

Get Claude 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