Docs navigation

Integrations

Claude Code

Route Claude Code through TokenRouter with two environment variables.

Claude Code speaks the Anthropic Messages API, which TokenRouter serves natively — so routing it through the gateway is two environment variables. You get budgets, rate limits, and per-key attribution for every engineer’s coding agent.

Setup

bash
export ANTHROPIC_BASE_URL=https://api.tokenrouter.io
export ANTHROPIC_AUTH_TOKEN=tr_your_key_here

claude
No /v1 suffix on ANTHROPIC_BASE_URL. Anthropic clients append /v1/messages themselves — setting https://api.tokenrouter.io/v1 would produce /v1/v1/messages and 404.

ANTHROPIC_API_KEY=tr_your_key_here also works if you prefer it over ANTHROPIC_AUTH_TOKEN — the gateway accepts the tr_ key either way.

Make it stick

bash
# ~/.zshrc (or ~/.bashrc)
export ANTHROPIC_BASE_URL=https://api.tokenrouter.io
export ANTHROPIC_AUTH_TOKEN=tr_your_key_here

Verify

bash
claude -p "Reply with exactly: routed via TokenRouter"

If the reply comes back, you’re routing. The request appears in the console logs within seconds, attributed to the key you used.

Tips

  • Create a dedicated key per engineer (e.g. claude-code-alice) so budgets and analytics attribute per person.
  • Requests to Claude models pass through verbatim — extended thinking, tools, and vision behave exactly as with Anthropic directly.
  • Put a daily hard-cap budget on coding-agent keys to bound worst-case spend.