Skip to main content
Codex CLI is OpenAI’s terminal coding agent. Bifrost connects it through a named custom provider backed by the OpenAI-compatible Responses API.
Codex CLI sends a session-id header on every request, so a session sticks to the provider and key that served it and keeps hitting the same prompt cache, with nothing to configure. See Session Affinity.

Install Codex CLI

A new virtual key with no provider_configs denies all providers by default. Make sure openai/gpt-5 (or the model you choose) appears in bifrost models list before launching, or the request is rejected.
Bifrost creates an isolated temporary CODEX_HOME for the launched process and declares a bifrost model provider. It copies the user’s config.toml first, preserving MCP servers, project trust entries, reasoning preferences, and other non-auth settings before replacing the model-provider routing. The user’s normal authentication and session history remain isolated, and changes Codex makes inside the temporary home are discarded when the process exits. Enterprise SSO and virtual keys are both supported. With SSO, Codex receives the current Bifrost agent access token only in its child-process environment. The token is not written to the temporary Codex provider configuration.
Codex currently receives one agent access token when the process starts. If a long-running Codex session reaches token expiry, exit and relaunch it through Bifrost so the CLI can refresh the Enterprise session first.

Persist a virtual key for direct Codex launches

This writes the current context’s Bifrost virtual key as experimental_bearer_token on the bifrost provider in $CODEX_HOME/config.toml (default ~/.codex/config.toml). It preserves your OpenAI/ChatGPT login in auth.json. A virtual key is required; Enterprise SSO tokens are not persisted. See Persistent coding-agent configuration.

Configure Codex manually with a virtual key

An existing ChatGPT or OpenAI login does not need /logout. With requires_openai_auth = false, Codex authenticates the bifrost provider with its own key (env_key here, or experimental_bearer_token when written by bifrost configure codex) and leaves the login in auth.json for other providers.
Export the virtual key in the same terminal used to start Codex:
Add a named provider to ~/.codex/config.toml:
The trailing /v1 is required because Codex appends /responses to the custom provider URL. supports_websockets = false keeps the custom provider on HTTP(S) Responses requests, which is required when Bifrost translates the request to a provider that does not implement OpenAI’s stateful Responses WebSocket protocol.
Use a named model_providers entry. Setting only OPENAI_BASE_URL or OPENAI_API_KEY can leave Codex on its built-in OpenAI provider, where OpenAI OAuth and built-in transport behavior can take precedence.

Sign in with ChatGPT through Bifrost

Teams on a ChatGPT workspace can keep Codex signed in with ChatGPT and still send every model request through Bifrost. Codex keeps the ChatGPT token in Authorization, and the Bifrost virtual key travels in x-bf-vk. Bifrost checks the virtual key, drops it, and forwards the request to the ChatGPT Codex backend with the ChatGPT headers unchanged. The ChatGPT seat pays for the tokens. This follows OpenAI’s Sign in with ChatGPT through a gateway guide, using its header option. It works the same way in the Codex CLI and in Codex inside the ChatGPT desktop app, since both read the same Codex configuration. Add the provider to your workspace’s cloud-managed requirements.toml in ChatGPT’s managed configuration, or to ~/.codex/config.toml to try it on one machine:
Export the virtual key in the environment Codex starts from, then sign in with ChatGPT inside Codex:
Bifrost forwards two routes under this base URL: GET /models for the Codex model picker and /responses for each turn. Bifrost refuses every other path and method. With supports_websockets = true, Codex opens one WebSocket to /responses per session and sends each turn over it, so later turns carry only the new input. Bifrost relays that socket to ChatGPT frame by frame and runs every turn through the virtual key’s checks, logging and billing, the same way it does for a turn sent over HTTP. If Bifrost refuses the upgrade, for example because the request carries no ChatGPT token, Codex switches to HTTP for the rest of the session on its own. Set supports_websockets = false to always use HTTP. Bifrost closes a socket that has no response in progress and no traffic for 15 minutes, and Codex opens a new one for its next turn. Each caller can hold up to 32 of these sockets at once.
Model names are the ones your ChatGPT plan offers, such as gpt-5.5, without a provider prefix. Requests go straight to ChatGPT, so Bifrost routing, fallbacks, and non-OpenAI models do not apply on this path. Use the virtual key setup for those.
The virtual key’s governance still applies. Bifrost checks each turn’s model against the key’s allowed models, and budgets and rate limits count the usage ChatGPT reports. The model list Codex fetches for its /model picker is trimmed to the OpenAI models the key allows, so a key limited to gpt-5.5 shows only gpt-5.5. Codex caches that list, so a change to the key’s allowed models reaches the picker on the next refresh. Without a Bifrost credential the list comes back as ChatGPT sent it. The ChatGPT token stands in for a Bifrost provider key, so no OpenAI key is picked for these requests. Provider-key limits, key weights, and the key column in logs do not apply to them. Bifrost forwards only tokens that ChatGPT issued. Any other Authorization value on this route, such as an OpenAI API key or a token from your identity provider, never reaches ChatGPT, and Bifrost sends its stored OpenAI key in its place.
Codex reads BIFROST_VIRTUAL_KEY once at launch and never refreshes it. After you rotate the virtual key, restart Codex. The desktop app needs the variable set on the app process itself.

