Crazyrouter Codex CLI: Use Codex with One API Key and an OpenAI-Compatible Gateway
Crazyrouter Codex CLI: Use Codex with One API Key and an OpenAI-Compatible Gateway
OpenAI Codex CLI is useful when you want an AI coding agent directly inside your terminal. The painful part is not the idea — it is the setup: API keys, base URLs, model names, Windows environment variables, macOS shell profiles, Linux config files, and different providers for different models.
The new crazyrouter-codex-cli repo solves one specific problem:
connect Codex CLI to Crazyrouter with one API key and an OpenAI-compatible API endpoint.
https://github.com/xujfcn/crazyrouter-codex-cli
The repo provides simple install scripts for:
It configures Codex CLI to use:
OPENAI_BASE_URL=https://cn.crazyrouter.com/v1 OPENAI_API_KEY=your-crazyrouter-key
That means Codex CLI can talk to Crazyrouter through an OpenAI-compatible interface, while Crazyrouter handles the model/provider side.
Do not add UTM parameters to API endpoints. UTM belongs on human-clickable website links, not OPENAI_BASE_URL.
export OPENAI_BASE_URL=https://cn.crazyrouter.com/v1
export OPENAI_BASE_URL=https://cn.crazyrouter.com/v1?utm_source=...
Why use Codex CLI through Crazyrouter?
A terminal coding agent is most useful when it can become part of your normal development loop:
open a project directory;
ask the agent to inspect code;
But real developer teams often want more than one model. Some tasks need a fast low-cost model. Some need a stronger reasoning model. Some need Claude-style code review. Some need Gemini-style long-context analysis. Some teams also need a more stable route from regions where direct access is unreliable.
Crazyrouter gives Codex CLI a single OpenAI-compatible gateway:
OpenAI-compatible client configuration;
easier switching between coding models.
Open PowerShell as a normal user and run:
iwr -UseB https://raw.githubusercontent.com/xujfcn/crazyrouter-codex-cli/main/install-crazyrouter-codex.ps1 | iex
install-crazyrouter-codex.bat
curl -fsSL https://raw.githubusercontent.com/xujfcn/crazyrouter-codex-cli/main/install-crazyrouter-codex.sh | bash
The script asks for your Crazyrouter API key, writes the needed environment variables, and backs up existing Codex configuration when needed.
If you prefer to configure it yourself, install Codex CLI first:
npm install -g @openai/codex
Node.js 22+ is recommended.
Then set the environment variables.
export OPENAI_API_KEY=sk-your-crazyrouter-key export OPENAI_BASE_URL=https://cn.crazyrouter.com/v1
setx OPENAI_API_KEY "sk-your-crazyrouter-key" setx OPENAI_BASE_URL "https://cn.crazyrouter.com/v1"
After setx, reopen your terminal.
Codex config.toml example
Some Codex CLI versions support provider configuration in: