Codex — VS Code extension
Configure OpenAI's Codex extension for VS Code with 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 the Codex VS Code extension on this machine to use RouterPlex, an OpenAI- and Anthropic-compatible AI gateway. Keep working until a real request from the Codex VS Code extension 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 (show at most its first 8 characters).Config handling:- Before changing an existing config file or shell startup file, copy it to a .bak file next to it and show me the diff. Merge into what is there; never replace my other settings, providers, or MCP servers.- If a step needs something only I can do, such as a click in a settings window, print the exact steps instead of guessing.Full guide: https://docs.routerplex.com/codex-vscodeStep 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 the Codex VS Code extension:- The extension shares the Codex CLI's user-level config. Merge this into ~/.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"- Make ROUTERPLEX_API_KEY permanent for my user so new terminals get it:- macOS/Linux: add export ROUTERPLEX_API_KEY='<key>' (keep the word export: a plain ROUTERPLEX_API_KEY=... line is invisible to programs started from the shell) 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.- VS Code only sees variables that existed when it started. Tell me to fully quit every VS Code window. On macOS, a VS Code started from the Dock does not read shell startup files, so either have me start it with code . from a new terminal or run launchctl setenv ROUTERPLEX_API_KEY '<key>'.Step 3. Test the Codex VS Code extension itself from a new terminal or a restarted app, so you test the saved setup rather than the shell you changed:First run the Codex CLI, which uses the same config, 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.'If the CLI is not installed, install it with curl -fsSL https://chatgpt.com/codex/install.sh | sh. Then ask me to start a new conversation in the extension and send: Reply with exactly: RouterPlex connected.Expected reply: "RouterPlex connected."Step 4. If step 1 works but step 3 fails, the problem is the Codex VS Code extension'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 the Codex VS Code extension 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.- the Codex VS Code extension is outdated, or still needs a full restart to read the new settings.- If an environment variable cannot be made to reach the Codex VS Code extension reliably and the Codex VS Code extension 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.Step 5. The test above sends no tools, but real sessions send every tool, MCP server, and plugin schema with each request, and that is where models differ. From a folder with a README.md (create a temporary one containing "# RouterPlex tool check" if needed), run:codex exec --model gpt-5.6-terra "List your available tools, then read ./README.md and reply with its first heading."It passes when the reply lists the tools and quotes the heading. If it fails while step 3 passes, the tool schemas are the problem, not the connection. Tell me the exact error; the chosen model may not handle the Codex VS Code extension's tools, so suggest another tool-capable model from https://routerplex.com/models.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 exactly which files you changed and which values you set (key shown by its first 8 characters only) so I can undo it, where the key is stored, and the final test output. Remind me that every request shows up in https://routerplex.com/dashboard/usage.
Manual setup #
The Codex VS Code extension shares Codex's user configuration. Use the current extension on macOS, Linux, or Windows; a VS Code window connected to WSL or SSH uses the remote environment instead.
1. Open the configuration #
Install/update the official Codex extension. In its panel, open the settings menu and choose the option to open config.toml (some releases group this under Codex settings → Configuration).
- macOS/Linux:
~/.codex/config.toml - Windows:
%USERPROFILE%\.codex\config.toml - Custom location:
config.tomlinsideCODEX_HOME, if set.
Use the user-level file, not your project's .codex/config.toml: current Codex ignores provider/auth changes in project configuration.
2. Add RouterPlex #
Merge the following into your existing file. Top-level keys go before any [table] header. Update an existing RouterPlex provider block rather than creating it twice. Keep unrelated settings.
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"
RouterPlex's Codex integration uses the Responses API. The same API key works here; it is loaded from your process environment.
3. Start VS Code with your key #
Fully quit all VS Code windows first. In the terminal that will launch VS Code:
macOS / Linux
export ROUTERPLEX_API_KEY='YOUR_ROUTERPLEX_API_KEY'code .
Windows PowerShell
$env:ROUTERPLEX_API_KEY = 'YOUR_ROUTERPLEX_API_KEY'code .
Replace YOUR_ROUTERPLEX_API_KEY with your key. If code is unavailable on macOS, run Shell Command: Install 'code' command in PATH in the VS Code Command Palette first. See environment setup for persistent Windows variables, desktop launchers, WSL, and SSH.
Reloading a window is not enough if the existing VS Code process never received the variable. For WSL, put the config and key inside WSL and open a WSL VS Code window.
4. Verify #
Start a new Codex conversation and ask Reply with exactly: RouterPlex connected. Do not read files or run tools. Confirm the request in Usage.
If you are asked for unrelated provider authentication, check which environment and config file the extension is using. To isolate extension setup problems, run the Codex CLI test from the same terminal. Change the model only to an exact ID from the catalog; API compatibility alone does not guarantee every model's agent behavior.
Official references: Codex configuration, Codex IDE extension.