Codex
Route Codex through AnyRouter for unified billing, audit logs, and one key that reaches every model — one CLI command, or two environment variables.
Point Codex at AnyRouter and every run flows through one gateway: unified billing, request audit logs, and a single sk-ar- key that reaches every model AnyRouter serves. Codex speaks the OpenAI-compatible wire protocol, so this is a config-only change.
Why route through AnyRouter
- One key for every model Codex can call — no per-provider keys.
- Audit logs with cost, latency, and tokens on every request.
- Swap models freely without rotating credentials.
This is the narrative "use Codex with AnyRouter" guide. For the full command reference — flags, profiles, --dry-run, and the login flow — see the canonical Codex CLI setup.
Set it up
One command handles everything:
curl -fsSL https://anyrouter.dev/setup.sh | bash
anyr codex
The first run sets you up once: paste an sk-ar- key, or log in at anyrouter.dev (a key is generated for you). Your config is saved to ~/.anyrouter/config.yaml and reused next time — and the same key also powers anyr claude for Claude Code.
Anything after -- forwards straight to Codex:
anyr codex --model auto --effort xhigh -- exec
See the CLI reference for all options.
Codex reads OPENAI_BASE_URL and OPENAI_API_KEY. Point them at AnyRouter's OpenAI-compatible endpoint:
export OPENAI_BASE_URL="https://anyrouter.dev/api/v1"
export OPENAI_API_KEY="sk-ar-your-anyrouter-key"
Create the key in your dashboard first — every AnyRouter key starts with sk-ar-. Every Codex request now routes through AnyRouter, billed against your credits and recorded in your audit logs.
Verify
Run any Codex command, then open your request logs. The call should appear within a second or two, with the model name, token counts, and cost. If it's there, you're routing through AnyRouter.
Troubleshooting
401 or 403 — confirm the key is active in your dashboard and that OPENAI_API_KEY (or your saved CLI config) holds a valid sk-ar- key.
Model not found — make sure the model id exactly matches an AnyRouter id; browse Chat-Completions-compatible models.
Related
- Codex CLI setup — canonical command reference
- Claude Code
- OpenCode
- Supported models
- Chat Completions API
