Claude Code router config: KeepRouter base URL setup
Set ANTHROPIC_BASE_URL=https://keeprouter.com and authenticate with a scoped KeepRouter key in ANTHROPIC_AUTH_TOKEN. This is Claude Code's native gateway configuration, not the separate third-party project commonly called claude-code-router. Anthropic supports gateways that implement its current API format, but explicitly says it does not support routing Claude Code to non-Claude models through any gateway.
macOS and Linux: two environment variables
export ANTHROPIC_BASE_URL=https://keeprouter.com
export ANTHROPIC_AUTH_TOKEN=sk-kr-your-keyStart claude from the same shell. Keep the token in secret tooling and out of source control.
Windows PowerShell
$env:ANTHROPIC_BASE_URL = "https://keeprouter.com"
$env:ANTHROPIC_AUTH_TOKEN = "sk-kr-your-key"settings.json
The base URL can be placed in ~/.claude/settings.json. Keep the credential in an environment variable or managed secret:
{
"env": {
"ANTHROPIC_BASE_URL": "https://keeprouter.com"
}
}URL, credential, and model are separate controls
| Control | What it changes | Common mistake |
|---|---|---|
ANTHROPIC_BASE_URL | Request destination | Adding /v1 even though Claude Code builds the Messages path |
ANTHROPIC_AUTH_TOKEN | Gateway authentication and billing account | Setting only the URL and leaving a saved claude.ai login active |
| Model setting | Requested model ID | Copying an ID from another catalog or assuming aliases are shared |
Anthropic documents that setting only the base URL without a gateway credential does not necessarily replace a saved subscription login. Verify both variables before assuming the serving or billing path changed.
Choose a Claude model deliberately
Switch models with /model <id> or the current model selector. These are Claude catalog examples, not recommendations or a permanent price snapshot:
| Model | Maker | Published price |
|---|---|---|
claude-opus-4-8 | Anthropic | $5.00 per 1M input tokens and $25.00 per 1M output tokens |
claude-sonnet-4-6 | Anthropic | $3.00 per 1M input tokens and $15.00 per 1M output tokens |
claude-haiku-4-5 | Anthropic | $1.00 per 1M input tokens and $5.00 per 1M output tokens |
See the full list on Models & pricing.
A non-Claude Messages-compatible route is third-party translation and is not supported by Anthropic as a Claude Code route.
Capability and support matrix
| Capability | Claude on a supported service | Claude through a gateway | Non-Claude through a gateway |
|---|---|---|---|
| Messages request | Supported | Gateway must track the current protocol | Third-party translation only |
| Streaming and tools | Supported for the selected Claude model | Gateway must preserve current fields and events | Test the exact translated route |
| MCP tool search | Normal product behavior | Non-Anthropic base URLs have extra requirements | Do not assume support |
| Remote Control | Product and account dependent | Non-Anthropic hosts have documented restrictions | Do not promise it |
| Anthropic support | Yes, within the selected service | Limited to the documented gateway boundary | No |
Five-step verification
- Start a new terminal and confirm only that both variables are set; do not print the token.
- Run a bounded text prompt and confirm the selected model in Claude Code and the KeepRouter usage record.
- Run one streaming response and cancel it once.
- Run one harmless tool call and return the result to the model.
- Repeat after a Claude Code, gateway, or model upgrade.
Troubleshooting
| Symptom | Check |
|---|---|
| Subscription still appears active | Gateway credential is set in the same process and old sessions are closed |
| 401 | Key, whitespace, scope, revocation, and destination host |
| 404 | Base URL is exactly https://keeprouter.com without /v1 or a Messages path |
| Model not found | Exact current KeepRouter ID and Messages compatibility on the model page |
| Text works but tools fail | Model capability, tool-result continuation, gateway protocol coverage, and Claude Code version |
| Remote Control unavailable | Anthropic's current restrictions for non-Anthropic hosts |
Manage spend and rollback
Use a separate key restricted to evaluated coding models, keep task and turn limits, require approval for side-effecting commands, and retain a known Claude route for rollback. Compare cost per successful repository task rather than list price alone.
Frequently asked questions
Is this the claude-code-router open-source project?
No. This guide uses Claude Code's native ANTHROPIC_BASE_URL and gateway credential configuration.
Does Anthropic support non-Claude models in Claude Code?
No. Anthropic's current gateway documentation says it does not support routing Claude Code to non-Claude models through any gateway.
Can a non-Claude route still work technically?
A third-party gateway can translate a tested request, but that does not prove tools, streaming, model features, Remote Control, MCP tool search, or future-version compatibility.
Should I put the token in settings.json?
Prefer an environment variable or managed secret. Never commit a token in a shared settings file.
Why should the base URL omit /v1?
Claude Code builds the Anthropic Messages path from the host-level base URL. Use https://keeprouter.com exactly.
Sources reviewed 2026-08-26
Get a scoped API key · Models & pricing · Support boundary · This page as Markdown