Use a Third-Party API with Claude Code: ANTHROPIC_BASE_URL and settings.json
Disclosure: LLM API Guide is maintained by the SeedRouter team, and this guide uses SeedRouter as the example. It applies to any gateway that offers an Anthropic Messages-compatible API.
What you need
| Value | SeedRouter example |
|---|---|
| Gateway root URL | https://seedrouter.net (no /v1) |
| API key | An sk-... key created in the seedrouter.net dashboard |
| Model ID | e.g. claude-sonnet-5-5 or claude-opus-5-5; copy it from the dashboard catalog |
Option 1: Try it with environment variables
macOS / Linux:
export SEEDROUTER_API_KEY="sk-your-key"
export ANTHROPIC_BASE_URL="https://seedrouter.net"
export ANTHROPIC_AUTH_TOKEN="$SEEDROUTER_API_KEY"
export ANTHROPIC_MODEL="claude-sonnet-5-5"
claude
Windows PowerShell:
$env:ANTHROPIC_BASE_URL = "https://seedrouter.net"
$env:ANTHROPIC_AUTH_TOKEN = "sk-your-key"
$env:ANTHROPIC_MODEL = "claude-sonnet-5-5"
claude
These variables only last for the current terminal window.
Option 2: Make it permanent in settings.json
Claude Code's user settings file is ~/.claude/settings.json (Windows: C:\Users\<you>\.claude\settings.json). Values in its env block are applied on every start:
{
"env": {
"ANTHROPIC_BASE_URL": "https://seedrouter.net",
"ANTHROPIC_AUTH_TOKEN": "sk-your-key",
"ANTHROPIC_MODEL": "claude-sonnet-5-5"
}
}
If the file already has other settings, merge the env block in and mind the commas. The file now contains a secret, so keep it out of Git and out of support chats.
Choosing models
ANTHROPIC_MODELsets the default model.- Type
/modelinside Claude Code to switch. - A gateway's model IDs can differ from official names, so copy them from the gateway's catalog.
Check that requests go through the gateway
- Start
claudeand ask a simple question. - Type
/statusinside Claude Code to see the current connection details. - Open the gateway dashboard's usage logs; the request and its charge should appear there.
Common problems
| Symptom | Cause | Fix |
|---|---|---|
| 401 | Wrong key, extra whitespace, or a key from another site | Copy the key from the dashboard again |
| 404 | /v1 added to ANTHROPIC_BASE_URL, or a typo in the domain | Use only the gateway root URL |
| Auth conflict warning | Both an account sign-in and an environment key are present | Run /logout, restart, or remove the extra variable |
| Model unavailable | The model ID is not in your account's catalog | Check the dashboard model list |
| Long task drops midway | Network or proxy interruption, or an intermediary closing a long silent stream | Retry and check the gateway status page |
Summary
Three variables do the work: ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN and ANTHROPIC_MODEL. Test them in your shell first, then move them into settings.json. On SeedRouter, Claude models are priced at 30% of official API pricing (see the live price table on the SeedRouter website), and new accounts get two free popular-model trials.
FAQ
Should ANTHROPIC_BASE_URL include /v1?
No. Claude Code appends /v1/messages itself. For SeedRouter use https://seedrouter.net.
What is the difference between ANTHROPIC_AUTH_TOKEN and ANTHROPIC_API_KEY?
AUTH_TOKEN is sent as an Authorization Bearer header and API_KEY as an x-api-key header. Use the one your gateway documents; SeedRouter's example uses ANTHROPIC_AUTH_TOKEN.
I signed in with a Claude account before. Will that conflict?
You may see an auth conflict warning. Run /logout inside Claude Code to drop the account sign-in, then start it again with the environment variables.