Skip to content
GuidesJuly 12, 2026

Run coding agents through one gateway

Point Claude Code, Codex, OpenCode, Cursor, or any OpenAI-compatible tool at AnyRouter and get one key for every model, unified billing, per-request audit logs, and app attribution. Two environment variables — or one npx command with the anyr CLI launcher.

Why route coding agents through a gateway?

Claude Code, Codex, OpenCode, Cursor, and their cousins all let you override the base URL and key. Point them at AnyRouter and every request from every tool lands on one account: one key for every model, one balance, one audit log with cost, latency, and token counts per request — and the freedom to pick a different model per tool without touching provider SDKs.

Two things make this clean. Claude Code speaks the Anthropic dialect (/messages), Codex and Cursor speak the OpenAI dialect (/chat/completions), and AnyRouter serves both from the same endpoint. And app attribution headers let each tool show up separately in your usage analytics.

How do I point Claude Code at a custom base URL?

Claude Code reads two environment variables. Set them to AnyRouter and every request routes through your account:

export ANTHROPIC_BASE_URL="https://anyrouter.dev/api"
export ANTHROPIC_API_KEY="sk-ar-your-anyrouter-key"
claude
Claude Code — manual configuration.

Codex and any OpenAI-compatible tool read the OpenAI pair instead:

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"
Codex / Cursor / any OpenAI-compatible client.

For Cursor, paste the same base URL (https://anyrouter.dev/api/v1) and an sk-ar- key into its OpenAI-compatible custom-model settings — no other change needed.

The anyr CLI launcher does it for you

If you'd rather not manage environment variables, the anyr launcher handles login, key storage, and the environment in one command — and the same stored key powers every 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

Config is saved to ~/.anyrouter/config.yaml and reused next time. Everything after -- forwards to the underlying tool verbatim (e.g. anyr claude -- --resume).

Attribute each tool's usage

Send app-attribution headers and each tool earns its own row in your analytics and the public rankings. HTTP-Referer is the primary identifier; the optional X-AnyRouter-* headers set the display name, platform, version, and marketplace category (coding tools fit cli-agent or 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"}] }'

Full setup guides live at /cli and /docs. To route on keys you already pay for, pair this with BYOK — /blog/byok-bring-your-own-keys.

One key for Claude Code, Codex, OpenCode, and Cursor — unified billing and audit logs.

Set up the CLI

Route your first request in 2 minutes

Start free with your own keys, or top up and pay per token. Get $4/mo in credits and free models on Go — $2/mo, or free when you donate a provider key.

Start free