multi-router.aidocs

Agents & Editors

Codex CLI

Connecting OpenAI's Codex CLI to a Codex Proxy with the OpenAI Responses format.

Codex CLI is OpenAI's coding agent for the terminal. It sends OpenAI Responses requests only, so it connects to Multi-Router through a Codex Proxy, which serves /v1/responses for OpenAI models and forwards each request to OpenAI unchanged.

Creating the router

  1. In Routers, choose New router, then Codex Proxy, and name it.
  2. Choose the OpenAI credential: Organization, with one of the organization's enabled OpenAI keys, or Developer, so that each developer's own OpenAI API key is passed through.
  3. Create the router. Its id, such as rt_XXXXXXXX, is on the router's page, under Forwarding with the Codex CLI settings.
  4. In API Keys, create a key with the inference scope for each developer. It can be limited to this router.

Settings

Codex CLI reads custom providers from ~/.codex/config.toml. A project's own .codex/config.toml cannot set a provider. Add a provider with the Responses format and the router header. The Multi-Router API key travels in its own header, X-MR-Api-Token, read from an environment variable:

~/.codex/config.tomltoml
model_provider = "multi_router"
model = "gpt-5"

[model_providers.multi_router]
name = "Multi-Router"
base_url = "https://api.multi-router.ai/v1"
wire_api = "responses"
env_key = "OPENAI_API_KEY"
http_headers = { "X-MR-Router" = "rt_XXXXXXXX" }
env_http_headers = { "X-MR-Api-Token" = "MR_API_TOKEN" }
Shellbash
export MR_API_TOKEN='Bearer <Multi-Router API key>'
export OPENAI_API_KEY='<OpenAI API key, or any value with the Organization credential>'
SettingValue
MR_API_TOKENThe Multi-Router API key with the Bearer prefix.
OPENAI_API_KEYWith the Developer credential, the developer's own OpenAI API key. With the Organization credential, any non-empty value; the organization's OpenAI key replaces it.
base_urlReplaces OPENAI_BASE_URL for this provider.

Codex CLI tries a WebSocket connection first. The Codex Proxy refuses it, and Codex CLI continues over HTTP. A ChatGPT plan sign-in does not go through a Codex Proxy.

Models

A Codex Proxy serves OpenAI models only, named as OpenAI names them, such as gpt-5, in model or with -m. A model from another provider is refused with 400 is not an OpenAI model, and a model unknown to the Multi-Router catalog is refused before it reaches OpenAI.

Checking the setup

A first requestbash
codex exec --skip-git-repo-check 'Reply exactly ready.'

The request then appears in Traffic with the Codex Proxy in the Router column and the model, tokens and cost in the request detail. A reply with the requested model or router was not found means the router id is wrong, or the API key is not allowed to use that router. See Traffic and Troubleshooting.

Claude CodeGemini CLI
Was this helpful?