Codex CLI
OpenAI Codex CLI is OpenAI's official terminal coding agent, built on the Responses API. With WRouter you can drive Codex with one key that also reaches Claude, Gemini, and other non-OpenAI models.
Prerequisites
| Item | Requirement |
|---|---|
| Codex CLI | ≥ 0.5 (binary codex) |
| Node.js | ≥ 20 (when installing via npm) |
| WRouter | A working token |
Install
bash
npm i -g @openai/codex
# Verify
codex --versionConfigure
1. ~/.codex/config.toml
toml
model_provider = "wrouter"
model = "gpt-5.5"
[model_providers.wrouter]
name = "wrouter"
base_url = "https://wrouter.ai/v1"
wire_api = "responses"
env_key = "WROUTER_API_KEY"Field reference:
| Field | Meaning |
|---|---|
base_url | WRouter OpenAI-compatible base. Must include /v1 |
wire_api | "responses" (recommended, Agentic) or "chat" (Chat Completions) |
env_key | Env var to read the API key from |
2. Environment
bash
# macOS / Linux
export WROUTER_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Windows (PowerShell)
[Environment]::SetEnvironmentVariable("WROUTER_API_KEY", "sk-xxxx...", "User")Verify
bash
codexRun /status:
Provider: wrouter
Model: gpt-5.5
Endpoint: https://wrouter.ai/v1
Wire API: responsesSmoke test:
> What files are in the current directory?Codex should invoke the shell tool.
Recommended models
| Model | wire_api | When |
|---|---|---|
gpt-5.5 | responses | Primary; best native Agentic support |
o3 | responses | Reasoning-heavy |
gpt-5.4 | responses or chat | General purpose |
claude-sonnet-4-6 | chat ⚠️ | Stick to chat for Claude |
gemini-2.5-pro | chat ⚠️ | Same |
Switch in-session:
/model claude-sonnet-4-6⚠️ Important: when switching to non-OpenAI models, also flip
wire_apito"chat", otherwise multi-step tool loops may degrade. Best practice: declare multiple providers:
toml
[model_providers.wrouter-chat]
name = "wrouter (chat)"
base_url = "https://wrouter.ai/v1"
wire_api = "chat"
env_key = "WROUTER_API_KEY"
# Then: codex --provider wrouter-chatTroubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
401 Unauthorized | WROUTER_API_KEY missing/wrong | echo $WROUTER_API_KEY; ensure toml env_key matches |
404 / unsupported wire_api | Model doesn't support Responses | Set wire_api = "chat" or switch model |
| Empty / hanging responses | wire_api mismatched with model | Same |
| Garbled / tool failures | Codex too old | npm i -g @openai/codex@latest |
rate_limit_exceeded | Hit WRouter RPM cap | Adjust in console |
Known limitations
- Some Codex high-level features (e.g. the built-in
web_searchtool) rely on OpenAI-only upstream paths and aren't available when routing non-OpenAI models through WRouter. wire_api = "responses"only works when the model itself implements Responses — today primarily OpenAI's GPT-5.x / o-series family.