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"
claudeThis 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-runConfig 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.
| Agent | Protocol | Environment variables |
|---|---|---|
| Claude Code | Anthropic /messages | ANTHROPIC_BASE_URL, ANTHROPIC_API_KEY |
| Codex | OpenAI /chat/completions | OPENAI_BASE_URL, OPENAI_API_KEY |
| OpenCode | OpenAI /chat/completions | anyr opencode, or opencode.json provider |
| Cursor | OpenAI-compatible custom model | Base 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.

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 freeRelated posts
Use OpenCode with AnyRouter — CLI launcher or opencode.json
Point the OpenCode coding agent at AnyRouter in one command, or add a custom Chat Completions provider in opencode.json. One sk-ar- key reaches every catalog model, with unified billing and request logs.
Run coding agents through one gateway
Point Claude Code, Codex, OpenCode, Cursor, or any OpenAI-compatible tool at AnyRouter and get one key for every model, unified billing, per-request audit logs, and app attribution. Two environment variables — or one npx command with the anyr CLI launcher.
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