Skip to content

anyr codex

Route Codex through AnyRouter for unified billing, audit logs, and one key that reaches every model. One command via the AnyRouter CLI, or set two environment variables yourself.

Route Codex through AnyRouter to get unified billing, request audit logs, and a single API key that reaches every model AnyRouter serves — either with one CLI command or two environment variables.

Setup

The CLI helper is the shortest path — anyr codex reuses the same stored key as anyr claude. Use manual configuration only when you want to set the environment yourself.

The fastest path — one command handles everything:

anyr codex

Step 1 — Run the launcher

The first run signs you in automatically (browser when available, device code on SSH/headless). Use --key, --paste, or --device if you need a specific path. See Login with AnyRouter.

Step 2 — Reuse it everywhere

Your config is saved to ~/.anyrouter/config.yaml and reused next time — the same key also powers anyr claude for Claude Code.

Step 3 — Pick models and flags

# Pin a model and set reasoning depth
anyr codex --model auto --effort xhigh

# Pass flags through to Codex itself
anyr codex --model auto -- exec

# Preview the resolved environment without running anything
anyr codex --dry-run

Anything after -- forwards to Codex verbatim. See the configuration reference for all flags.

Step 1 — Create an AnyRouter API key

Head to your dashboard and create a new API key. It is prefixed with sk-ar-.

Step 2 — Point Codex at AnyRouter

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"

Drop these two lines into ~/.bashrc or ~/.zshrc so they persist across shells.

Step 3 — Run Codex

Every Codex request now routes through AnyRouter, billed against your credits and recorded in your audit logs:

codex "Refactor this function to use async/await"

Verify

Confirm requests are flowing through AnyRouter:

  • Run a one-shot prompt (codex "hello" or anyr codex "hello") and check that it responds.
  • Open your usage dashboard — the request should appear in your audit log with cost, latency, and token counts.
  • With the CLI, anyr codex --dry-run prints the resolved command and environment (secrets redacted) so you can confirm the base URL and model first.

Troubleshooting

401 or authentication errors — your key isn't reaching Codex. In manual mode, confirm OPENAI_API_KEY is exported in the current shell (echo $OPENAI_API_KEY). With the CLI, run anyr config get to check a key is stored, or re-run anyr setup.

Requests still hit OpenAI directly — OPENAI_BASE_URL isn't set. Confirm echo $OPENAI_BASE_URL prints https://anyrouter.dev/api/v1 (note the /v1 suffix — Codex uses the OpenAI-compatible path).

Model not found — Codex uses the Chat Completions surface. Make sure the model id you pass is Chat-Completions-compatible (see the filter link below).

Supported models

Browse every model usable with Codex by filtering the catalog to Chat-Completions-compatible models: /models?endpoint=chat-completions.