Claude Code
Run Claude Code on DeepSeek V4.1 Flash, or keep Claude and let the CLI's Router send the easy turns to Spare.
/v1/messagesConfig~/.claude/settings.jsonClaude Code talks to the Anthropic Messages API, which Spare serves at /v1/messages. You point it at
Spare with two environment variables, then pick one of two setups:
- Run on DeepSeek V4.1 Flash. Every request goes to Spare, at the live price.
- Keep Claude, add the Router. The CLI's Cost routing keeps hard turns on your Claude model and sends the rest to Spare.
Before you start
- A Spare API key from the console.
- For the Router: the CLI, signed in to your Claude model with an Anthropic key or a Claude Pro or Max subscription.
Put the settings below in the env block of ~/.claude/settings.json, so they apply in every project
and to background agents. Don't put keys in a project's .claude/settings.json: that file is committed.
Run on DeepSeek V4.1 Flash
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.spareinference.ai",
"ANTHROPIC_AUTH_TOKEN": "sk-spare-...",
"ANTHROPIC_MODEL": "deepseek-v4.1-flash",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-v4.1-flash",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-v4.1-flash",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek-v4.1-flash"
}
}ANTHROPIC_MODEL sets the main model. The three DEFAULT_* variables cover the model aliases Claude
Code uses for subagents and background tasks, so nothing falls through to a Claude model.
Fallbacks
If a provider fails, the request moves to the next provider serving DeepSeek V4.1 Flash on its own. To fall back to Claude instead of failing, chain the two models in the CLI; see Fall back to a different model.
Use a routing preset
Set ANTHROPIC_MODEL to @<name> to run a routing preset, so you can
change the model or providers behind Claude Code from the console without touching its settings.
Keep Claude, add the Router
Spare's API runs the model you name and doesn't route between models; the Router runs in the CLI on your machine. Set it up once, following Cost routing, with your Claude model as
the strong route and deepseek-v4.1-flash as the economy route. Then start Claude Code through the CLI:
spare claude --model spare/autoClaude Code keeps its interface and tools. spare requests shows which model served each turn.
Check it works
Start claude and run /status. The Anthropic base URL line should show
https://api.spareinference.ai, and the auth line should name ANTHROPIC_AUTH_TOKEN.
To get a request id you can look up, send one from the same shell with your key exported as SPARE_API_KEY:
curl -si https://api.spareinference.ai/v1/messages \
-H "Authorization: Bearer $SPARE_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model":"deepseek-v4.1-flash","max_tokens":16,"messages":[{"role":"user","content":"Reply with OK"}]}' \
| grep -i '^x-bitrouter-request-id'Look the id up with settlement, or find the request on the console's Activity page.
Good to know
- Anthropic doesn't support Claude Code with non-Claude models. It works through Spare's Messages API, but features that depend on Anthropic's servers, like web search and server-side tools, aren't available on DeepSeek V4.1 Flash.
- Remote Control and voice dictation turn off while
ANTHROPIC_AUTH_TOKENis set, because they need a claude.ai login. Unset it to use them. - Prompt caching is automatic. Claude Code's
cache_controlmarkers are accepted and ignored. - The desktop app reads gateway settings from Developer → Configure Third-Party Inference, not
from
settings.json. The VS Code extension reads them fromclaudeCode.environmentVariables.
How is this guide?