Skip to content

anyr claude

Route Claude Code through AnyRouter for unified billing, audit logs, and a single API key that unlocks every model. One command via the AnyRouter CLI, or set two environment variables yourself.

Route Claude Code through AnyRouter to get unified billing, request audit logs, and a single API key for every model AnyRouter serves — either with one CLI command or two environment variables.

Setup

Most people should use the CLI helper — anyr claude handles login, key storage, and the environment for you. Reach for manual configuration only when you want to control the environment yourself.

The fastest path — one command handles everything:

curl -fsSL https://anyrouter.dev/setup.sh | bash
anyr claude
anyr claude --install --ok   # install Claude Code first if it is missing

Step 1 — Run the launcher

The first run signs you in automatically (browser when available, device code on SSH/headless). Use --key, --paste, or --device if you need a specific path. See Login with AnyRouter.

Step 2 — Reuse it everywhere

Your config is saved to ~/.anyrouter/config.yaml and reused automatically next time. The same key also powers anyr codex and the other launchers.

Step 3 — Pick models and flags

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

# Set reasoning depth
anyr claude --model auto --effort high

# Pass flags through to Claude Code itself
anyr claude --model auto -- --resume

# Preview the resolved environment without running anything
anyr claude --dry-run

auto is the catalog id anyrouter/auto (smart pick). Claude Code's /model picker still lists opus, sonnet, and haiku as separate aliases — pinning the session model no longer overwrites them.

Set those aliases independently:

anyr claude --haiku "anthropic/claude-haiku-4.5" --sonnet "anthropic/claude-sonnet-4.6" --opus "anthropic/claude-opus-4.6"
anyr models use --haiku "z-ai/glm-4.7-flash"
anyr models --pick    # Default / Haiku / Sonnet / Opus

They persist in ~/.anyrouter/config.yaml as claude_haiku, claude_sonnet, and claude_opus.

Everything after -- forwards to Claude Code verbatim. See the configuration reference for --model, --effort, --profile, and the rest.

Step 1 — Create an AnyRouter API key

Head to your dashboard and create a new API key. It is prefixed with sk-ar-.

Step 2 — Point Claude Code at AnyRouter

Claude Code reads ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY from the environment. Set them to your AnyRouter endpoint and key:

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

Drop these two lines into ~/.bashrc or ~/.zshrc so they persist across shells.

Step 3 — Run Claude Code

That's it. Every Claude Code request now routes through AnyRouter, billed against your credits and recorded in your audit logs:

# Start an interactive session
claude

# Run a one-shot prompt
claude "Explain the architecture of this project"

# Pick any AnyRouter model on the fly
claude --model "anthropic/claude-sonnet-4.6" "Refactor this function"
claude --model "z-ai/glm-4.7-flash" "Review this PR"

Optional — wrapper script

If you keep an Anthropic key for other work and only want AnyRouter for some sessions, drop the env vars into a wrapper instead of your shell rc. Save it as ~/bin/claude-ar (or anywhere on $PATH) and chmod +x:

#!/usr/bin/env bash
# Wrapper: route Claude Code through AnyRouter

export ANTHROPIC_AUTH_TOKEN="${ANYROUTER_API_KEY:-sk-ar-your-anyrouter-key}"
export ANTHROPIC_BASE_URL="https://anyrouter.dev/api"

# Optional — pin the model tier names to specific AnyRouter model ids
export ANTHROPIC_DEFAULT_HAIKU_MODEL="anthropic/claude-haiku-4.5"
export ANTHROPIC_DEFAULT_SONNET_MODEL="anthropic/claude-sonnet-4.6"
export ANTHROPIC_DEFAULT_OPUS_MODEL="anthropic/claude-opus-4.6"

# Long-running agent flows: bump the SDK timeout
export API_TIMEOUT_MS=3000000

exec claude "$@"

Now claude-ar uses AnyRouter while bare claude keeps using your Anthropic key. Every flag forwards through to claude.

GLM-5.2 with your own Z-AI key (BYOK)

Prefer Z-AI's GLM-5.2 as your coding agent? Bring your own Z-AI key and AnyRouter routes Claude Code to it — you pay Z-AI directly (or use your Z-AI Coding Plan subscription), and AnyRouter adds nothing to the per-token cost.

GLM-5.2 has a 1M-token context, a 128K output window, and controllable reasoning effort, making it a strong option for long-horizon coding sessions.

Step 1 — Add your Z-AI key

Open Settings → BYOK and paste your Z-AI API key. If you have a Z-AI Coding Plan, paste that key — AnyRouter routes it through the Coding Plan endpoint automatically. Your key is encrypted at rest and only used to sign your own requests.

Step 2 — Point Claude Code at GLM-5.2

anyr claude --model "z-ai/glm-5.2"

Or with manual env vars and the wrapper:

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

claude-ar --model "z-ai/glm-5.2" "Refactor this module and add tests"

Pin GLM-5.2 as the default tier models in your wrapper:

export ANTHROPIC_DEFAULT_SONNET_MODEL="z-ai/glm-5.2"
export ANTHROPIC_DEFAULT_OPUS_MODEL="z-ai/glm-5.2"

Reasoning effort

GLM-5.2 supports controllable thinking. AnyRouter maps the standard reasoning_effort levels onto Z-AI's thinking control: low/medium/high/max enable thinking, while none/minimal disable it. Use Claude Code's /effort command or the CLI --effort flag:

anyr claude --model "z-ai/glm-5.2" --effort high "Plan a migration"

1M context

To use GLM-5.2's full 1M-token window in Claude Code, raise the auto-compact threshold so Claude Code keeps the long context instead of summarizing early:

export CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000

Verify

Confirm requests are flowing through AnyRouter:

  • Run a one-shot prompt (claude "hello" or anyr claude "hello") and check that it responds.
  • Open your usage dashboard — the request should appear in your audit log with cost, latency, and token counts.
  • With the CLI, anyr claude --dry-run prints the resolved command and environment (secrets redacted) so you can confirm the base URL and model before sending anything.

Troubleshooting

401 or authentication errors — your key isn't reaching Claude Code. In manual mode, re-check ANTHROPIC_API_KEY is exported in the current shell (echo $ANTHROPIC_API_KEY). With the CLI, run anyr config get to confirm a key is stored, or re-run anyr setup.

Requests still hit Anthropic directly — ANTHROPIC_BASE_URL isn't set (or a wrapper isn't on $PATH). Confirm echo $ANTHROPIC_BASE_URL prints https://anyrouter.dev/api, and if you use the claude-ar wrapper, that ~/bin is on your $PATH.

Long agent runs time out — bump the SDK timeout with export API_TIMEOUT_MS=3000000 (50 minutes) before launching Claude Code.

Supported models

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