
Run Claude Code with a different model provider: the variables per vendor, what CC Switch and magpie write, and what breaks
Tools in this post
To run Claude Code on another vendor's model, you set ANTHROPIC_BASE_URL to the vendor's Anthropic-compatible endpoint, put the vendor's key in ANTHROPIC_AUTH_TOKEN and map all four model tiers to the vendor's models, which takes about ten minutes. The steps below are copied from each vendor's docs on 14 October 2026, when Claude Code 2.1.299 was the latest release; some vendors last tested older versions. Anthropic's gateway docs say it does not support routing Claude Code to non-Claude models, so when something breaks, the vendor's docs and issue tracker are where the fix is.
The harness lock-in post covers what you leave behind in plugins, hooks and sessions. This one is the setup.
What you need
- Claude Code 2.1.268 or later. Versions 2.1.265 to 2.1.267 sent a tool schema that Z.ai and DeepSeek rejected on every interactive request (issue #92964).
- A key for the vendor. At Kimi, pay-as-you-go keys and the coding plan are separate products with different endpoints, and MiniMax's endpoint below takes an M Plan key.
- For a local model, Ollama, with its context length set to 64k or more.
| Vendor | Endpoint for ANTHROPIC_BASE_URL |
Model the vendor's docs put on the top tiers |
|---|---|---|
| DeepSeek API | https://api.deepseek.com/anthropic |
deepseek-flash[1m] |
| Kimi API | https://api.moonshot.ai/anthropic |
kimi-k3[1m] |
| Kimi Code plan | https://api.kimi.ai/coding/ |
k3-256k or k3[1m] |
| Z.ai GLM Coding Plan | https://api.z.ai/api/anthropic |
glm-5.3[1m] |
| MiniMax M Plan | https://api.minimax.io/anthropic |
MiniMax-M3.1-Flash-Preview[1m] |
| OpenRouter | https://openrouter.ai/api |
~anthropic/claude-sonnet-latest[1m], or any model with CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 |
| Ollama | http://localhost:11434 |
Any local model |
Sources: DeepSeek, Kimi API, Kimi Code, Z.ai, MiniMax, OpenRouter, Ollama.
1. Test the endpoint with curl first
Testing the endpoint before Claude Code starts separates a wrong URL or key from a Claude Code problem. Anthropic's connection guide gives this request:
curl -sS -w '\n%{http_code}\n' -X POST "$ANTHROPIC_BASE_URL/v1/messages" \
-H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "claude-sonnet-4-6", "max_tokens": 1, "messages": [{"role": "user", "content": "."}]}'
An error naming an unknown model still means the URL and key work. A 401 means the key was rejected. The base URL ends before /v1: adding /v1 yourself produces /v1/v1/messages.
2. Set all four model tiers in settings.json
Claude Code calls four model tiers, not one: Opus, Sonnet and Fable for the main work, Haiku for background calls, plus a separate model for subagents. Kimi's docs warn that setting only some of them makes the rest fail silently. DeepSeek's snippet does not set the Fable tier (ANTHROPIC_DEFAULT_FABLE_MODEL), and DeepSeek maps any model name it does not support to deepseek-flash. DeepSeek's setup, moved into the env block of ~/.claude/settings.json:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
"ANTHROPIC_AUTH_TOKEN": "<your DeepSeek API key>",
"ANTHROPIC_MODEL": "deepseek-flash[1m]",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-flash[1m]",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-flash[1m]",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek-flash",
"CLAUDE_CODE_SUBAGENT_MODEL": "deepseek-flash",
"CLAUDE_CODE_EFFORT_LEVEL": "max",
"CLAUDE_CODE_AUTO_COMPACT_WINDOW": "786432"
}
}
Use ~/.claude/settings.json for every project or .claude/settings.local.json for one, never the committed .claude/settings.json. When a shell export and the settings file set the same variable, the settings file wins, so a leftover env block overrides whatever you export later. Use ANTHROPIC_AUTH_TOKEN unless the vendor says otherwise; Kimi's coding plan is the exception and uses ANTHROPIC_API_KEY. ANTHROPIC_SMALL_FAST_MODEL, which older guides set, is deprecated in favour of ANTHROPIC_DEFAULT_HAIKU_MODEL.
For Ollama, ollama launch claude does all of this for one run: it sets the variables on the child process only and writes no Claude Code settings file (source).
3. Check /status, then the vendor's dashboard
/status in Claude Code confirms the switch: it shows an Anthropic base URL line only when a gateway is set, and an Auth token: ANTHROPIC_AUTH_TOKEN line when the key is the one in use. A Login method line naming claude.ai means your vendor key is not active. Then run /model and check that each tier lists the vendor's model.
Read the bill on the vendor's dashboard, not the dollar figure in /usage (/cost is now an alias for it), which Claude Code computes locally from token counts at list price (costs). The model names mislead too: DeepSeek maps claude-opus requests to deepseek-v4-pro and bills the V4 Pro price (DeepSeek), and since about 9 October its endpoint echoes the requested model back, so transcripts record Opus (issue #101637). /usage does show the prompt cache hit ratio, which is the number to watch.
What CC Switch and magpie write to disk
A switcher does steps 2 and 3 for you, and it rewrites your config each time you switch. CC Switch v4.0.11, released 13 October with 144,049 GitHub stars, and magpie v0.1.1233, released 14 October with 12,231 stars, are both MIT-licensed and touch the same file.
| CC Switch | magpie | |
|---|---|---|
| Claude Code file it edits | env keys and model in ~/.claude/settings.json; leaves permissions, hooks and plugins alone |
env keys in ~/.claude/settings.json; restores the old values when you switch back |
| OpenAI Codex | Writes [model_providers.custom] to ~/.codex/config.toml and deletes ~/.codex/auth.json on a direct switch, stashing the login |
Adds [model_providers.magpie] and a model catalog file |
| Local proxy | 127.0.0.1:15721 in Routing mode, which writes the placeholder key PROXY_MANAGED |
Gateway at 127.0.0.1:3425, translating between API formats |
| Its own data | ~/.cc-switch/ (SQLite database, backups every 24 hours) |
~/.config/magpie/ (keys in providers.json, replaced values in stash.json) |
Sources: CC Switch config file docs, magpie reference, magpie README.
Three side effects to know. CC Switch does not save the model you picked with /model back to the previous provider. magpie's docs say a key in ANTHROPIC_AUTH_TOKEN signs Claude Code out of claude.ai while it runs through magpie, which turns off claude.ai's plan limits in /usage, its connectors, voice and /teleport, and that Remote Control stays off because Claude Code offers it only on Anthropic's own address. magpie also reads your existing Claude Code and Codex sign-ins to offer them as providers (magpie accounts discovery off stops it) and sends one usage ping a day unless DO_NOT_TRACK=1 is set.
What goes wrong, and the fix
The cache misses and the bill jumps
Prompt caching is where a provider swap costs or saves the most, because a long session resends the whole context every turn. Anthropic's caching docs warn that a gateway which drops the cache markers "bills as uncached input on every turn". DeepSeek ignores the markers and caches on its own, best-effort, so hits are not guaranteed. OpenRouter keeps a session on one provider for its cache until 10 minutes of inactivity. Ollama does not support the markers, which costs nothing on a local model.
Input cost of one turn that resends a 100,000-token context, at each vendor's list price on 14 October 2026 (output and cache writes left out):
| Model | Uncached | Cached |
|---|---|---|
| Claude Sonnet 5.5 | $0.20 | $0.01 |
| DeepSeek V4.1 Flash, peak hours | $0.03 | $0.0006 |
| DeepSeek V4 Pro, peak hours | $0.132 | $0.0044 |
| Kimi K3 | $0.30 | $0.03 |
| GLM-5.3, pay-as-you-go | $0.14 | $0.026 |
| MiniMax-M3 | $0.03 | $0.006 |
Prices: Anthropic, DeepSeek, Kimi, Z.ai, MiniMax. DeepSeek halves both prices off-peak. A missed cache on DeepSeek V4 Pro ($0.132) or even V4.1 Flash ($0.03) costs more than a hit on Sonnet 5.5 ($0.01), so a cheaper model with a broken cache can cost more than the Claude model it replaced. Kimi K3 lists input above Sonnet 5.5, at $3 against $2 per million tokens.
Fix: watch the hit ratio in /usage for the first sessions, and do not switch provider in the middle of a session: CC Switch's docs note that the new model has to rebuild its prompt cache.
Background calls fail with "invalid thinking"
Some models only run with thinking on. Kimi's docs show kimi-k2.7-code, which their own setup puts on the Haiku tier, rejecting requests sent with thinking off with 400 invalid thinking: only type=enabled is allowed for this model, and tell you to keep thinking on in Claude Code. MiniMax's M3.1 Flash Preview also cannot turn thinking off. CC Switch hit this when its Routing mode wrote the Haiku tier as claude-haiku-4-5, a name Claude Code treats as able to run without thinking, and fixed it on 12 October.
Fix: keep thinking on, or put a model that accepts thinking off on ANTHROPIC_DEFAULT_HAIKU_MODEL, and update the switcher.
/context shows a 200k window on a 1M model
Claude Code assumes 200,000 tokens for a model name it does not know, so it compacts early or reports a nearly full context before the first message (issue #94487). Without a matching auto-compact window, it can also run into the vendor's real limit.
Fix: use the [1m] suffix the vendor's docs give, or set CLAUDE_CODE_MAX_CONTEXT_TOKENS and CLAUDE_CODE_AUTO_COMPACT_WINDOW to the model's real window (env vars). An ID with [1m] ignores CLAUDE_CODE_MAX_CONTEXT_TOKENS unless CLAUDE_CODE_DISABLE_1M_CONTEXT=1 is also set.
Requests fail after a Claude Code update
New Claude Code releases send new tool schemas and beta fields that other vendors' endpoints may reject. Anthropic's troubleshooting table gives CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 for an Extra inputs are not permitted error. For a schema error that starts with one release, check the vendor's and the switcher's issue trackers before downgrading.
Images and web search stop working
DeepSeek V4 Pro does not take images; only Flash does. Claude Code's WebSearch tool runs on Anthropic's search backend, which DeepSeek's endpoint serves itself at extra token cost; Z.ai and MiniMax offer search through MCP servers instead.
When the vendor's own harness is the better choice
If you will run one vendor's model full time, its own harness avoids most of these failures: ZCode for GLM, DeepSeek Harness (a preview), Kimi Code for Kimi, or a model-agnostic one such as Pi, all among the AI coding tools developers list. The swap makes sense when you want Claude Code's hooks, skills and plugins and a cheaper model for part of the work, which is the trade the model routing post prices. On Stackness, as of 14 October 2026, 8 real profiles list Claude Code, 1 lists Kimi K3 and none list CC Switch or magpie, after removing bot accounts (data sources), so these are early setups.
Checklist
[ ] Claude Code 2.1.268 or later
[ ] curl test returns 200 or an unknown-model error, not 401
[ ] ANTHROPIC_BASE_URL without /v1, key in ANTHROPIC_AUTH_TOKEN (Kimi Code: ANTHROPIC_API_KEY)
[ ] Opus, Sonnet, Fable, Haiku and subagent models all set, in ~/.claude/settings.json or settings.local.json
[ ] Haiku-tier model works with the thinking setting you run
[ ] [1m] suffix or CLAUDE_CODE_MAX_CONTEXT_TOKENS matches the real window
[ ] /status shows the base URL and the auth token line
[ ] cache hit ratio checked in /usage; bill read on the vendor's dashboard
[ ] no provider switch mid-session
Which of these do you use?
Nobody on Stackness runs OpenRouter yet. Tick what you use and be the first.



