Home / Guides / Configure Codex CLI to route through API Token Route
Configure Codex CLI to route through API Token Route
One config file and one environment variable. No changes to Codex itself.
Codex CLI reads its model provider from ~/.codex/config.toml. Set model_provider = "apitokenroute", point base_url at https://api.apitokenroute.com/v1, set wire_api = "responses", and export OPENAI_API_KEY with your sk-atr- key. Then run codex; Codex sends its requests through API Token Route.
What this setup does
Codex CLI speaks the OpenAI Responses API. API Token Route exposes that API at /v1/responses, so Codex can use the gateway without a proxy or a patched build. The provider block tells Codex where to send requests; the environment variable supplies the key.
- Codex uses GPT models. Claude and Gemini are not available through Codex's Responses path.
- The same
sk-atr-key works with Claude Code and other tools; each tool uses its own protocol. - Check your console balance first; a small trial credit may be present. Top up at least $5 for sustained use.
Install Codex CLI (Node.js 22 or later)
Check Node first. Codex requires Node.js 22 or later.
node -v
npm install -g @openai/codex
codex --versionOn macOS you can also use Homebrew: brew install codex. To update later: npm install -g @openai/codex@latest.
If the shell cannot find codex after installation, npm's global bin directory is not on PATH. Run npm config get prefix, add its bin folder to PATH, then open a new terminal.
Write the config file
macOS and Linux: paste the whole block into a terminal.
mkdir -p ~/.codex
cat > ~/.codex/config.toml <<'EOF'
model_provider = "apitokenroute"
model = "gpt-6.2-sol"
model_reasoning_effort = "high"
[model_providers.apitokenroute]
name = "API Token Route"
base_url = "https://api.apitokenroute.com/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"
EOFWindows PowerShell:
New-Item -ItemType Directory -Force -Path "$HOME\.codex" | Out-Null
@'
model_provider = "apitokenroute"
model = "gpt-6.2-sol"
model_reasoning_effort = "high"
[model_providers.apitokenroute]
name = "API Token Route"
base_url = "https://api.apitokenroute.com/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"
'@ | Set-Content -Path "$HOME\.codex\config.toml" -Encoding UTF8Set OPENAI_API_KEY
Replace the placeholder with the key from the console's API Keys page.
macOS (zsh):
echo 'export OPENAI_API_KEY="sk-atr-..."' >> ~/.zshrc
source ~/.zshrcLinux (bash):
echo 'export OPENAI_API_KEY="sk-atr-..."' >> ~/.bashrc
source ~/.bashrcWindows PowerShell:
[Environment]::SetEnvironmentVariable("OPENAI_API_KEY", "sk-atr-...", "User")Close and reopen PowerShell after the Windows command. A running window keeps the old environment.
Run Codex and change models
Open a new terminal and run codex. Codex reads the config when it starts. To use another model, change model in config.toml to a GPT model ID from the catalog, for example gpt-6.2-sol or gpt-6.2-astra.
Keep wire_api = "responses". Codex's Responses path is for GPT models; pointing it at a Claude or Gemini ID returns an error instead of falling back.
Check the key and balance independently with the model list:
curl https://api.apitokenroute.com/v1/models -H "Authorization: Bearer $OPENAI_API_KEY"Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
codex: command not found | npm global bin is not on PATH | Run npm config get prefix, add its bin folder to PATH, open a new terminal. |
| 401 authentication error | OPENAI_API_KEY missing from this shell, or the key was deleted | Re-export the key, open a new terminal, or create a new key in the console. |
| 400 wallet balance is insufficient | Balance is $0 or too low | Top up at least $5 and retry. |
| 400 model_not_available | Model ID is not in the catalog | Use the exact catalog ID. Claude IDs use hyphens; Codex needs a GPT ID. |
| 404 or connection error | base_url is wrong | Use exactly https://api.apitokenroute.com/v1, including /v1. |
| 429 | Requests-per-minute limit | Wait for the retry-after interval and retry with backoff. |
Limits of this setup
This configuration routes Codex to GPT models through the Responses API. It does not make Claude or Gemini usable inside Codex. For those, use a client that speaks the matching protocol: Claude Code for Anthropic models, Gemini CLI for Gemini models.
Read next: Codex CLI setup, API integration guide, pricing, model catalog.
FAQ
Does Codex read OPENAI_BASE_URL?
No. Codex takes the provider from ~/.codex/config.toml, not from OPENAI_BASE_URL. It reads OPENAI_API_KEY only because the provider block names that variable in env_key.
Can I use Claude models through Codex?
No. Codex uses the Responses API, which serves GPT models. Claude requests return 400. Use Claude Code for Claude models.
Where is config.toml on Windows?
In your home directory: $HOME\.codex\config.toml, normally C:\Users\
Do I need to restart after editing the config?
Start a new codex session so it rereads the file. Environment variable changes need a new terminal window.
Why do I get 401 after setting the key?
The variable was set in a different window, or the value has spaces or a newline. Check it in the same shell that runs codex, then open a new terminal.
What is the minimum balance for Codex?
Top-ups start at $5. Check the console balance first; a small trial credit may be present, but do not rely on it for sustained use.