Codex CLI
Point OpenAI's Codex CLI at RouterPlex.
On this page
Set it up with your coding agent #
Paste your key into the prompt's key field, then copy the prompt into Claude Code, Codex, Cursor, or any coding agent. It configures the tool and keeps testing until a real request goes through RouterPlex, fixing environment problems along the way. Prefer to do it by hand? Follow the manual setup below; your key fills those commands too.
Optional. It stays in this browser tab and is never saved or sent. No key yet? Create one in guided setup.
Set up Codex CLI on this machine to use RouterPlex, an OpenAI- and Anthropic-compatible AI gateway. Keep working until a real request from Codex CLI succeeds through RouterPlex.My RouterPlex API key: YOUR_ROUTERPLEX_API_KEYKey handling:- If the key line above is a placeholder rather than a real key (real keys start with sk-), use my ROUTERPLEX_API_KEY environment variable. If that is empty too, ask me for the key once, then continue.- Store the key only in user-level config or my user environment. Never put it in a project file, never commit it, and do not repeat the full key in your replies.Full guide: https://docs.routerplex.com/codex-cliStep 1. Prove the key and the RouterPlex gateway work before changing anything else. Run:curl -sS https://api.routerplex.com/v1/chat/completions -H "Authorization: Bearer YOUR_ROUTERPLEX_API_KEY" -H "Content-Type: application/json" -d '{"model":"claude-sonnet-4-6","max_tokens":32,"messages":[{"role":"user","content":"Reply with exactly: RouterPlex connected."}]}'On Windows PowerShell, use curl.exe with the body in a file, or Invoke-RestMethod.- A reply containing "RouterPlex connected.": go on.- 401: the key is wrong or revoked. Stop and ask me for a correct key.- 402: my balance or trial credit is used up. 403: this key reached its own spending limit. Stop and tell me; retrying cannot fix these.- Network, DNS, TLS, or proxy errors: find and fix the cause (proxy variables, VPN, firewall, system clock, outdated CA certificates), then run it again.Step 2. Configure Codex CLI:- Run codex --version. If Codex is missing, install it with the official installer (curl -fsSL https://chatgpt.com/codex/install.sh | sh).- Merge this into my user-level ~/.codex/config.toml (Windows: %USERPROFILE%\.codex\config.toml; use $CODEX_HOME/config.toml if CODEX_HOME is set). Keep my other settings, put model and model_provider above any [table] header, and update an existing [model_providers.routerplex] block instead of adding a second one:model_provider = "routerplex"model = "gpt-5.6-terra"model_reasoning_effort = "low"[model_providers.routerplex]name = "RouterPlex"base_url = "https://api.routerplex.com/v1"wire_api = "responses"env_key = "ROUTERPLEX_API_KEY"- wire_api = "responses" is required. env_key makes Codex read the key from ROUTERPLEX_API_KEY.- Make ROUTERPLEX_API_KEY permanent for my user so new terminals get it:- macOS/Linux: add export ROUTERPLEX_API_KEY='<key>' to the startup file of the shell I use (check $SHELL: zsh uses ~/.zshrc; bash uses ~/.bashrc, plus ~/.bash_profile or ~/.profile if they do not source ~/.bashrc). Update an existing line instead of adding a second one.- Windows: run [Environment]::SetEnvironmentVariable('ROUTERPLEX_API_KEY', '<key>', 'User'). Only terminals and apps started after this see it.- WSL, SSH, or a dev container: set it inside that environment, where the tool actually runs.Step 3. Test Codex CLI itself from a new terminal or a restarted app, so you test the saved setup rather than the shell you changed:From an empty temporary folder: codex exec --skip-git-repo-check --model 'gpt-5.6-terra' 'Reply with exactly: RouterPlex connected. Do not read files or run tools.'Expected reply: "RouterPlex connected."Step 4. If step 1 works but step 3 fails, the problem is Codex CLI's configuration or environment, not RouterPlex. Check these, fix what is wrong, and repeat step 3:- The key or base URL is set in one place but not where Codex CLI starts: zsh vs bash startup files, login vs non-login shells, a desktop launcher, a background service, Windows vs WSL, or a remote SSH or container environment.- Another setting wins: OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_API_BASE, ANTHROPIC_API_KEY, ANTHROPIC_BASE_URL, or a project-level config that overrides the user-level one.- Codex CLI is outdated, or still needs a full restart to read the new settings.- If an environment variable cannot be made to reach Codex CLI reliably and Codex CLI accepts a key in its user-level config, put the key there instead.Keep repeating steps 3 and 4 until the test reply comes back. Stop early only for a 401, 402, or 403, or for a step only I can do, such as a click in a settings window or a login. Then tell me exactly what to do, wait for me, and continue testing afterwards.When it works, tell me which files you changed, where the key is stored, and the final test output.
Manual setup #
Use RouterPlex's Responses API with a user-level Codex custom provider. Start with the example model, then try other catalog models on a small task before relying on their agent behavior.
1. Install or update #
macOS / Linux
curl -fsSL https://chatgpt.com/codex/install.sh | sh
Windows PowerShell
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
Reopen your terminal and run codex --version. These commands use the standalone installer. If you chose the npm install on Windows, use codex.cmd when PowerShell blocks codex.ps1.
2. Save the provider #
Edit the user-level config.toml:
- macOS/Linux:
~/.codex/config.toml - Windows:
%USERPROFILE%\.codex\config.toml - Custom location:
config.tomlinsideCODEX_HOME, if set.
Merge the settings below. Put model and model_provider above any [table] headers; update the existing RouterPlex block if present. Current Codex ignores provider/auth configuration in project .codex/config.toml files.
model_provider = "routerplex"model = "gpt-5.6-terra"model_reasoning_effort = "low"[model_providers.routerplex]name = "RouterPlex"base_url = "https://api.routerplex.com/v1"wire_api = "responses"env_key = "ROUTERPLEX_API_KEY"
wire_api = "responses" is required for this path. env_key reads your RouterPlex key from the process environment; do not insert the raw key into the TOML file.
3. Set your key and test #
Use an empty folder and replace YOUR_ROUTERPLEX_API_KEY with your key.
macOS / Linux
export ROUTERPLEX_API_KEY='YOUR_ROUTERPLEX_API_KEY'codex exec --skip-git-repo-check --model 'gpt-5.6-terra' 'Reply with exactly: RouterPlex connected. Do not read files or run tools.'
Windows PowerShell
$env:ROUTERPLEX_API_KEY = 'YOUR_ROUTERPLEX_API_KEY'codex exec --skip-git-repo-check --model 'gpt-5.6-terra' 'Reply with exactly: RouterPlex connected. Do not read files or run tools.'
Check the reply and Usage. Then run codex in your project. Set the variable again in a new terminal. See environment setup for persistent settings and WSL.
Switch models and profiles #
Use codex --model claude-sonnet-4-6 to change only the model while keeping the provider. Your key must allow the selected model.
For Codex 0.134.0 and later, a profile is a separate file alongside config.toml, for example routerplex-sonnet.config.toml:
model = "claude-sonnet-4-6"
Launch with codex --profile routerplex-sonnet. Keep shared provider settings in the base config. Older [profiles.name] examples do not apply to current releases; update Codex before using this profile layout.
Troubleshooting #
Check key presence without printing its value using environment setup. Restart Codex after changing configuration. If the route or model is wrong, inspect user and project overrides. Responses compatibility is separate from a model's ability to follow Codex tool instructions.
For the VS Code extension, use its guide, especially the environment inheritance steps.
A longer walkthrough of the same custom provider is in Codex CLI custom provider.
Official references: Codex installation, custom providers and profiles.