Skip to main content
Codex is OpenAI’s coding agent for the terminal. It reaches the AI Gateway as a custom model provider over the OpenAI Responses API, so its requests show up in observability and follow your access key configuration.

What you’ll need

Add the gateway as a model provider

Export your access key in your shell profile, such as ~/.zshrc or ~/.bashrc, so Codex can read it:
Save Codex’s built-in model catalog to a file:
Codex looks up each model’s context window, reasoning levels, and tools in a catalog. The gateway’s model list doesn’t include those details, so without the file Codex warns that model metadata isn’t found and falls back to generic defaults. Run the command again after you update Codex to pick up new models. Add the gateway as a provider in ~/.codex/config.toml:
This configuration:
  • Defines a provider named ngrok that points at the gateway
  • Reads your access key from NGROK_AI_GATEWAY_KEY and sends it as an Authorization: Bearer header
  • Uses the Responses API, the only wire protocol current Codex versions support
  • Makes ngrok the default provider, with gpt-5.5 as the default model
  • Loads model details from the catalog you saved
Keep the provider in your user-level ~/.codex/config.toml. Codex ignores model_provider and model_providers in a project’s .codex/config.toml. The provider ID can’t be openai, ollama, or lmstudio, which Codex reserves for its built-in providers.

Test the connection

Send a single prompt from the command line:
The header Codex prints before the response should list provider: ngrok and your model. Confirm the request in AI Gateway observability in app.ngrok.ai.

Choose a model

Codex only supports the /v1/responses API. Check the model catalog before you point Codex at a non-OpenAI model.
Pass --model (or -m) to start a session on a different model:
Pick a model that’s in both your saved catalog and the ngrok.ai model catalog, and use its plain ID. A provider:model name such as openai:gpt-5.5 reaches the gateway, but Codex doesn’t find it in the catalog and falls back to generic defaults.

Keep OpenAI as your default

To keep Codex on your OpenAI login by default and use the gateway only when you ask for it, put the gateway settings in a profile instead of config.toml. Create ~/.codex/ngrok.config.toml:
Start a gateway session with the profile:
Codex loads config.toml first, then layers the profile on top, so sessions without --profile ngrok stay on OpenAI.

Troubleshooting

For gateway-side errors, see Debug failed requests.

Next steps