Skip to content
IQ

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 supports stateful Responses calls, so streamed tool calls and previous_response_id continuation work. Cancelling a response and listing its input items are not supported. 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, cost and cache status. When present, the x-iq-model response header identifies the model IQ dispatched, or the model recorded for a cache hit. Streaming headers are sent before provider-side substitutions can be verified. Use X-Request-Id to open that turn in /requests/<uuid>. 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; open Requests to see the model IQ recorded and manage your workspace'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, read the error code and any X-RateLimit-Scope header. Request and token limits (rps, rpm, and tpm) carry Retry-After and X-RateLimit-Reset. The rps window is one second, and rpm and tpm use 60-second windows. Both daily_budget and team_daily_budget carry Retry-After for the next UTC reset.

Monthly budget replies (monthly_budget, team_monthly_budget) carry no Retry-After. They reset at the start of the next UTC month. Weekly seat model limits return seat_model_limit_reached and Retry-After, without X-RateLimit-Scope or X-RateLimit-Reset. The limit resets Monday at 00:00 UTC.

A key_spend_ceiling response carries X-RateLimit-Reset: 0. This ceiling does not reset on a clock, so 0 is not a time to retry. Ask your workspace admin to raise it. 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.