Codex CLI supports custom providers — describe a provider with our base_url in config.toml and point the key at an env var.
You'll need Node.js 18 or newer:
terminal
npm install -g @openai/codexGrab a cai-... key from API keys. Codex's config lives in ~/.codex/ (on Windows — %USERPROFILE%\.codex\).
Create or extend ~/.codex/config.toml:
~/.codex/config.toml
model = "gpt-4o"
model_provider = "cheapai"
[model_providers.cheapai]
name = "cheapai.io"
base_url = "https://api.cheapai.io/v1"
env_key = "CHEAPAI_API_KEY"
wire_api = "chat"The base_url already includes /v1 — that's the OpenAI-compatible endpoint. For model use any model from the catalog that supports chat.
The config.toml above sets env_key = "CHEAPAI_API_KEY" — Codex reads the key from that variable:
macOS / Linux · ~/.zshrc
export CHEAPAI_API_KEY="cai-..."Windows · PowerShell
[Environment]::SetEnvironmentVariable("CHEAPAI_API_KEY", "cai-...", "User")Alternative: ~/.codex/auth.json with the key in it; the env var is simpler and harder to commit by accident.
Restart the terminal after adding the variable, otherwise Codex won't see it. Check with echo $CHEAPAI_API_KEY (PowerShell — echo $Env:CHEAPAI_API_KEY) — it should print your key.
terminal
codex # interactive mode
codex "fix the failing test in src/auth" # one-off taskSwitch model for a single run: codex -m claude-3-5-sonnet (if the model is in the catalog and supports chat). Permanently — change model in config.toml.
Next: Cursor, Cline, Aider… · OpenAI-compatible API · Error codes.