Skip to content
GuidesAugust 5, 2026

How to use AnyRouter with Claude Code (Anthropic's CLI coding tool)

Point Claude Code at AnyRouter by setting two environment variables. Here's the setup, what changes, and what to do when things go wrong.

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"
claude

That'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 free