AnyRouter

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). How the model flag maps onto Claude Code's aliases:

  • --model auto, --model anyrouter/free, another anyrouter/* router, or no --model — Claude Code's haiku, sonnet, opus, and fable aliases keep their Anthropic defaults (Claude Haiku 4.5, Sonnet 4.6, Opus 4.6, Fable 5), and subagents use the haiku alias.
  • --model <id> (one catalog model) — that id is used for the session, for every alias you have not set, and for Claude Code's subagents (CLAUDE_CODE_SUBAGENT_MODEL).

An alias you set always wins over --model:

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 / Fable

They persist in ~/.anyrouter/config.yaml as claude_haiku, claude_sonnet, claude_opus, and claude_fable. Use --dry-run to see the resolved ANTHROPIC_DEFAULT_*_MODEL values.

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

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.