anyr codex
Route Codex through AnyRouter with one CLI command, or set two environment variables yourself.
Route Codex through AnyRouter for one key, unified billing and request logs across every model.
Setup
anyr codexThe first run signs you in (browser, or device code on SSH/headless; --key, --paste and --device force a path, see Login). The key is saved to ~/.anyrouter/config.yaml and shared with anyr claude.
anyr codex --model auto --effort xhigh # model and reasoning depth
anyr codex --model auto -- exec # flags after -- go to Codex
anyr codex --dry-run # print resolved environment, run nothingSee the configuration reference for all flags.
-
Create a key (prefix
sk-ar-) in your dashboard. -
Set the environment (add to
~/.bashrcor~/.zshrcto persist):bashexport OPENAI_BASE_URL="https://anyrouter.dev/api/v1" export OPENAI_API_KEY="sk-ar-your-anyrouter-key" -
Run
codex "Refactor this function to use async/await".
MCP tools
anyr codex connects the AnyRouter MCP gateway with the session's key when Auto-connect in coding agents is on in the dashboard. Turn it off with --no-mcp, anyr mcp auto off, or in the dashboard.
Verify
Run codex "hello" or anyr codex "hello"; the request appears in your usage dashboard with cost, latency and tokens. anyr codex --dry-run shows the base URL and model first.
Troubleshooting
| Symptom | Fix |
|---|---|
| 401 or auth errors | Manual: check echo $OPENAI_API_KEY in the current shell. CLI: anyr config get to confirm a stored key, or re-run anyr setup. |
| Requests still hit OpenAI | echo $OPENAI_BASE_URL must print https://anyrouter.dev/api/v1 (note /v1). |
| Model not found | Codex uses Chat Completions; pick a Chat-Completions-compatible model. |
AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer