Skip to content

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

ItemRequirement
Codex CLI≥ 0.5 (binary codex)
Node.js≥ 20 (when installing via npm)
WRouterA working token

Install

bash
npm i -g @openai/codex

# Verify
codex --version

Configure

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:

FieldMeaning
base_urlWRouter OpenAI-compatible base. Must include /v1
wire_api"responses" (recommended, Agentic) or "chat" (Chat Completions)
env_keyEnv 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
codex

Run /status:

Provider:    wrouter
Model:       gpt-5.5
Endpoint:    https://wrouter.ai/v1
Wire API:    responses

Smoke test:

> What files are in the current directory?

Codex should invoke the shell tool.

Modelwire_apiWhen
gpt-5.5responsesPrimary; best native Agentic support
o3responsesReasoning-heavy
gpt-5.4responses or chatGeneral purpose
claude-sonnet-4-6chat ⚠️Stick to chat for Claude
gemini-2.5-prochat ⚠️Same

Switch in-session:

/model claude-sonnet-4-6

⚠️ Important: when switching to non-OpenAI models, also flip wire_api to "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-chat

Troubleshooting

SymptomLikely causeFix
401 UnauthorizedWROUTER_API_KEY missing/wrongecho $WROUTER_API_KEY; ensure toml env_key matches
404 / unsupported wire_apiModel doesn't support ResponsesSet wire_api = "chat" or switch model
Empty / hanging responseswire_api mismatched with modelSame
Garbled / tool failuresCodex too oldnpm i -g @openai/codex@latest
rate_limit_exceededHit WRouter RPM capAdjust in console

Known limitations

  • Some Codex high-level features (e.g. the built-in web_search tool) 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.