Skip to content

Run Claude Code Against AnyRouter

Point Claude Code at AnyRouter so every coding session is billed once, logged, and free to use any Messages-compatible model in the catalog.

Point Claude Code at AnyRouter and every session is billed once through your AnyRouter account, recorded in your request logs, and free to call any Messages-compatible model in the catalog — including non-Anthropic ones.

The idea

Claude Code speaks the Anthropic Messages protocol, and AnyRouter exposes a fully compatible Messages endpoint. So you can drop AnyRouter in front of Claude Code with no change to how you use the tool: point it at AnyRouter's base URL and key, and AnyRouter translates the Messages protocol to whatever the upstream model expects.

flowchart LR
  cc["Claude Code"] -->|Messages protocol| ar["AnyRouter"]
  ar --> a["Anthropic models"]
  ar --> z["Z-AI / GLM"]
  ar --> o["Other providers"]
  ar --> logs["Request logs · one bill"]

How it works

  • One bill — every session draws from one AnyRouter balance (or your BYOK provider accounts) instead of separate per-provider invoices.
  • Request logs — each Claude Code call is recorded in your request logs for debugging and audit.
  • Any model — switch the coding model without touching Claude Code's own config.

Implementation

The AnyRouter CLI launches Claude Code with the right environment already set — no extra Node install, no manual env vars.

curl -fsSL https://anyrouter.dev/setup.sh | bash
anyr claude
anyr claude --install --ok

The first run asks how you want to connect — paste an sk-ar- key or log in at anyrouter.dev — and saves your profile to ~/.anyrouter/config.yaml. Every run after that goes straight into Claude Code.

Pin a model or reasoning depth per session:

anyr claude --model "anthropic/claude-sonnet-4.6"
anyr claude --model auto --effort high

auto lets your pinned preset choose the model. Anything after -- is forwarded to Claude Code itself:

anyr claude --model auto -- --resume

Claude Code reads two environment variables. Point them at AnyRouter's Messages base URL and your key:

export ANTHROPIC_BASE_URL="https://anyrouter.dev/api"
export ANTHROPIC_AUTH_TOKEN="sk-ar-v1-your-key"

claude

Drop those lines into a wrapper script if you want to keep a separate Anthropic key for other work — see the Claude Code guide for the wrapper recipe.

Because AnyRouter translates the Messages protocol, you can run Claude Code on non-Anthropic models. Bring your own Z-AI key and run GLM:

anyr claude --model "z-ai/glm-4.7-flash"

Browse everything Claude Code can call by filtering the catalog to Messages-compatible models: /models?endpoint=messages.