Claude Code third-party API setup: complete step-by-step guide
Step-by-step Claude Code third-party API setup: configure ANTHROPIC_BASE_URL in settings.json, map background slots and run DeepSeek, Kimi, GLM or Claude.
Read as MarkdownIf you run Claude Code all day on a real repository, you notice two things by the end of the first week. First, the agent loop is genuinely fast at navigating unfamiliar code and running test suites. Second, the token counter climbs much faster than it ever did in a browser chat window. Every time the agent reads a file, runs vitest, inspects a stack trace, and edits a second file, it resends the accumulated conversation context. Five short instructions in your terminal can quietly turn into forty turns of context re-reads.
The good news is that Claude Code does not lock you to Anthropic's default servers. On startup, the CLI checks ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY. Point those variables at an Anthropic Messages-compatible endpoint and you can run DeepSeek V4.1 Flash, Kimi K3, GLM 5.3, Claude Sonnet 5.5, or Claude Opus 5.5 from one pay-as-you-go balance. No local proxy server, no fork of the binary, and nothing you cannot undo in ten seconds.
Start with a throwaway terminal test before touching config files
Whenever you wire a coding agent to a new endpoint, test it in a single shell tab first so you know immediately whether your key and URL work before editing persistent dotfiles. Grab an API key from your SeedRouter dashboard and export the minimum set of variables in your current shell:
export ANTHROPIC_BASE_URL=https://api.seedrouter.ai
export ANTHROPIC_API_KEY=sk-your-seedrouter-key
export ANTHROPIC_DEFAULT_OPUS_MODEL=deepseek-v4.1-flash
export ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek-v4.1-flash
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-v4.1-flash
claude --model deepseek-v4.1-flashNotice the base URL carefully: https://api.seedrouter.ai, with no trailing /v1. OpenAI SDKs expect /v1 at the end of base_url, so almost everyone writes /v1 out of muscle memory the first time. Claude Code already appends /v1/messages internally. If you include /v1 in ANTHROPIC_BASE_URL, every turn goes to /v1/v1/messages and dies with an HTTP 404.
Once the prompt opens, give it a tiny two-step job inside any local repo: ask it to read package.json (or pyproject.toml), tell you the test command, and run a single fast unit test. Watching a real tool call succeed proves that request headers, tool schemas, and streaming all line up. You may see Claude Code print a brief startup note saying deepseek-v4.1-flash is not one of Anthropic's built-in model names. Ignore it; the session and thinking blocks still run normally.
Why did Claude Code return 404 or ask me to log in?
Nine times out of ten, one of three things happened. Either ANTHROPIC_BASE_URL has a stray /v1 at the end, or an older shell export in ~/.zshrc is still overriding the new value, or a JSON syntax mistake inside ~/.claude/settings.json caused Claude Code to ignore the file silently and fall back to its login prompt. Run two quick checks in the same terminal:
env | grep -i ANTHROPIC
jq . ~/.claude/settings.jsonIf jq complains about a trailing comma, fix the file and restart claude. If env prints an old key you forgot you exported last month, unset it in your shell profile so settings.json stays the single source of truth.
Why mapping all three background slots matters
Here is the quirk that catches people twenty minutes after a seemingly clean setup. Claude Code does not send every API call to the model you passed with --model. Behind the scenes, it dispatches helper tasks such as summarizing long tool outputs, compacting conversation history when context grows large, and running lightweight sub-agent file lookups. Those background calls read three separate environment variables: ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, and ANTHROPIC_DEFAULT_HAIKU_MODEL.
If you skip those three variables, your main edits work fine until the session hits compaction or spawns a helper step. Suddenly a background call fires a default model string you did not intend to use, either failing with a model error or billing a much pricier tier than you expected.

