Codex CLI
Codex CLI is OpenAI's official AI coding command-line tool. It's positioned similarly to Claude Code, but runs on OpenAI's own GPT-5 series models.
Key difference: The protocol uses OpenAI's Responses API (not the more common ChatCompletions), so when configuring you must specify
wire_api = "responses"and thebase_urlmust not include/v1. For models, choose coding-focused versions such asgpt-5.5-codex/gpt-5.3-codex— these are OpenAI's optimized builds for long-chain engineering tasks.Who it's for: Developers comfortable in the OpenAI ecosystem, who prefer the stability of the GPT-5 model chain and don't mind configuring a toml file.
This tutorial: Point Codex CLI at claude-api.org to run the GPT-5 series without a ChatGPT Plus subscription.
OpenAI's official Codex command-line tool. Use it with the OpenAI Channel, running the Responses API protocol.
Recommended Channel
OpenAI — a single Channel that supports both the Responses API (used by Codex CLI) and ChatCompletions (used by other OpenAI-compatible tools) at the same time.
Installation
Requires Node.js 18+.
npm install -g @openai/codexOr download the binary from the GitHub release.
Configuration
Codex CLI configures the provider via ~/.codex/config.toml:
model_provider = "OpenAI"
model = "gpt-5.4"
[model_providers.OpenAI]
name = "OpenAI"
base_url = "https://claude-api.org"
wire_api = "responses"
requires_openai_auth = trueexport OPENAI_API_KEY="sk-你的key"Base URL must not include /v1
Codex uses OpenAI's Responses API (not ChatCompletions), where the path is /v1/responses, so the base_url should simply be https://claude-api.org — do not add /v1.
Verification
codexOnce you're in interactive mode, type Write a Python function to reverse a string. If it returns code, the setup succeeded.
Or use curl:
curl -sS https://claude-api.org/v1/responses \
-H "Authorization: Bearer sk-你的key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"input": "ping",
"max_output_tokens": 32
}'Model Selection
| Model | Best for |
|---|---|
gpt-5.4 | Workhorse, balances capability and price (recommended starting point) |
gpt-5.5 | Latest version |
gpt-5.5-codex | Latest coding-focused version |
gpt-5.3-codex | Coding-focused, strong at writing code |
gpt-5.3-codex-spark | Accelerated Codex build, faster but slightly weaker |
gpt-5.2 / gpt-5.2-pro | Previous generation / long-chain reasoning |
At startup:
codex --model gpt-5.5-codexOr change model = in config.toml.
Don't let Codex CLI use the default model
When model = is not explicitly set, Codex CLI defaults to sending gpt-5 (with no version number). We don't provide a short-name fallback on our side, so you'll get 503 No available accounts directly. Be sure to specify one of the exact names from the table above in config.toml.
FAQ
401 Invalid API key
- The key is wrong / not bound to the OpenAI Channel. When creating a Key in the dashboard, select the
OpenAIChannel. - Note that Codex CLI uses the
Authorization: Bearer ...header, notx-api-key.
404 Not Found
wire_apiwas set tochat(the default) → Codex CLI defaults to ChatCompletions, but our Codex Channel uses the Responses API, so it must be changed toresponses.- Or
base_urlhas an extra/v1→ remove it.
tool calls failing / tool loops
The Responses API protocol has limitations on certain tool-call formats. If your Codex keeps getting stuck in a tool loop, consider switching to the ChatCompletions protocol (the same OpenAI Channel also supports it — change wire_api to chat and add /v1 to base_url), or switch to a Claude Channel (tool calls are more reliable there).
See the FAQ for more.
