Published November 14, 2026 · 6 min read
Codex CLI with a Custom Provider: config.toml and wire_api = "responses"
Run OpenAI Codex CLI against zrouter. The model_providers block for config.toml, why wire_api must be responses, where the file has to live, and how to fix the usual errors.
OpenAI's Codex CLI can be pointed at any gateway that implements the Responses API. zrouter exposes /v1/responses next to chat completions and messages, so Codex can run against it with one provider block and one environment variable.
This guide shows the config.toml that works, explains wire_api = "responses", and lists the mistakes that cause Codex to ignore a custom provider.
The config
Add this to your user-level Codex configuration (~/.codex/config.toml):
model = "deepseek-v4.1-flash"
model_provider = "zrouter"
[model_providers.zrouter]
name = "zrouter"
base_url = "https://api.zrouter.dev/v1"
env_key = "ZROUTER_API_KEY"
wire_api = "responses"
Then export the key in the shell where you start Codex:
export ZROUTER_API_KEY="zr_your_key_here"
codex
What the fields mean, as described in the Codex advanced configuration and configuration reference pages:
model_providers.<id>defines a provider. The ID (zrouterhere) is what you put inmodel_provider.base_urlis the API root. For zrouter that ishttps://api.zrouter.dev/v1, including/v1.env_keynames the environment variable that holds the key. The key itself never goes into the file.wire_apiis the protocol Codex speaks to the provider.
Why wire_api = "responses"
The configuration reference says that responses is the only supported value for wire_api, and that it is the default when you leave it out. Older guides that tell you to set wire_api = "chat" may predate the current Codex release. With a current Codex, the provider you point at must therefore implement the Responses API.
zrouter does. A plain request to /v1/responses works with the same zr_ key:
curl https://api.zrouter.dev/v1/responses \
-H "Authorization: Bearer $ZROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"deepseek-v4.1-flash","input":"Say hi","max_output_tokens":512}'
If that returns 200, Codex will be able to use the provider. Keep wire_api = "responses" in the file even though it is the default; it makes the intent obvious to the next person who reads the config.
Where the file must live
This is the most common reason a custom provider is ignored. The configuration reference states that Codex ignores model_provider and model_providers when they appear in a project-local .codex/config.toml, and says to put provider keys in the user-level config instead. So:
- Put the
[model_providers.zrouter]block in~/.codex/config.toml. - A project-level
.codex/config.tomlcan still hold project settings, just not the provider definition.
A shortcut for the built-in provider
If all you want is to redirect the built-in OpenAI provider to a different base URL, the same page describes a top-level openai_base_url setting, which avoids defining a separate provider. A named zrouter provider is clearer when you want to keep the original provider available next to it, and lets you switch with model_provider.
Troubleshooting
| Symptom | Likely cause |
| --- | --- |
| Codex still talks to the default provider | The block is in a project .codex/config.toml (ignored), or model_provider is missing |
| 401 invalid_api_key | The key is wrong, expired or revoked, or ZROUTER_API_KEY is not exported in the shell that started Codex |
| 402 insufficient_balance | No Token Plan left for the model and the pay-as-you-go balance is empty. Top up and retry |
| 404 model_not_found | The model name does not match the catalog, or the model is not visible |
| Empty answer on a tiny request | A reasoning model used the whole output budget thinking. Raise max_output_tokens |
What it costs
At the time of writing, deepseek-v4.1-flash is $0.015 per 1M input tokens and $0.06 per 1M output tokens, 90% below the official price, with a 1,000,000-token context. A Token Plan ($1, $2, $5 or $10) is used before the pay-as-you-go balance; the balance does not expire and there is no 5-hour window. Check the model page and pricing for current numbers, and the API docs for the Responses endpoint.
You can pay with QRIS, USDT or USDC, no credit card needed. For USDT and USDC the sender pays the blockchain network fee, and QRIS checkouts may carry a small service fee that is shown before you confirm.
Summary
- Put the provider in
~/.codex/config.toml, not in a project file. base_url = "https://api.zrouter.dev/v1",env_key = "ZROUTER_API_KEY",wire_api = "responses".- Test
/v1/responseswithcurlfirst; if it returns200, Codex will work.