Codex
Codex talks to models through the Responses API. Add a provider that points at NezhaGate in config.toml and code with NezhaGate's GPT models.
Before you start
- Install the Codex CLI, or the Codex extension in VS Code, Cursor or Windsurf, and create an API key in the console.
- Codex only uses the OpenAI Responses API (
/v1/responses), where NezhaGate serves the GPT models. For Claude, Gemini and the other models, use the chat endpoint or a tool such as Claude Code.
Models you can use in Codex:
gpt-5.6-sol · gpt-5.6-terra · gpt-5.6-luna · gpt-5.5 · gpt-6-astra · gpt-6.1-sol · gpt-6-sol · gpt-6-luna
Add a provider in config.toml
Open ~/.codex/config.toml (%USERPROFILE%\.codex\config.toml on Windows), create it if needed, and add:
model = "gpt-6.1-sol" model_provider = "nezhagate" web_search = "disabled" [model_providers.nezhagate] name = "NezhaGate" base_url = "https://nezhagate.com/v1" wire_api = "responses" env_key = "NEZHAGATE_API_KEY"
- Top-level keys such as
modelandmodel_providermust come before the first[...]table, or Codex reads them as part of that table. web_search = "disabled": Codex's built-in web search relies on an OpenAI-hosted tool that is not guaranteed through another provider, so turn it off.- The provider must live in the user-level config.toml:
model_providerin a project's.codex/config.tomlis ignored. The provider id cannot beopenai,ollamaorlmstudio; Codex reserves them.
Set the API key
Codex reads the key from the NEZHAGATE_API_KEY environment variable (the env_key above) and sends it as Authorization: Bearer; no codex login is needed.
export NEZHAGATE_API_KEY=YOUR_API_KEY codex
On macOS / Linux, put the export line in ~/.zshrc or ~/.bashrc so it sticks. On Windows, reopen the terminal or VS Code after setx so the variable is picked up.
Run and test
Run the command below; a reply of gateway-ok means you are connected:
codex exec "Reply with exactly: gateway-ok"
- Type
/statusin Codex to see the current model and provider. - To switch models, start with
codex -m gpt-6.1-solor changemodelin config.toml. Codex's/modelmenu lists its own built-in models only, not NezhaGate's list. - Then ask for something that needs a tool (for example, list the files here) to check that tool calls work too.
The IDE extension
The Codex extension in VS Code, Cursor and Windsurf reads the same config.toml: gear icon in the extension panel → Codex Settings → Open config.toml. Restart the editor after editing, and make sure an editor not launched from a terminal can see the API key variable.
Troubleshooting
NEZHAGATE_API_KEYThe process that launched Codex cannot see the variable: set it in the same terminal before running; restart the IDE or desktop app, and on Windows reopen it after setx.
wire_api = "chat" is no longer supportedAn old config: set wire_api to "responses".
The key is wrong: check that it was copied in full without extra spaces, or whether it was disabled.
base_url is missing /v1. It should be https://nezhagate.com/v1; Codex appends /responses itself.
Codex only uses /v1/responses, where NezhaGate serves the GPT models only. Switch to one of the GPT models listed above.
The stream was cut before it finished, usually by a local proxy or the network. Retry, and check your proxy if it keeps happening.