For AI agents, the documentation index lists all pages. Append .md to a documentation URL for Markdown, or request text/markdown.

Skip to Content
spare inference

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.

3 min readEdit this page
Claude CodeEndpoint/v1/messagesConfig~/.claude/settings.json

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

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

~/.claude/settings.json
{
  "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/auto

Claude 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_TOKEN is set, because they need a claude.ai login. Unset it to use them.
  • Prompt caching is automatic. Claude Code's cache_control markers 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 from claudeCode.environmentVariables.

How is this guide?