40 40
41## Configure the provider41## Configure the provider
42 42
43Open `config.toml` at `~/.codex/config.toml` on macOS or Linux, or43In the interactive CLI, run `/config` and open **Sessions** > **Model providers**.
44Choose **Create a custom provider or gateway** and enter the name, base URL,
45and, if needed, the name of the environment variable holding the API key.
46To change an editable provider, open its details and choose **Edit configuration**.
47If you can change the default, highlight the provider, press <kbd>Space</kbd>, and
48start a chat with `/new`.
49
50To set up a gateway during CLI sign-in, start `codex --enable gateway_setup_wizard`
51and choose **Sign in another way** > **Use a custom provider or gateway**.
52This optional sign-in flow is off by default. It appears in a signed-out CLI
53using the embedded app server when the default provider is OpenAI, API-key
54sign-in is allowed, and no managed setting or launch override selects a provider.
55
56For manual setup or additional authentication settings, open
57`config.toml` at `~/.codex/config.toml` on macOS or Linux, or
44`%USERPROFILE%\.codex\config.toml` on Windows.58`%USERPROFILE%\.codex\config.toml` on Windows.
45 59
46Merge this example into your existing configuration, replacing the URL and model60Merge this example into your existing configuration, replacing the URL and model
80 94
81- **Built-in name:** If the gateway accepts the exact model name bundled with your Codex version and routes it to the matching model, set `model` to that name. Codex already has its metadata.95- **Built-in name:** If the gateway accepts the exact model name bundled with your Codex version and routes it to the matching model, set `model` to that name. Codex already has its metadata.
82- **Catalog endpoint:** If the gateway serves Codex-compatible metadata, use its full catalog URL. This can be a `/v1/models` endpoint that implements the [Codex catalog response](https://learn.chatgpt.com/docs/enterprise/roll-out-a-gateway#implement-the-catalog-endpoint). A response that only lists model IDs is insufficient for custom aliases.96- **Catalog endpoint:** If the gateway serves Codex-compatible metadata, use its full catalog URL. This can be a `/v1/models` endpoint that implements the [Codex catalog response](https://learn.chatgpt.com/docs/enterprise/roll-out-a-gateway#implement-the-catalog-endpoint). A response that only lists model IDs is insufficient for custom aliases.
83- **Catalog file:** If your gateway uses custom aliases and your administrator distributes a file, use the [local models.json example](https://learn.chatgpt.com/docs/enterprise/roll-out-a-gateway#start-with-a-local-modelsjson-file). Use a local file when native gateway OAuth is your only credential and you need custom metadata.97- **Catalog file:** If your gateway uses custom aliases and your administrator distributes a file, use the [local models.json example](https://learn.chatgpt.com/docs/enterprise/roll-out-a-gateway#start-with-a-local-modelsjson-file).
84 98
85For API-key or helper authentication, if your administrator supplies a catalog99If your administrator supplies a catalog URL, add it to the existing
86URL, add it to the existing
87`[model_providers.enterprise-gateway]` table:100`[model_providers.enterprise-gateway]` table:
88 101
89```toml102```toml
90model_catalog_url = "https://gateway.example.com/codex/models.json"103model_catalog_url = "https://gateway.example.com/codex/models.json"
91```104```
92 105
106If gateway OAuth is your only credential, the catalog URL must use the same
107scheme, host, and port as `base_url`. Sign in to the gateway first. Codex uses
108your existing gateway session to fetch the catalog.
109
93Remove any effective `model_catalog_json` setting; it takes precedence over the110Remove any effective `model_catalog_json` setting; it takes precedence over the
94URL. Administrators can find endpoint requirements in111URL. Administrators can find endpoint requirements in
95[remote catalog setup](https://learn.chatgpt.com/docs/enterprise/roll-out-a-gateway#serve-a-remote-catalog).112[remote catalog setup](https://learn.chatgpt.com/docs/enterprise/roll-out-a-gateway#serve-a-remote-catalog).
107 124
108## Choose an authentication method125## Choose an authentication method
109 126
110Use native gateway OAuth for browser sign-in, an API key for a scoped credential, or a credential helper if your organization supplies a command.127Use native gateway OAuth for browser or device-code sign-in, an API key for a scoped credential, or a credential helper if your organization supplies a command.
111 128
112{/* prettier-ignore */}129{/* prettier-ignore */}
113<Tabs130<Tabs
145token_url = "https://login.example.com/oauth/token"162token_url = "https://login.example.com/oauth/token"
146client_id = "YOUR_PUBLIC_CLIENT_ID"163client_id = "YOUR_PUBLIC_CLIENT_ID"
147# redirect_port = 43127164# redirect_port = 43127
165# device_authorization_url = "https://login.example.com/oauth/device"
148```166```
149 167
150Add `scopes` and, if required, `resource` to this table using the values your168Add `scopes` and, if required, `resource` to this table using the values your
172 190
173When OAuth is your only credential, keep `requires_openai_auth = false` and remove the191When OAuth is your only credential, keep `requires_openai_auth = false` and remove the
174previous `env_key`, `experimental_bearer_token`, or `auth` settings used for the192previous `env_key`, `experimental_bearer_token`, or `auth` settings used for the
175gateway credential. Use a [local model catalog](https://learn.chatgpt.com/docs/enterprise/roll-out-a-gateway#start-with-a-local-modelsjson-file) if you need custom model193gateway credential.
176metadata; OAuth alone doesn't enable remote catalog discovery.
177 194
178Restart the desktop app and follow its gateway sign-in prompt to open the browser.195Restart the desktop app and follow its gateway sign-in prompt to open the browser.
179In the CLI, start `codex` and follow the browser sign-in when Codex first accesses196In the CLI, start `codex` and follow its sign-in prompt. Complete your
180the gateway. Complete your organization's sign-in and MFA, then return to the197organization's sign-in and MFA, then return to Codex. If the grant expires or
181client. If the grant expires or Codex can't refresh it, sign in again when prompted.198Codex can't refresh it, sign in again when prompted.
199
200For SSH or a terminal without a browser, set `device_authorization_url` to the
201device authorization endpoint your identity provider supplies. When you need to
202sign in, the interactive CLI shows a verification URL and a one-time code. Open
203the URL in a browser and enter the code. This flow doesn't require port forwarding.
182 204
183Native gateway OAuth requires a browser and a reachable loopback callback. It has205If your provider only supports browser sign-in and the CLI runs over SSH, set
184no device-code fallback. If the CLI runs over SSH, set `redirect_port = 43127` in206`redirect_port = 43127` and register the matching redirect URI. From the machine
185the OAuth table and register the matching redirect URI described above. From the207with your browser, forward the port before starting Codex:
186machine with your browser, forward that port before starting Codex:
187 208
188```shell209```shell
189ssh -L 43127:127.0.0.1:43127 user@remote210ssh -L 43127:127.0.0.1:43127 user@remote
190```211```
191 212
192In that SSH session, start `codex` and open the gateway sign-in URL in your local213In that SSH session, start `codex` and open the gateway sign-in URL in your local
193browser. A CLI inside a container also needs a callback reachable from the214browser. For browser sign-in inside a container, the callback must also be
194browser. If you can't make the callback reachable, use an API key or credential215reachable from the browser. If you can't reach it, use device authorization,
195helper instead.216an API key, or a credential helper.
196 217
197 218
198 219
241 262
242### Use an organization credential helper263### Use an organization credential helper
243 264
244If your administrator provides command-backed authentication, use their installed265If the helper supplies your primary provider credential, use your administrator's
245helper and configuration instead of `env_key`. Don't configure both mechanisms.266installed helper and configuration instead of `env_key`. Don't configure both mechanisms.
246The helper must exist on your machine; Codex doesn't install it. For example,267The helper must exist on your machine; Codex doesn't install it. For example,
247add this table without `env_key`, using the resolver path and268add this table without `env_key`, using the resolver path and
248arguments your administrator supplies:269arguments your administrator supplies:
262 283
263<a id="option-a-reuse-your-credential-command-with-a-helper"></a>284<a id="option-a-reuse-your-credential-command-with-a-helper"></a>
264 285
265With ChatGPT sign-in, run the helper before launching Codex and pass its output through a [custom gateway header](https://learn.chatgpt.com/docs/enterprise/connect-to-a-gateway?gateway-auth=api-key#use-a-custom-authentication-header) instead of configuring the `auth` table. When the key expires, get a new key and relaunch Codex.286If your helper supplies a gateway token alongside ChatGPT sign-in, omit the
287provider's `auth` table and set `requires_openai_auth = true`. Configure a
288gateway credential export command and the header or cookie your gateway accepts:
289
290```toml
291[model_providers.enterprise-gateway.gateway_oauth]
292delivery = { kind = "cookie", name = "gateway_session" }
293
294[model_providers.enterprise-gateway.gateway_oauth.credential_export]
295command = "/usr/local/bin/fetch-codex-gateway-token"
296args = ["print-token"]
297```
298
299The command must print one access token to standard output. Codex runs it on
300first use and caches the token in memory. If the gateway rejects an inference
301request with HTTP 401, Codex runs the command again and retries once.
302When using `credential_export`, omit the OAuth client ID and endpoint settings.
303
304You can also run the helper before starting Codex and pass the token in a
305[custom gateway header](https://learn.chatgpt.com/docs/enterprise/connect-to-a-gateway?gateway-auth=api-key#use-a-custom-authentication-header).
306Renew the token and restart Codex when it expires.
266 307
267Use resolved absolute paths for helper executables and catalog files.308Use resolved absolute paths for helper executables and catalog files.
268 309
283For manual setup, update the existing `[model_providers.enterprise-gateway]` table before signing in:324For manual setup, update the existing `[model_providers.enterprise-gateway]` table before signing in:
284 325
2851. Set `requires_openai_auth = true` and keep `base_url` pointing to your gateway. Remove any `env_key`, `experimental_bearer_token`, and provider `auth` settings so Codex uses your OpenAI credential for primary authentication.3261. Set `requires_openai_auth = true` and keep `base_url` pointing to your gateway. Remove any `env_key`, `experimental_bearer_token`, and provider `auth` settings so Codex uses your OpenAI credential for primary authentication.
2862. Send the gateway credential separately. For [native gateway OAuth](#use-native-gateway-oauth), configure `gateway_oauth.delivery` to use the cookie or custom header your gateway accepts. For an API key or credential helper, use a [custom authentication header](#use-a-custom-authentication-header). Reserve `Authorization` for the OpenAI credential.3272. Send the gateway credential separately. For [native gateway OAuth](https://learn.chatgpt.com/docs/enterprise/connect-to-a-gateway?gateway-auth=oauth#use-native-gateway-oauth) or a [gateway credential export command](https://learn.chatgpt.com/docs/enterprise/connect-to-a-gateway?gateway-auth=helper#use-an-organization-credential-helper), configure `gateway_oauth.delivery` to use the cookie or custom header your gateway accepts. For a static API key, use a [custom authentication header](https://learn.chatgpt.com/docs/enterprise/connect-to-a-gateway?gateway-auth=api-key#use-a-custom-authentication-header). Reserve `Authorization` for the OpenAI credential.
287 328
288Sign in to the ChatGPT workspace your administrator named. Complete the gateway sign-in if prompted, then [verify your connection](#verify-the-connection).329Sign in to the ChatGPT workspace your administrator named. Complete the gateway sign-in if prompted, then [verify your connection](#verify-the-connection).
289 330