# Codex VS Code extension and desktop app: connect a custom API provider

> Markdown mirror of https://router.one/codex-vscode for AI assistants and crawlers. Router One is a unified, OpenAI-compatible LLM API gateway.
> Last updated: 2026-12-06

Yes: the Codex IDE extension (VS Code, Cursor, Windsurf; `openai.chatgpt`) and Codex in the ChatGPT desktop app share `~/.codex/config.toml` with Codex CLI (OpenAI IDE & Developer settings docs, checked 2026-12-06). Add `[model_providers.router]` (`base_url = "https://api.router.one/v1"`, `wire_api = "responses"`, `env_key = "ROUTER_ONE_API_KEY"`) with top-level `model_provider = "router"` and `model = "gpt-6.2-sol"`, set `ROUTER_ONE_API_KEY` in `~/.codex/.env`, and restart. On Router One, model requests use a China-reachable Responses endpoint without a VPN or ChatGPT Plus.

## How the IDE extension, CLI and desktop app share config.toml

Per OpenAI's Codex IDE, Developer settings and Config basics docs (checked 2026-12-06), agent settings (model, reasoning effort, permissions, sandbox, MCP, personalization) live in `config.toml` across CLI, IDE extension and desktop app, while editor-only `chatgpt.*` keys stay in VS Code settings. Per Advanced Configuration docs (checked 2026-12-06), project-local `.codex/config.toml` ignores `model_provider`, `model_providers` and `openai_base_url`, so define providers in user-level `~/.codex/config.toml`. For Router One we recommend a custom provider over `openai_base_url`, which sends the credential Codex holds for OpenAI (ChatGPT sign-in tokens included) to that address (https://router.one/codex-responses-api).

| Client | Config file | Setup entry | Reload |
| --- | --- | --- | --- |
| VS Code, Cursor, Windsurf (`openai.chatgpt`) | `~/.codex/config.toml` (Windows: `%USERPROFILE%\.codex\config.toml`) | Gear → Codex Settings → Open config.toml (if the Codex icon is hidden: Command Palette → Codex: Open Codex Sidebar) | Quit all windows and reopen |
| ChatGPT desktop app (Codex) | `~/.codex/config.toml` (Windows: `%USERPROFILE%\.codex\config.toml`) | Settings → Model Providers → Add → Gateway or custom provider | Save in UI or restart app |
| Codex CLI | `~/.codex/config.toml` (`CODEX_HOME` overrides default) | Edit `config.toml`, or `/config` → Sessions → Model providers | Start new `codex` session |

- Other IDEs: OpenAI's IDE docs (checked 2026-12-06) list VS Code, VS Code Insiders, Cursor and Windsurf on `openai.chatgpt`; Xcode and JetBrains use separate integrations.
- Windows WSL2: when Codex runs inside WSL (for the extension, with `chatgpt.runCodexInWindowsSubsystemForLinux` on), it reads `config.toml` and `.env` from Linux `~/.codex/`, not `%USERPROFILE%\.codex\`, unless `CODEX_HOME` points elsewhere (Connect to a gateway and Windows app docs, checked 2026-12-06).

## Configure Router One in ~/.codex/config.toml

This is the block from https://router.one/codex-responses-api; the https://router.one/codex-china one-click install writes the same model, model_provider, base_url, env_key and wire_api, plus a few optional keys and the display name Router One. Keep `model` and `model_provider` above the first `[table]` header (Connect to a gateway docs, checked 2026-12-06: keys after a header belong to that table).

`~/.codex/config.toml`

```toml
# ~/.codex/config.toml
model = "gpt-6.2-sol"
model_provider = "router"

