Claude Code 是什么
Claude Code 是 Anthropic 官方的编程 CLI。它会读项目文件、跑终端命令,并调用 Anthropic API 生成回复。默认连的是 api.anthropic.com。
你也可以把它指到任意兼容 Anthropic 的 API 端点,包括 AnyRouter。
配置
两个环境变量决定 Claude Code 把请求发到哪里:
export ANTHROPIC_API_KEY="sk-ar-v1-placeholder"
export ANTHROPIC_BASE_URL="https://anyrouter.dev/api"
claude就这样。Claude Code 会用它直连 Anthropic 时同一套 Messages API 格式,把全部 API 请求经 AnyRouter 发出。
会变什么
- 所有请求都走 AnyRouter 的路由层
- 可以用 --model 访问 AnyRouter 上的模型,例如 claude --model claude-sonnet-4-5
- 用量会记在 AnyRouter 控制台
- 某一家上游挂了,AnyRouter 可以切到备用上游
常见问题
- 401 Unauthorized — API key 无效或过期。到 AnyRouter 控制台再生成一把。
- 404 或 model not found — Anthropic 和 AnyRouter 上的模型名可能不同。去看 AnyRouter 的模型列表。
- 429 限流 — 看我们的 429 排障指南。也可以换更轻的档(Haiku 而不是 Sonnet),额度往往更高。
另一种做法:anyr CLI 包装
不想自己管环境变量,可以用 anyr CLI 处理登录和配置:
curl -fsSL https://anyrouter.dev/setup.sh | bash
anyr login
anyr claude
anyr claude --model "z-ai/glm-4.7"它会设好环境变量并替你启动 Claude Code。
看用量
在 chmonitor.dev 看你发了多少 Claude Code 请求、用了哪些模型、花了多少。
把 Claude Code 接到 AnyRouter — 一把 key、所有模型、完整审计日志。
免费注册相关文章
Run Claude Code on AnyRouter — wrapper script or CLI
Route Claude Code through AnyRouter in two ways: a wrapper that installs itself and maps Opus, Sonnet, and Haiku to one catalog model (override with --model), or the anyr CLI launcher. One key, unified billing, audit logs.
OpenRouter alternatives 2026: how AnyRouter differs
OpenRouter alternatives 2026, without invented rankings: AnyRouter is one OpenRouter alternative with $0-markup BYOK, a donated shared pool, a $2/mo Go plan, Cloudflare-edge routing, on-device models via local relay, a built-in MCP server, and open pricing config.