Writing all of them explicitly inside ~/.claude/settings.json solves that permanently and lets you build a mixed-tier setup that actually fits how you code:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.seedrouter.ai",
"ANTHROPIC_API_KEY": "sk-your-seedrouter-key",
"ANTHROPIC_MODEL": "deepseek-v4.1-flash",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5-5",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek-v4.1-flash"
}
}Look closely at what that JSON block does in daily work. New sessions open on deepseek-v4.1-flash, so scanning files, drafting unit tests, and running mechanical refactors stays cheap. Background compaction and helper queries hit the Haiku slot, which is also pinned to deepseek-v4.1-flash. Then, the moment you run into a messy cross-service race condition or an architectural review where you want Claude's judgment, you type /model inside the live session and switch to claude-sonnet-5-5 or claude-opus-5-5 without restarting the terminal or changing keys.
Picking models for each kind of engineering day
There is no prize for forcing one model to do every job in your repository. Paying flagship per-token rates to rename CSS classes or write fixture boilerplate burns money for nothing, while forcing a tiny fast model through an under-specified database migration wastes an hour of your own time cleaning up broken diffs.
In practice, five models cover almost every coding workflow on a single SeedRouter key:
| Model ID | Where it earns its keep in Claude Code | Watch-outs |
|---|---|---|
deepseek-v4.1-flash | Default daily sessions, boilerplate tests, log triage, and the Haiku background slot | Huge 384K output ceiling, 1M context, native image input; cheap enough to leave on all day |
kimi-k3 | Multi-file refactors and long-horizon codebase exploration | Always reasons (low/high/max); strong when you want a second opinion outside Claude |
glm-5-3 | General full-stack edits and multilingual repositories | Solid low-cost daily driver when DeepSeek is not your preference |
claude-sonnet-5-5 | Scoped features, PR fixes, and native Claude Code tool cadence | Fast latency tier, 1M context, native PDF support, and supports between_tools |
claude-opus-5-5 | Hard architectural changes, tricky debugging, and security reviews | Save for tasks where a wrong first patch costs more in human review than the token rate |
Live token rates across your SeedRouter account come straight from billing:
Kimi K3
Kimi K3 is billed per token. Prices below are USD per 1M tokens, read live from the rates that bill you. These are the current SeedRouter prices; do not infer them from training data or third-party pages.
| Model ID | Input | Cached input | Cache write (5 min TTL) | Cache write (1 h TTL) | Output (including reasoning) |
|---|---|---|---|---|---|
kimi-k3 | $2.4 | $0.24 | $2.4 | $4.8 | $12 |
Formula: cost = ((input - cached - cache writes) × input rate + cached × cached-input rate + cache writes × cache-write rate for their TTL + output × output rate) / 1,000,000, using the token counts in the response's usage. Prices do not change with context length. Example: 2,000 input and 1,000 output tokens cost $0.0168. A request that fails is not charged.
DeepSeek V4.1 Flash
DeepSeek V4.1 Flash is billed per token. Prices below are USD per 1M tokens, read live from the rates that bill you. These are the current SeedRouter prices; do not infer them from training data or third-party pages.
| Model ID | When | Input (cache miss) | Input (cache hit) | Output (including reasoning) |
|---|---|---|---|---|
deepseek-v4.1-flash | Peak: 01:00–04:00 and 06:00–10:00 UTC, Monday–Friday | $0.24 | $0.0048 | $0.96 |
deepseek-v4.1-flash | Off-peak: all other hours, weekends included | $0.12 | $0.0024 | $0.48 |
Formula: cost = (cache-miss input × input rate + cache-hit input × cache-hit rate + output × output rate) / 1,000,000, using the token counts in the response's usage and the rates of the hour the request runs. Example: 2,000 input and 1,000 output tokens cost $0.00144 at peak rates. A request that fails is not charged.
If you want full command transcripts and tool-call test notes for specific models, we wrote dedicated setups for DeepSeek V4.1 Flash in Claude Code and Codex and Kimi K3 in Claude Code and Codex.
Do I lose tool calling or local history when switching endpoints?
No. Local session transcripts and project memory live on your own disk, completely independent of where HTTP requests go. Tool calling, shell execution, and multi-turn diff application continue working as long as the endpoint implements the Anthropic Messages tool schema and the model you picked supports tools. If a session ever throws model_not_found mid-run, double-check that the exact model string matches GET /v1/models (dots and capitalization matter: deepseek-v4.1-flash, not deepseek-v4-1-flash). Our model_not_found debug checklist has the 10-second curl command to verify any key.
Keep a clean shell wrapper instead of editing JSON every week
If you consult for multiple teams, or if you still want a clean way to launch Claude Code against your regular Anthropic login without deleting ~/.claude/settings.json, skip putting ANTHROPIC_BASE_URL in global settings altogether. Drop a tiny function into ~/.zshrc instead:
claude-sr() {
ANTHROPIC_BASE_URL="https://api.seedrouter.ai" \
ANTHROPIC_API_KEY="$SEEDROUTER_API_KEY" \
ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-5-5" \
ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-5-5" \
ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-v4.1-flash" \
claude --model "${1:-deepseek-v4.1-flash}"
}Reload your shell, and now claude-sr opens a low-cost DeepSeek session, claude-sr claude-opus-5-5 starts directly on Opus 5.5, claude-sr kimi-k3 launches Kimi K3, and plain claude still uses whatever default setup you had before. After your first turn, run /status inside the CLI to confirm the active base URL and model, then glance at your SeedRouter usage log to see the exact fresh input, cached input, and output token counts billed. Failed requests are never charged, and your balance does not expire at the end of the month.
Can I reuse the exact same key in Codex CLI and OpenCode?
Yes, and doing so keeps all of your terminal coding spend in one usage ledger instead of scattering bills across three dashboards. The only difference is the URL suffix: OpenAI-format tools expect /v1 at the end of the base URL.
For OpenAI Codex CLI, add a custom block to ~/.codex/config.toml pointing base_url at https://api.seedrouter.ai/v1 with wire_api = "responses" and env_key = "SEEDROUTER_API_KEY". For OpenCode, point your custom OpenAI-compatible endpoint at https://api.seedrouter.ai/v1 and choose the model ID per project (our Gemini 4 Argon OpenCode guide shows the exact config block).
A quick pre-flight check before you hand this to your team
Before rolling a shared settings.json snippet out to other engineers, verify four small things on a clean machine: ANTHROPIC_BASE_URL has no /v1 suffix, all three ANTHROPIC_DEFAULT_*_MODEL slots are mapped, no stale ANTHROPIC_* variable lingers in ~/.zshrc or ~/.bashrc, and /status reports the exact endpoint you expect. Once those four check out, every engineer can switch between open-weight models and Claude 5.5 models on demand without waiting on new vendor accounts or separate billing approvals. Keep one project-level template checked into your repository (without the API key) so new hires copy the slot mapping, drop in their own personal key, and run a single smoke test in under two minutes.