[model_providers.router]
name = "router"
base_url = "https://api.router.one/v1"
env_key = "ROUTER_ONE_API_KEY"
wire_api = "responses"
```

- Active model: follows the `model` line in `config.toml` (context windows and `model_context_window`: /codex-context-window).
- IDE model choice: OpenAI's Codex models docs (checked 2026-12-06) list GPT-6.2 Sol for the Codex app and CLI; if the extension shares this `config.toml`, they suggest a model every client offers, such as `gpt-6.1-sol`. Router One serves both natively on `POST /v1/responses`.
- Responses models: per Configuration Reference (checked 2026-12-06), `wire_api = "responses"` is the only supported value. Router One serves GPT chat models (`gpt-6.2-sol`, `gpt-6.1-sol`, `gpt-6-sol`, `gpt-6.2-astra`), DeepSeek (`deepseek-v4.1-flash`, `deepseek-v4-flash`) and Grok chat models (`grok-4.7`, `grok-4.6`, `grok-4.5`, `grok-4.7-build-fast`) natively on `POST /v1/responses` (Grok since 2026-09-22; GPT-6.2 Sol and GPT-6.2 Astra observed 2026-11-22); the authoritative list is the models whose detail page on /models lists `POST /v1/responses`.
- GPT-6 tools & Claude 400s: GPT-6-family tool calls go to `/v1/responses`, which Codex uses natively. Claude-family IDs return HTTP 400 before any model is called (`model '<id>' must be called via /v1/messages or /v1/chat/completions`), so use Claude Code for Claude models. Responses limits (`background: true`, `image_generation` → 400): https://router.one/codex-responses-api.

## Pass ROUTER_ONE_API_KEY to VS Code and the desktop app

Per Connect to a gateway docs (checked 2026-12-06), a terminal variable may not reach a desktop-launched app. Put the key in `~/.codex/.env` or launch VS Code from an exported shell, then test with `GET /v1/models` (200 = accepted, 401 = refused):

`~/.codex/.env and key check`

```bash
# Option 1: ~/.codex/.env (Windows: %USERPROFILE%\.codex\.env)
ROUTER_ONE_API_KEY=sk-your-router-one-key

# Option 2: quit every VS Code window, export in a shell, then launch VS Code from it:
export ROUTER_ONE_API_KEY="sk-your-router-one-key"
code .

# Verify key (200 or 401; reads ROUTER_ONE_API_KEY from this shell):
curl -s -o /dev/null -w "%{http_code}\n" https://api.router.one/v1/models -H "Authorization: Bearer $ROUTER_ONE_API_KEY"
# Windows PowerShell:
curl.exe -s -o NUL -w "%{http_code}" https://api.router.one/v1/models -H "Authorization: Bearer $env:ROUTER_ONE_API_KEY"
```

- The check reads `ROUTER_ONE_API_KEY` from the shell you run it in: with Option 1 only, set the same key in that shell first; if `~/.codex/.env` holds a different value, Codex sends that one.
- Option 2 needs every VS Code window closed first: per VS Code's command-line docs (checked 2026-12-06), a new `code` launch inherits the environment of an already running VS Code instance.
- Why `~/.codex/.env` works: per `openai/codex` `rust-v0.174.0` (`arg0/src/lib.rs`, `app-server/src/main.rs`, checked 2026-12-06), CLI and `app-server` load `CODEX_HOME/.env` before threads start, overriding shell values for non-`CODEX_` keys. Never commit `.env`.
- Windows PowerShell: run `[Environment]::SetEnvironmentVariable("ROUTER_ONE_API_KEY", "sk-your-router-one-key", "User")`, then restart all windows. 401 or `Missing environment variable`: https://router.one/codex-401-unauthorized.

## Desktop app GUI and CLI /config setup

Connect to a gateway docs (checked 2026-12-06) also cover interactive setup menus:

- ChatGPT desktop app: Settings → Model Providers → Add → Gateway or custom provider; enter Name (`Router One`), Base URL `https://api.router.one/v1`, Authentication → Environment variable with `ROUTER_ONE_API_KEY` in API key environment variable, turn on Set as current provider (if shown), click Save, and open a new chat.
- Codex CLI: `/config` → Sessions → Model providers → Create a custom provider or gateway, fill Name, Base URL and API key variable, Save, then, if your organization lets you change the default, press `Space` to set it as default.

## Sign-in screen, requires_openai_auth and API key limits

Per Authentication docs (Alternative model providers, checked 2026-12-06), custom providers support five auth modes: OpenAI auth (`requires_openai_auth` on, via ChatGPT or OpenAI API key), `env_key`, native gateway OAuth (`gateway_oauth`), command-backed tokens (`auth`), or no auth (unset/`false`, no credential settings). Leave `requires_openai_auth` off for Router One: it defaults to `false` (`model-provider-info/src/lib.rs`, `rust-v0.174.0`, checked 2026-12-06), while enabling it turns on OpenAI sign-in.

