Codex CLI

Set up a Responses provider and a shell-scoped API key for Codex CLI.

Install and prepare

  1. Install Node.js, then install the official Codex CLI with the command below. Run codex --version in a new terminal.
  2. Create a key on routerra.ai → API Keys. Choose an exact model ID from Models with Responses API and tool-call support; a Chat Completions-only model cannot run this configuration.
npm install -g @openai/codex
codex --version

Define the TOML provider

  1. Edit ~/.codex/config.toml (Windows: %USERPROFILE%\.codex\config.toml). Merge the TOML below without duplicating an existing provider table. model_provider must match routerra; env_key names an environment variable, not the secret itself. Replace YOUR_MODEL_ID.
  2. Export ROUTERRA_API_KEY in the same shell that launches codex. These commands last only for that shell; persist the variable in your shell profile if needed. This custom provider uses its own key rather than a ChatGPT login. Restart Codex after editing TOML.
model = "YOUR_MODEL_ID"
model_provider = "routerra"

[model_providers.routerra]
name = "routerra.ai"
base_url = "https://routerra.ai/v1"
env_key = "ROUTERRA_API_KEY"
wire_api = "responses"

Launch with the provider key

A missing-variable error means Codex did not inherit ROUTERRA_API_KEY; launch it from that terminal. A /responses 404 means the URL or protocol is wrong: keep /v1 exactly once and wire_api = "responses". If text works but a file-listing task fails, select a tool-capable model. Confirm the resulting request appears in routerra.ai usage; successful CLI startup alone does not verify routing.

export ROUTERRA_API_KEY="YOUR_API_KEY"
codex

For Windows PowerShell:

$env:ROUTERRA_API_KEY = "YOUR_API_KEY"
codex