Codex CLI
Configure a custom model provider in ~/.codex/config.toml with the
gateway base URL and your IQ API key to route Codex model calls through IQ.
Drop-in switch
Add a custom model provider to ~/.codex/config.toml and make it the
default:
model = "auto-coding"
model_provider = "iq-routing"
[model_providers.iq-routing]
name = "IQ"
base_url = "https://gateway.iq-routing.com/v1"
env_key = "IQ_API_KEY"
wire_api = "responses"
Then export your gateway key under the name you gave env_key and run
Codex:
export IQ_API_KEY="gw_live_xxxxxxxx"
codex
base_url keeps the /v1 suffix, since Codex calls /v1/responses.
wire_api = "responses" selects the Responses wire format; the gateway implements the stateful Responses API end
to end, so streamed tool calls and previous_response_id continuation
work the same as they do against OpenAI directly. model = "auto-coding" is a task alias, and a custom model ladder is a
Team setting described in the routing docs.
Opt-in wrapper instead of a default
If you would rather keep plain codex on its existing login and route
through the gateway only when you choose, skip the config-file default
and pass the same provider as -c overrides from a shell function:
iqcodex() {
codex \
-c model_provider=iq \
-c model=auto-coding \
-c 'model_providers.iq.name="IQ"' \
-c 'model_providers.iq.base_url="https://gateway.iq-routing.com/v1"' \
-c 'model_providers.iq.env_key="IQ_API_KEY"' \
-c 'model_providers.iq.wire_api="responses"' \
"$@"
}
iqcodex then routes through IQ while bare codex stays exactly as it
was.
Verify it routes
Start Codex in a scratch repo and give it a one-line task
(“list the files in this directory”). The tool call streams,
executes, and the summary renders with the gateway's standard
latency. Open your dashboard at /requests and each Codex turn is its
own row, with the chosen model, the cost, and the cache-hit status. The
response also carries the x-iq-routing header
(chosen_provider, chosen_model, cache_hit), so you can confirm
which concrete model handled the turn, plus an X-Request-Id header you
can paste into /requests/<uuid> to pull up that exact turn. An invalid
key returns 401; a revoked key (from /keys) returns
403 API key revoked. No row after a turn that otherwise looked normal
usually means model_provider stayed on its default -- see Common
gotchas below.
Using capability aliases
Set model to a cap:<name> alias to request a capability; see the
capability docs for available aliases:
model = "cap:reason-heavy"
model_provider = "iq-routing"
Use a capability alias to request a suitable model for a task; inspect the response to see the model used and manage your organization's overrides at /settings/capabilities.
Common gotchas
Configure the gateway provider with its own base_url and select it
with model_provider; the built-in OpenAI provider also has an
openai_base_url config setting, and its default endpoint depends on
whether you use API-key or ChatGPT authentication.
Use wire_api = "responses" for current Codex releases; consult the
Codex configuration reference
when updating an older configuration.
Long agent sessions can spend fast, especially with shell-command loops.
If a turn returns 429, check the X-RateLimit-Scope header to see
which cap fired: rps, rpm, and tpm carry a Retry-After window
to back off against (rps is a one-second window, rpm/tpm are
sixty-second), while daily_budget resets at midnight UTC,
monthly_budget resets at the start of the next month, and
key_spend_ceiling needs a manual budget increase. Watch your /dashboard spend bar during long runs. See the
FAQ for the full list of scopes.
Function tools round-trip fully, streamed or not, including namespaced
tool groups (Codex sub-agents and MCP-app tools): a dot-qualified
ns.fn call still reaches the right sub-agent or MCP tool on the other
side. Provider-hosted tools with no
function body, such as web_search and image_generation, are the one
category that does not cross yet -- the gateway drops those entries from
the roster instead of forwarding them, so a Codex run that reaches for one
falls back to its function tools rather than erroring the whole call.
On startup Codex refreshes model metadata from /v1/models. The
gateway's response carries the top-level models array Codex reads
alongside the standard OpenAI data array, so the refresh parses
cleanly and routing is unaffected.
Each Codex turn is its own row in /requests; the gateway does not
collapse a multi-turn session into one entry.