| Feature (OpenAI docs, checked 2026-12-06) | API key sign-in | ChatGPT sign-in (Plus, Pro, Business, Enterprise) |
| --- | --- | --- |
| IDE extension, CLI, desktop local chats | Available | Available |
| Local `/review`, sandbox, worktrees, `AGENTS.md`, Skills, MCP, subagents | Available | Available |
| First-party plugins | Limited (some need unsupported OAuth) | Available |
| Codex cloud, cloud environments, IDE → Codex web delegation | Unavailable | Available |
| GitHub PR reviews, Slack/Linear cloud, Connectors, Plugin sharing | Unavailable | Available |
| Voice dictation, ChatGPT Voice, Mobile remote control, Work web | Unavailable | Available |

- If the sign-in screen still shows: in `rust-v0.174.0` (`account_processor.rs`, `model-provider/src/provider.rs`, checked 2026-12-06), `app-server` reports `requires_openai_auth: false` and no account when the active provider leaves it off. Confirm `model_provider = "router"` sits above `[table]` headers, `requires_openai_auth` is off, `ROUTER_ONE_API_KEY` is in `~/.codex/.env`, and all windows restarted.
- Signed-out buttons vs custom provider: Use API Key in the IDE (Sign in another way in desktop) saves an OpenAI Platform key as Codex's OpenAI authentication, stored as `cli_auth_credentials_store` sets (file, keyring, auto or ephemeral; Authentication docs, checked 2026-12-06). Per the openai/codex source (see https://router.one/codex-401-unauthorized), a custom provider that leaves `requires_openai_auth` off never sends that key, so Router One's `env_key` provider is unaffected. You don't need to sign out of ChatGPT to use the `env_key` provider locally.
- Feature differences: Authentication docs state "API key authentication supports local Codex workflows, but some features that rely on ChatGPT workspace access or cloud services are limited or unavailable" (Feature availability, checked 2026-12-06).
- The table compares sign-in methods. A custom provider such as Router One only changes where model requests go; features that rely on a ChatGPT workspace still need ChatGPT sign-in.

## Billing, per-key caps, logs and error codes on Router One

Top up with a card, Alipay or WeChat Pay through hosted checkout, or with USDT/USDC on six chains (Tron, BSC, Ethereum, Polygon, Base, Arbitrum). No US credit card required. Pricing starts as low as 10% of official provider list prices (up to 90% off) on select models; live per-model rates: https://router.one/models. On Pro, Max or Ultra plans (/pricing), a billed request uses plan quota when your plan covers that model and has quota left, and the wallet otherwise.

- Logs: Dashboard → Logs records each request the gateway forwards to a model with its model, tokens, wallet charge or plan quota used, latency and status. Requests refused before any model is called — a 401 for the key, a 402 for funds or for the key's cap or period budget, a 403 from the key's model allowlist, a 429 from the key's or account's own limits, or a 400 or 404 for the model ID or endpoint — leave no record; a streamed request that failed before any output may have none either.
- Key caps and errors: use a dedicated VS Code key with `maxSpend`, a daily/monthly budget or a model allowlist (/llm-api-key-budgets). For 401/402/403 see /invalid-api-key and https://router.one/codex-401-unauthorized; Mainland China access: https://router.one/codex-china and https://router.one/benchmarks/china-latency.

## FAQ

### Can the Codex VS Code extension use a third-party API?

