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-key

Start 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

ControlWhat it changesCommon mistake
ANTHROPIC_BASE_URLRequest destinationAdding /v1 even though Claude Code builds the Messages path
ANTHROPIC_AUTH_TOKENGateway authentication and billing accountSetting only the URL and leaving a saved claude.ai login active
Model settingRequested model IDCopying 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:

ModelMakerPublished price
claude-opus-4-8Anthropic$5.00 per 1M input tokens and $25.00 per 1M output tokens
claude-sonnet-4-6Anthropic$3.00 per 1M input tokens and $15.00 per 1M output tokens
claude-haiku-4-5Anthropic$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

CapabilityClaude on a supported serviceClaude through a gatewayNon-Claude through a gateway
Messages requestSupportedGateway must track the current protocolThird-party translation only
Streaming and toolsSupported for the selected Claude modelGateway must preserve current fields and eventsTest the exact translated route
MCP tool searchNormal product behaviorNon-Anthropic base URLs have extra requirementsDo not assume support
Remote ControlProduct and account dependentNon-Anthropic hosts have documented restrictionsDo not promise it
Anthropic supportYes, within the selected serviceLimited to the documented gateway boundaryNo

Five-step verification

  1. Start a new terminal and confirm only that both variables are set; do not print the token.
  2. Run a bounded text prompt and confirm the selected model in Claude Code and the KeepRouter usage record.
  3. Run one streaming response and cancel it once.
  4. Run one harmless tool call and return the result to the model.
  5. Repeat after a Claude Code, gateway, or model upgrade.

Troubleshooting

SymptomCheck
Subscription still appears activeGateway credential is set in the same process and old sessions are closed
401Key, whitespace, scope, revocation, and destination host
404Base URL is exactly https://keeprouter.com without /v1 or a Messages path
Model not foundExact current KeepRouter ID and Messages compatibility on the model page
Text works but tools failModel capability, tool-result continuation, gateway protocol coverage, and Claude Code version
Remote Control unavailableAnthropic'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