Codex
Codex is OpenAI's coding agent for the terminal. This guide routes its requests through the Zuplo AI Gateway.
Two approaches:
- Use a provider key. The gateway calls OpenAI with the API key saved on your provider. OpenAI bills that key's account.
- Use your ChatGPT subscription. Codex stays signed in with
codex login. The gateway forwards that login to OpenAI and meters usage against an app. Your ChatGPT plan pays for the tokens.
Prerequisites
Create an OpenAI provider in the AI Gateway, then get a gateway URL and key in one of two ways:
- Use your personal API key (recommended). Codex runs on your own machine, so call the project's User App. Open the My Keys tab of your AI Gateway project, copy the Gateway URL, and create a key under My API keys. Your requests count against your own budget.
- Use an app. For a shared or automated setup, and for the ChatGPT subscription approach, create a pool and an app for Codex, then copy the app's API URL and API Key.
The rest of this guide calls these your gateway URL and gateway key.
Configure Codex
Replace the provider name
The examples assume your provider is named openai. Replace that prefix with
the name of your provider before copying anything. A provider named
my-openai routes my-openai/gpt-6.1-sol. The model part must be an ID that
provider serves. Check your provider's page in the
Portal.
Codex reads configuration from ~/.codex/config.toml. Create this file (and the
~/.codex directory if needed) if it does not exist. Add the block for your
approach, then set the API key in your environment and restart Codex:
Code
Use a provider key
This example uses the User App's gateway URL. For an app, use the app's API URL instead.
Code
base_urlis your gateway URL with/v1appended.modelisproviderName/model.
Use your ChatGPT subscription
This approach is shown with an app. On the User App, turning on passthrough would change authentication for everyone who uses it, so use an app for subscription logins.
Code
requires_openai_auth = truemakes Codex send your ChatGPT login in theAuthorizationheader. Do not setenv_key.env_http_headerssends the app's API key in thezp-gateway-api-keyheader, which is where the passthrough policy reads it.modelmust be a model your ChatGPT plan can use in Codex, with your provider name as the prefix.
Run codex login if you are not signed in. The gateway never sends your ChatGPT
login anywhere except OpenAI, and never sends your app key to OpenAI.
Configure the API Key Authentication policy
On the pool's policy template, or on the app's Policies tab, edit API Key Authentication in the JSON editor:
Code
authScheme must be the empty string, not left blank. A blank field keeps the
Bearer default and every request fails with
401 Invalid Authorization Scheme.
The provider still needs an API key saved. Passthrough requests never use it; Fallback Model targets do. A placeholder value works if nothing else uses it.
Rules
model_provider = "zuplo"is required. Without it, Codex uses its built-inopenaiprovider and bypasses the gateway.wire_apimust beresponses. Codex speaks only the Responses API; it removed support for/v1/chat/completions, andwire_api = "chat"fails to load.- Put this configuration in the user-level file. Codex ignores
model_providerandmodel_providersin a project-level.codex/config.toml. - Do not use
openai_base_urlto point Codex at the gateway. That keeps Codex's built-in transport, which the gateway does not support.
Switch models
Set model in config.toml, or pass it on the command line:
Code
Do not use the /model picker. It sends model names without the provider
prefix, and the gateway rejects them with a 400.
Codex warns that it has no metadata for a prefixed model name. Requests still succeed.
The Model Filtering policy on the User App or the app controls which models you can use.
Verify
Code
The session header shows provider: zuplo. With a personal key, the request
appears in your usage on the My Keys tab; with an app, it appears in the
app's usage in the Zuplo Portal.
Troubleshooting
| Error | Fix |
|---|---|
400 The request body model must use "providerName/model" | Add the provider prefix to model. Do not use the /model picker. |
403 This User App route requires a personal API key issued for this User App | With a personal key: the key is missing, wrong, from another project, or not sent as Authorization: Bearer. Create a key on My Keys and use the Gateway URL from the same project. |
ERROR: Missing environment variable: ZUPLO_AI_GATEWAY_API_KEY | Export the variable in the shell that runs Codex. |
401 Authorization Failed | With an app: the key is wrong. Copy it from the app's API Key tab. |
401 Header configured by options.authHeader is missing | Subscription approach: add the env_http_headers line and export ZUPLO_AI_GATEWAY_API_KEY. |
401 Invalid Authorization Scheme | Set authScheme to the empty string in the policy JSON. |
401 rejected the credential this app passed through from the caller (HTTP 401) | Your ChatGPT login expired or is invalid. Run codex login again. |
401 Missing scopes: api.responses.write | The app is not in passthrough mode. Configure the API Key Authentication policy as above. |
Errors mention api.openai.com or not supported when using Codex with a ChatGPT account | Codex is not using your provider. Set model_provider = "zuplo". |