为什么让 coding agent 走网关?
Claude Code、Codex、OpenCode、Cursor 和同类工具都允许覆盖 base URL 和 key。指到 AnyRouter,每个工具的每次请求都落到一个账号:一把 key 打到每个模型,一份余额,一份带每次请求成本、延迟和 token 数的审计日志——还可以按工具换模型,不用碰供应商 SDK。
两件事让这干净。Claude Code 说 Anthropic 方言(/messages),Codex 和 Cursor 说 OpenAI 方言(/chat/completions),AnyRouter 从同一端点伺候两者。App 归因头让每个工具在用量分析里单独成行。
怎么把 Claude Code 指到自定义 base URL?
Claude Code 读两个环境变量。设成 AnyRouter,每次请求都经你的账号走:
export ANTHROPIC_BASE_URL="https://anyrouter.dev/api"
export ANTHROPIC_API_KEY="sk-ar-your-anyrouter-key"
claudeCodex 和任何兼容 OpenAI 的工具读 OpenAI 那一对:
export OPENAI_BASE_URL="https://anyrouter.dev/api/v1"
export OPENAI_API_KEY="sk-ar-your-anyrouter-key"
codex "Refactor this function to use async/await"Cursor 把同一 base URL(https://anyrouter.dev/api/v1)和一把 sk-ar- key 贴进兼容 OpenAI 的自定义模型设置——不用改别的。
anyr CLI launcher 替你做
不想管环境变量的话,anyr launcher 一条命令处理登录、存 key 和环境——同一把存好的 key 驱动每个 launcher:
# Install the native CLI (no Node required)
curl -fsSL https://anyrouter.dev/setup.sh | bash
anyr login
# Launch Claude Code through AnyRouter
anyr claude
# Same for Codex and OpenCode — reuses the stored key
anyr codex
anyr opencode
# Pin a model, set reasoning depth, or preview the env
anyr claude --model "z-ai/glm-5.2"
anyr opencode --model "anthropic/claude-sonnet-4.6"
anyr claude --dry-run配置存到 ~/.anyrouter/config.yaml,下次复用。-- 后面原样转给底层工具(例如 anyr claude -- --resume)。
给每个工具的用量归因
发 app 归因头,每个工具在分析和公开排名里各占一行。HTTP-Referer 是主标识;可选的 X-AnyRouter-* 头设显示名、平台、版本和市场类目(编程工具适合 cli-agent 或 ide-extension)。
curl https://anyrouter.dev/api/v1/chat/completions \
-H "Authorization: Bearer sk-ar-your-key" \
-H "HTTP-Referer: https://myagent.dev" \
-H "X-AnyRouter-Title: My Coding Agent" \
-H "X-AnyRouter-Source: cli" \
-H "X-AnyRouter-Categories: cli-agent" \
-H "Content-Type: application/json" \
-d '{ "model": "anthropic/claude-opus-4-8", "messages": [{"role":"user","content":"hi"}] }'完整设置指南在 /cli 和 /docs。要用你已经在付的 key 路由,搭配 BYOK — /blog/zh/byok-bring-your-own-keys。
一把 key 给 Claude Code、Codex、OpenCode 和 Cursor——统一账单和审计日志。
设置 CLI相关文章
Use OpenCode with AnyRouter — CLI launcher or opencode.json
Point the OpenCode coding agent at AnyRouter in one command, or add a custom Chat Completions provider in opencode.json. One sk-ar- key reaches every catalog model, with unified billing and request logs.
Point Claude Code at a custom base URL
Claude Code reads ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY, so pointing it at AnyRouter takes two environment variables — no plugin, no fork. You get every model in the catalog behind the same key, automatic failover when a provider is rate-limited, and one audit log shared with Codex, Cursor, and every other agent you run.
