Skip to content
GuidesJuly 12, 2026

Point Claude Code at a custom base URL

Claude Code reads ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY, so pointing it at AnyRouter takes two environment variables — no plugin, no fork. You get every model in the catalog behind the same key, automatic failover when a provider is rate-limited, and one audit log shared with Codex, Cursor, and every other agent you run.

How do I point Claude Code at a custom base URL?

Claude Code reads two environment variables for its provider connection: ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY. Set them to AnyRouter's endpoint and an AnyRouter key, and every request Claude Code makes — the main session, subagents, background tasks — routes through your account instead of directly to Anthropic.

export ANTHROPIC_BASE_URL="https://anyrouter.dev/api"
export ANTHROPIC_API_KEY="sk-ar-your-anyrouter-key"
claude
Claude Code — manual setup, two environment variables.

This works because Claude Code speaks the Anthropic /messages dialect, and AnyRouter serves that same dialect for every model in the catalog — the client has no way to tell the request left Anthropic's own infrastructure.

The anyr CLI sets it up for you

If you'd rather not manage environment variables by hand, the anyr launcher handles login, key storage, and the environment in one command:

# Install the native CLI (no Node required)
curl -fsSL https://anyrouter.dev/setup.sh | bash
anyr login

# Launch Claude Code through AnyRouter
anyr claude

# Pin a specific model for this session
anyr claude --model "z-ai/glm-5.2"

# Preview the environment without launching
anyr claude --dry-run

Config is saved to ~/.anyrouter/config.yaml and reused next time — by claude, and by every other launcher the CLI ships (codex, cursor). Everything after -- forwards to Claude Code itself, so existing flags still work (anyr claude -- --resume).

Run Codex and Cursor on the same key

Claude Code isn't the only agent worth routing this way. Codex and Cursor speak the OpenAI dialect instead of Anthropic's, and AnyRouter serves both dialects from the same account — so one key covers every agent you run, not just one.

AgentProtocolEnvironment variables
Claude CodeAnthropic /messagesANTHROPIC_BASE_URL, ANTHROPIC_API_KEY
CodexOpenAI /chat/completionsOPENAI_BASE_URL, OPENAI_API_KEY
OpenCodeOpenAI /chat/completionsanyr opencode, or opencode.json provider
CursorOpenAI-compatible custom modelBase URL + key pasted into settings

Whichever combination you run, requests from every tool land in the same balance, the same per-request audit log, and the same rate limits — no separate account per agent.

Swap the model Claude Code uses without leaving your terminal

Model ids on AnyRouter are provider/model strings, so changing what Claude Code runs on for a given task is a flag, not a rewrite. Route cheap, fast edits one way and a hard refactor another, in the same session.

  • Route on your own keys at $0 markup — anyrouter/coding sends requests to the coding-capable subset of your configured BYOK keys.
  • Pin a specific model for a hard problem — anyr claude --model "anthropic/claude-opus-4-8".
  • Preview a model's behavior before wiring it in — try it live in /playground first.
AnyRouter model detail page showing a single model's specs and pricing
Every catalog model has its own page — check specs before pointing an agent at it.

Where to go from here

For the broader picture on routing any OpenAI- or Anthropic-compatible tool through one account — including the app-attribution headers that make each tool show up separately in your usage analytics — see /blog/coding-agents-one-gateway. To route on provider keys you already pay for, see /blog/byok-bring-your-own-keys.

  • Full CLI reference and flags — /cli.
  • Endpoint and header reference — /docs.
  • Try any model live before wiring it in — /playground.

Point Claude Code at AnyRouter and get every model behind one key.

Set it up free

Route your first request in 2 minutes

Start free with your own keys, or top up and pay per token. Get $4/mo in credits and free models on Go — $2/mo, or free when you donate a provider key.

Start free