Sign in with your identity provider (Enterprise)

Bifrost Enterprise also supports the guide’s native gateway OAuth option. Each person signs in to your identity provider from Codex, so requests are attributed to them and their user budgets, rate limits, and access profile apply. No virtual key is needed, and the token expires and refreshes as with any other sign-in. Codex runs the whole sign-in against your identity provider. Bifrost takes no part in it and only validates the token Codex sends afterwards against the SSO provider set up under Governance → User Provisioning.
  1. In your identity provider, register a public client with PKCE and add the loopback redirect http://127.0.0.1:43127/callback. Use the port you set as redirect_port below. On Okta, this is a native app. On Entra, add the redirect to the app registration Bifrost already uses for SSO, as described below. Codex cannot hold a client secret, so identity providers that require one on the token exchange, such as Google, do not work.
  2. Point Codex at that client in requirements.toml, using your identity provider’s authorize and token URLs:
The example uses an Okta custom authorization server. client_id is the public client from step 1. On Okta that is the native app you created for Codex, not the app Bifrost uses for SSO. Include the scopes your SSO login requests, and offline_access where your identity provider needs it to issue refresh tokens, so Codex can refresh instead of sending people back to the browser. Codex sends the identity provider’s access token, not the ID token, so it has to pass the checks of the SSO provider configured in Bifrost. The issuer must match the SSO provider’s issuer URL, and when the SSO provider sets an audience, the token’s aud must equal it. For an Okta custom authorization server that audience is usually api://default. Bifrost then reads the user and their role from that same access token, not from the ID token your dashboard login uses. It looks up an existing user by sub, then by the email claim. It resolves the role from the claims your SSO provider’s role mappings read, and teams from the groups claim. A token with no role claim keeps the user’s current Bifrost role, so a person who already signed in to the dashboard only needs email in the token. A person with no Bifrost role and no role claim in the token gets 403. Identity providers often leave email, groups, and custom attributes out of access tokens by default, so check what yours issues before rolling this out.
Entra issues the access token for whichever API the requested scopes belong to. With only openid, email, and profile, that API is Microsoft Graph, and Bifrost rejects the token because its audience is Graph and its issuer is the v1 sts.windows.net one. Codex has to request a scope that Bifrost’s own app registration defines.In the Microsoft Entra admin center, open App registrations and select the app Bifrost uses for SSO.
  1. Under Expose an API, set the Application ID URI to the default api://<client-id> if it is empty, then select Add a scope. Name it access_as_user, set Who can consent to Admins and users, and save.
  2. Under Manifest, add the loopback redirect as a public client redirect URI and set the access token version to 2 inside the api object, so the token’s issuer is https://login.microsoftonline.com/<tenant-id>/v2.0 and its audience is the client ID. The portal’s Redirect URIs field rejects http loopback addresses, so the manifest is the only place to add it. Entra ignores the port only for localhost, so the port must equal redirect_port:
  3. Under Token configuration, select Add optional claim, choose the Access token type and add email, so Bifrost can match the token to an existing user. Accept the Microsoft Graph permission prompt if one appears. Entra fills email only for users with a mail address.
  4. Optionally, under API permissions, add the delegated access_as_user permission from My APIs and grant admin consent, so users do not see a consent prompt on first sign-in.
