What Claude Code is
Claude Code is Anthropic's official CLI tool for coding tasks. It reads your project files, runs terminal commands, and calls the Anthropic API to generate responses. By default, it connects directly to api.anthropic.com.
You can point it at any Anthropic-compatible API endpoint instead, including AnyRouter.
Setup
Two environment variables control where Claude Code sends requests:
export ANTHROPIC_API_KEY="sk-ar-v1-placeholder"
export ANTHROPIC_BASE_URL="https://anyrouter.dev/api"
claudeThat's it. Claude Code will send all its API requests through AnyRouter using the same Messages API format it uses with Anthropic directly.
What changes
- All requests go through AnyRouter's routing layer
- You can access models available on AnyRouter by passing --model, e.g. claude --model claude-sonnet-4-5
- Usage is tracked in your AnyRouter dashboard
- If one provider is down, AnyRouter can fail over to an alternative upstream
Common issues
- 401 Unauthorized — your API key is invalid or expired. Generate a new one from the AnyRouter dashboard.
- 404 or model not found — the model name may differ between Anthropic and AnyRouter. Check the AnyRouter model list.
- 429 rate limit — see our guide on fixing 429 errors. You can also try a different model tier (Haiku instead of Sonnet) which often has higher limits.
Alternative: the anyr CLI wrapper
If you'd rather not manage env vars manually, the anyr CLI handles login and config:
curl -fsSL https://anyrouter.dev/setup.sh | bash
anyr login
anyr claude
anyr claude --model "z-ai/glm-4.7"This sets the correct environment variables and launches Claude Code for you.
Monitoring your usage
Track how many Claude Code requests you're making, which models you're using, and how much you're spending at chmonitor.dev.
Route Claude Code through AnyRouter — one key, every model, full audit log.
Sign up freeRelated posts
Run Claude Code on AnyRouter — wrapper script or CLI
Route Claude Code through AnyRouter in two ways: a wrapper that installs itself and maps Opus, Sonnet, and Haiku to one catalog model (override with --model), or the anyr CLI launcher. One key, unified billing, audit logs.
OpenRouter alternatives 2026: how AnyRouter differs
OpenRouter alternatives 2026, without invented rankings: AnyRouter is one OpenRouter alternative with $0-markup BYOK, a donated shared pool, a $2/mo Go plan, Cloudflare-edge routing, on-device models via local relay, a built-in MCP server, and open pricing config.