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 missingThe 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 nothingauto is the catalog id anyrouter/auto (smart pick). How --model maps onto Claude Code's aliases:
--model auto,anyrouter/free, anotheranyrouter/*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 / FableThey 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.
-
Create a key (prefix
sk-ar-) in your dashboard. -
Set the environment (add to
~/.bashrcor~/.zshrcto persist):export ANTHROPIC_BASE_URL="https://anyrouter.dev/api" export ANTHROPIC_API_KEY="sk-ar-your-anyrouter-key" -
Run Claude Code with any AnyRouter model:
claude --model "anthropic/claude-sonnet-4-6" "Refactor this function"
To keep your Anthropic key for other work, use a wrapper such as ~/bin/claude-ar (chmod +x) instead of shell rc:
#!/usr/bin/env bash
export ANTHROPIC_AUTH_TOKEN="${ANYROUTER_API_KEY:-sk-ar-your-anyrouter-key}"
export ANTHROPIC_BASE_URL="https://anyrouter.dev/api"
# Optional: pin tier names to 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 agent runs: raise the SDK timeout
export API_TIMEOUT_MS=3000000
exec claude "$@"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.
- 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.
- Run
anyr claude --model "z-ai/glm-5.2", or with manual env varsclaude-ar --model "z-ai/glm-5.2". To make it the default tier model, setANTHROPIC_DEFAULT_SONNET_MODELandANTHROPIC_DEFAULT_OPUS_MODELtoz-ai/glm-5.2in the wrapper. - Reasoning effort:
low/medium/high/maxenable thinking,none/minimaldisable it. Use/effortin Claude Code oranyr claude --model "z-ai/glm-5.2" --effort high. - 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
| Symptom | Fix |
|---|---|
| 401 or auth errors | Manual: 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 Anthropic | echo $ANTHROPIC_BASE_URL must print https://anyrouter.dev/api; with the wrapper, ~/bin must be on $PATH. |
| Long agent runs time out | export 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