Then point Codex at Entra with the scope you created:
The scope names the API by its client ID rather than by api://<client-id>. Codex signs in with the same app it requests the scope from, and Entra issues a token an app requests for itself only when the API is named by its client ID. Because Codex uses Bifrost’s SSO app, the token’s audience already matches and Bifrost’s Entra configuration needs no Audience.
Create an OIDC - OpenID Connect app of type Native Application with the Authorization Code and Refresh Token grant types, add the sign-in redirect URI http://127.0.0.1:43127/callback, and assign it to the same users and groups as your Bifrost SSO app. Okta matches redirect URIs exactly, so the port must equal redirect_port.Use the authorize and token URLs of a custom authorization server, such as default: https://<your-org>.okta.com/oauth2/<server-id>/v1/authorize and /v1/token. Its issuer must be the one set in Bifrost’s Okta configuration, and the token’s audience must match the Audience set in Bifrost, if any. The org authorization server (/oauth2/v1/...) does not work here, because Okta issues its access tokens for Okta’s own APIs and does not support validating them elsewhere.A custom authorization server’s access token carries only sub, uid, cid, and scp by default. Claims you added to the SSO app’s ID token do not carry over. Under Security → API → Authorization Servers, open the server, go to Claims, and add these with Include in token type set to Access Token:Set groups to the Groups value type. With Expression, Okta evaluates .* as an expression that yields nothing and leaves the claim out of the token without any error.The email claim matters even when roles come from somewhere else. On a custom authorization server, sub is the user’s login, such as jane@example.com, while a user created by dashboard SSO is stored under the Okta user ID from the ID token. The sub lookup misses, and only email links the Codex sign-in to that user.Check the result on the server’s Token Preview tab. Pick the Codex client, a user, the Authorization Code grant, and the scopes from requirements.toml. On the token tab, not id_token, confirm that iss, aud, email, groups, and your role claim have the values Bifrost expects. If the preview reports no matching policy, add a rule under the server’s Access Policies that covers the Codex client with the Authorization Code and Refresh Token grants.
Codex then sends two credentials on every request. The ChatGPT token stays in Authorization and reaches ChatGPT unchanged; Bifrost forwards it only when ChatGPT issued it. The identity provider token travels in the auth-openid cookie. Bifrost validates it, attributes the request to that user, and removes the cookie before forwarding. When inference authentication is enforced, a missing or invalid cookie returns 401. The cookie name must be auth-openid.
This option needs a Codex build with native gateway OAuth, a browser, and a reachable loopback port. It covers model requests only, not MCP, plugins, or voice.

Select a model

Pass the complete Bifrost model identifier when starting the session:
Or, when starting Codex directly from a manually configured shell:
Codex’s in-session /model picker uses Codex’s model catalog, not Bifrost’s /v1/models response. Provider-qualified Bifrost models may not appear there, and entering an arbitrary value after /model can leave the previous model active. Use /status to verify the model. For a model outside the picker, exit and relaunch with bifrost run codex --model provider/model.
The Bifrost launcher currently validates gateway connectivity and discovers the permitted models, but it does not generate a Codex model-catalog file.

Non-OpenAI models

Bifrost can translate Codex’s Responses API requests to other configured providers. The target model must support the tool calls Codex needs for file operations, shell commands, and edits. Provider support for streaming, reasoning items, parallel tools, images, and compaction can also differ.
The current automated Codex cloud harness exercises the OpenAI provider path. Treat other provider/model combinations as compatibility targets to validate with your selected model before production rollout.
A quick isolation sequence is:
Inside Codex, run /status before sending the first task. If Bifrost’s error payload reports a different original_model_requested, Codex did not switch to the intended model.

Troubleshooting

The request still uses gpt-5

The in-session model change did not take effect. Relaunch with the desired model on the command line and verify it with /status.

The request is routed to the wrong provider key

Bifrost routes on the model Codex actually sends. Inspect original_model_requested in the error response or the Bifrost logs. Fixing a provider-key error will not change Codex’s active model.

401 Unauthorized

When using Bifrost CLI, run:
When configuring Codex manually, confirm that model_provider = "bifrost", requires_openai_auth = false, and OPENAI_API_KEY contains a Bifrost virtual key. When you sign in with your identity provider, a 401 means Bifrost rejected the auth-openid token. Its issuer or audience does not match the SSO provider configured in Bifrost. On Okta, the usual cause is authorize and token URLs that point at the org authorization server (/oauth2/v1/...) instead of a custom one.

403 Access denied: no application role or group mapping

Bifrost validated the identity provider token but found no role for the user. The access token has no claim that your role mappings read, and no existing Bifrost user with a role matched its sub or email. Add email and your role or group claims to the access token, as described for your identity provider, then restart Codex and sign in again so it gets a new token.

Sign-in fails with an offline_access or policy error

The identity provider refused the scopes Codex requested. On Okta, give the Codex app the Refresh Token grant, and make sure the authorization server has an access policy rule for that client that allows the Authorization Code and Refresh Token grants.

Next steps