anyr claude

Route Claude Code through AnyRouter with one CLI command, or set two environment variables yourself.

Route Claude Code through AnyRouter for one key, unified billing and request logs across every model.

Setup

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

The first run signs you in (browser, or device code on SSH/headless; --key, --paste and --device force a path, see Login). The key is saved to ~/.anyrouter/config.yaml and reused by every launcher.

anyr claude --model "z-ai/glm-5.2"          # pin a model
anyr claude --model auto --effort high       # reasoning depth
anyr claude --model auto -- --resume         # flags after -- go to Claude Code
anyr claude --dry-run                        # print resolved environment, run nothing

auto is the catalog id anyrouter/auto (smart pick). How --model maps onto Claude Code's aliases:

  • --model auto, anyrouter/free, another anyrouter/* router, or no --model: the 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, every alias you have not set, and 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 config.yaml as claude_haiku, claude_sonnet, claude_opus, claude_fable. --dry-run shows the resolved ANTHROPIC_DEFAULT_*_MODEL values. See the configuration reference for all flags.

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

Bring your own Z-AI key and AnyRouter routes Claude Code to GLM-5.2 (1M-token context, 128K output, controllable reasoning). You pay Z-AI directly or use your Z-AI Coding Plan; AnyRouter adds nothing to the per-token cost.

  1. Paste your Z-AI key in Settings → BYOK. A Coding Plan key is routed through the Coding Plan endpoint automatically. It is encrypted at rest and only used for your requests.
  2. Run anyr claude --model "z-ai/glm-5.2", or with manual env vars claude-ar --model "z-ai/glm-5.2". To make it the default tier model, set ANTHROPIC_DEFAULT_SONNET_MODEL and ANTHROPIC_DEFAULT_OPUS_MODEL to z-ai/glm-5.2 in the wrapper.
  3. Reasoning effort: low/medium/high/max enable thinking, none/minimal disable it. Use /effort in Claude Code or anyr claude --model "z-ai/glm-5.2" --effort high.
  4. For the full 1M window, raise the auto-compact threshold: export CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000.

MCP tools

anyr claude connects the AnyRouter MCP gateway with the session's key when Auto-connect in coding agents is on in the dashboard. Turn it off with --no-mcp, anyr mcp auto off, or in the dashboard.

Verify

Run claude "hello" or anyr claude "hello"; the request appears in your usage dashboard with cost, latency and tokens. anyr claude --dry-run shows the base URL and model first.

Troubleshooting

SymptomFix
401 or auth errorsManual: check echo $ANTHROPIC_API_KEY in the current shell. CLI: anyr config get to confirm a stored key, or re-run anyr setup.
Requests still hit Anthropicecho $ANTHROPIC_BASE_URL must print https://anyrouter.dev/api; with the wrapper, ~/bin must be on $PATH.
Long agent runs time outexport API_TIMEOUT_MS=3000000 (50 minutes) before launching.

Messages-compatible models: /models?endpoint=messages.

AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer