Agents & CLIsReference / 20

Codex CLI

Point OpenAI's Codex CLI at RouterPlex.

Follow updates Share setup

Codex uses the Responses API for custom model providers. RouterPlex supports that route for Codex; other OpenAI-compatible tools in these docs use /v1/chat/completions when their client expects Chat Completions. Configure RouterPlex in your user-level Codex configuration at ~/.codex/config.toml (the leading dot is required):

Using the Codex extension for VS Code instead of the terminal? See Codex — VS Code extension — same config file, edited from the settings UI.

toml
# ~/.codex/config.toml
model_provider = "routerplex"
model = "gpt-5.6-sol"
 
[model_providers.routerplex]
name = "RouterPlex"
base_url = "https://api.routerplex.com/v1"
wire_api = "responses"
env_key = "ROUTERPLEX_API_KEY"
env_key_instructions = "Set ROUTERPLEX_API_KEY before starting Codex."

Set the API key #

Create a dedicated, budget-capped RouterPlex key in the dashboard, then set it in the terminal session that starts Codex:

bash
export ROUTERPLEX_API_KEY="sk-..."
codex

env_key tells Codex to read the key from ROUTERPLEX_API_KEY and send it as bearer authentication. Keep the key out of config.toml, source control, and shared shell history. Restart Codex after changing either the configuration or the variable.

gpt-5.6-sol is a practical starting model for coding work. To switch models, replace the model value with an exact ID from the catalog, restart Codex, and try a small task first.

Add multiple models #

Codex runs one active model per session, but the same RouterPlex provider can serve any RouterPlex model ID. Keep the shared provider block once in ~/.codex/config.toml, then switch models with --model:

bash
codex --model claude-opus-4-8
codex exec --model gemini-3.5-flash "summarize this repository"

For repeatable presets, create profile files next to config.toml. Each profile only needs the settings that differ from the base RouterPlex provider:

toml
# ~/.codex/routerplex-opus.config.toml
model = "claude-opus-4-8"
model_reasoning_effort = "high"
toml
# ~/.codex/routerplex-flash.config.toml
model = "gemini-3.5-flash"
model_reasoning_effort = "low"

Run a preset with:

bash
codex --profile routerplex-opus
codex exec --profile routerplex-flash "check this diff"

Do not add separate [model_providers.routerplex-*] blocks for each model unless the base URL or authentication method changes. The model ID changes; the RouterPlex provider, base URL, and ROUTERPLEX_API_KEY stay the same.

Verify the configuration #

Start Codex with a small prompt and confirm the request appears under the dedicated key in the RouterPlex dashboard. If authentication fails, run printenv ROUTERPLEX_API_KEY in the same shell before starting Codex; it should show that the variable exists, but do not paste the value into logs or support messages.

If Codex reports an unsupported API format, make sure wire_api = "responses" is present. If a model is rejected, copy its case-sensitive ID from the live catalog and update the model value in the configuration.

Use a separate budget #

Coding agents can make many tool and follow-up calls from one instruction. Create a Codex-specific RouterPlex key with a hard budget rather than reusing a key that also serves an application. The limit is enforced by RouterPlex, so a local configuration mistake or runaway loop cannot spend beyond that key's cap.

Codex CLI — Docs