Yes. Add `[model_providers.router]` in `~/.codex/config.toml` (`base_url = "https://api.router.one/v1"`, `wire_api = "responses"`, `env_key = "ROUTER_ONE_API_KEY"`), top-level `model_provider = "router"` and `model = "gpt-6.2-sol"` (if the extension shares the file, OpenAI's Codex models docs suggest `gpt-6.1-sol`), put `ROUTER_ONE_API_KEY` in `~/.codex/.env`, and restart. Native `POST /v1/responses` is required (https://router.one/codex-responses-api).

### Do the Codex VS Code extension, CLI and desktop app share one config file?

Yes. Per OpenAI's Developer settings and Config basics docs (CLI and IDE extension) and its Codex models and Connect to a gateway docs (desktop app), checked 2026-12-06, all three read `~/.codex/config.toml` (`%USERPROFILE%\.codex\config.toml` on Windows), while `chatgpt.*` options stay in VS Code settings.

### What if the Codex VS Code extension keeps asking me to sign in?

Confirm `model_provider = "router"` sits above `[table]` headers and `requires_openai_auth` is off (`rust-v0.174.0`, checked 2026-12-06: `app-server` reports `requires_openai_auth: false`). Put `ROUTER_ONE_API_KEY=sk-your-router-one-key` in `~/.codex/.env`, then restart VS Code completely. Use API Key on the signed-out screen stores an OpenAI Platform key that a provider with `requires_openai_auth` off never sends.

### Why are some Codex features missing when I use an API key?

Per Authentication docs and Feature availability (checked 2026-12-06), API key auth supports local workflows (IDE, CLI, desktop local chats, `/review`, worktrees, `AGENTS.md`, Skills, MCP, subagents), while workspace and cloud features (Codex cloud, Codex web delegation, GitHub PR reviews, Slack/Linear cloud, Voice, Connectors, plugins that need unsupported OAuth) are unavailable or limited.

### How do I add a custom API provider in the Codex / ChatGPT desktop app?

Per Connect to a gateway docs (checked 2026-12-06), open Settings → Model Providers → Add → Gateway or custom provider, enter Name and Base URL (`https://api.router.one/v1`), choose Authentication → Environment variable with `ROUTER_ONE_API_KEY`, turn on Set as current provider if shown, and Save — or edit `~/.codex/config.toml` and restart.

### Does the Codex VS Code extension need a VPN in Mainland China with Router One?

No VPN is needed for model calls to `https://api.router.one/v1` (https://router.one/codex-china, https://router.one/benchmarks/china-latency). Per Connect to a gateway docs (checked 2026-12-06), only model-provider requests use the gateway route; workspace sign-in, MCP servers, plugins and voice can use other paths, and installing the extension from the Marketplace does not go through Router One.

### Can I install the Codex extension in Cursor or Windsurf?

Yes. Per OpenAI's IDE docs (checked 2026-12-06), VS Code, Cursor and Windsurf share `openai.chatgpt` and `~/.codex/config.toml` (Cursor settings: https://router.one/integrations/cursor). Windsurf became Devin Desktop on 2026-06-02 (Devin Desktop FAQ, checked 2026-12-06).

### Can the Codex VS Code extension use DeepSeek or Grok models?

Yes. Router One serves `deepseek-v4.1-flash`, `deepseek-v4-flash` and Grok chat IDs (`grok-4.7`, `grok-4.6`, `grok-4.5`, `grok-4.7-build-fast`) natively on `POST /v1/responses` (Grok since 2026-09-22, per /facts/api-compatibility.md), alongside GPT chat models (`gpt-6.2-sol`). Put the exact /models ID on `model` (see https://router.one/codex-responses-api, /codex-context-window). Claude IDs return HTTP 400 on `/v1/responses`.

## See also

- Codex CLI in China: https://router.one/codex-china
- Codex Responses API: https://router.one/codex-responses-api
- Codex 401 and missing variable fix: https://router.one/codex-401-unauthorized
- Codex context window (258K, 500K, 1M): https://router.one/codex-context-window
- Codex usage limit: https://router.one/codex-usage-limit
- Incorrect API key provided (401/402/403): https://router.one/invalid-api-key
- API key budgets and model allowlist: https://router.one/llm-api-key-budgets
- CLI setup guide: https://router.one/docs/guides/cli-setup
- CC Switch desktop setup: https://router.one/docs/guides/cc-switch
- Cursor integration: https://router.one/integrations/cursor
- OpenAI Codex IDE extension docs: https://learn.chatgpt.com/docs/ide
- OpenAI Codex authentication docs: https://learn.chatgpt.com/docs/auth
- Canonical page: https://router.one/codex-vscode
- Models and per-model token rates: https://router.one/models (markdown: https://router.one/models.md)
- Pricing: https://router.one/pricing
- API docs (markdown): https://router.one/docs.md
- Company facts: https://router.one/facts/company.md
