OpenAI Codex CLI with a LiteLLM gateway

Route Codex CLI and the Codex surface in ChatGPT Desktop through a self-hosted LiteLLM gateway so model access, spend and logs are governed per developer and team.

On this page

How Codex CLI connects to a LiteLLM gateway

An engineering leader who wants Codex usage governed by virtual keys, budgets and request logs, in infrastructure the organization controls, does not need a special Codex plugin on the gateway side. Codex CLI is pointed at LiteLLM through a custom model provider defined in ~/.codex/config.toml. The provider's base_url points at the proxy's /v1 path, and wire_api is set to responses, because Codex speaks the OpenAI Responses API. LiteLLM serves that API at /v1/responses, so the integration is configuration on each developer machine plus a running proxy, with no client-side plugin to install or maintain.

That simplicity shifts the governance work to the gateway. Each developer's key is read from an environment variable named in the provider block, so the key itself stays out of the config file, while the proxy decides which models that key can reach and what it may spend. Confirm with your own LiteLLM version that the Responses endpoint behaves as the Codex documentation describes, since the endpoint's behavior is the part most likely to change between releases. Also confirm which model names your gateway exposes, because Codex will request models by the names the proxy publishes.

This section explains the pieces of that configuration: the custom provider block, the wire_api setting, the /v1/responses endpoint and why the key belongs in an environment variable. The sections that follow cover the exact config.toml keys, virtual key setup and budgets, model discovery, and how the MCP gateway is declared in the same file. Treat the setup as something to test on one developer machine before a wider rollout, and record the Codex CLI and LiteLLM versions you validated so later upgrades can be checked against them.

What you need before changing any developer config

Codex CLI and ChatGPT Desktop should only point at a gateway you have already proven works. The cards below cover the proxy, its database and cache, its secrets, its version and the network path from developer machines, in the order you should confirm them.

PostgreSQL as the database

Virtual keys, budgets and spend records all need a PostgreSQL database, and it is the primary database LiteLLM supports for production. Codex developers will hit the same keys and budgets as every other client, so confirm the database is provisioned, backed up and reachable from every proxy instance before you issue a single key. Ask your DBA how point-in-time recovery will be tested.

Production guide

Redis 7.0 or newer

Once more than one proxy instance runs, shared rate limits, router state and cache need Redis, and the production guide requires version 7.0 or newer. Without it, a TPM or RPM limit applied to a developer's key can be enforced differently on each replica. Decide whether Redis is managed or self-run, and who patches it.

Master key in a secret manager

The LITELLM_MASTER_KEY must start with sk- and grants administrative control over the proxy, including issuing virtual keys. Store it in your secret manager, never in a shared config file or a developer's shell profile, and limit who can read it. The keys developers receive through Codex are separate from this master key, so confirm your team understands the difference.

A supported LiteLLM minor version

LiteLLM supports the four most recent stable minor versions for open source and Enterprise deployments. Pick a release from the current window, pin it in your deployment, and record it, because the Codex CLI integration depends on the proxy serving the Responses API correctly. Check the release list before you deploy, since newer releases can move the window.

Supported minor versions
4
LiteLLM releases

TLS and reachability from developer machines

Every developer laptop must reach the proxy over HTTPS with a certificate your devices trust, including any internal certificate authority your company uses. Test the path from a managed laptop on the office network, on VPN and off VPN, since a gateway that only resolves inside the data center will break remote work. Document the base URL that developers will receive.

Confirmed Codex CLI and ChatGPT Desktop versions

Confirm the exact Codex CLI and ChatGPT Desktop versions your developers run against the LiteLLM Codex CLI documentation before rollout. Record those versions next to the LiteLLM release you pinned, and repeat the check whenever either client updates. Treat an unlisted version as untested until your own pilot passes.

Codex CLI setup docs

Configuring the custom provider in config.toml

This sequence takes a team from a running LiteLLM proxy to a Codex CLI session that sends Responses API traffic through a key-limited, budgeted gateway. Each step ends with a check that confirms the gateway, key and client work together before wider rollout.

  1. Deploy the proxy and confirm its health

    The platform team deploys the LiteLLM proxy in infrastructure the organization controls, with PostgreSQL as the database because virtual keys require it, and a master key stored in a secret manager. Keep the master key out of developer machines and out of Codex configuration. Confirm the proxy answers its health endpoint and that the admin UI loads from an internal address before any key is issued. Ask your deployment partner or team to confirm the exact health and admin paths for the release line you run, since these depend on the version you install.

  2. Register the approved models in the proxy

    Add the model entries that Codex users are allowed to call to the proxy configuration, mapping each public model name to the upstream provider route it uses. Keep the list short and reviewed, because every name listed here becomes a choice inside Codex. Send one test request to each model directly against the proxy with the master key. A successful completion for each entry confirms that the upstream credentials and routes are correct before any developer depends on them.

  3. Create a virtual key scoped to approved models

    Using the admin UI or the key management API, create a virtual key for the developer or team. Restrict it to the approved model names, set a budget, and set TPM and RPM limits that match the team's expected use. The budget and limits are set per key, per user or per team, so choose the scope that matches how your organization charges and reports spend. Record the key's ID in your inventory. The key is done when it appears in the admin UI with the model list, budget and limits you specified.

  4. Store the key in an environment variable

    Place the virtual key in an environment variable on the developer's machine, such as one set from the shell profile or a managed secret store, and make sure the variable is not written into config.toml or committed to a repository. Codex reads the key from the variable named in its provider block, so the file can be shared or versioned without exposing the credential. Verify by opening a new shell and printing the variable's length, not its value, to confirm it is set. Keep master keys and virtual keys in separate variables.

  5. Add the custom model provider block

    Edit ~/.codex/config.toml to define a custom model provider whose base_url points at the proxy's /v1 path and whose wire_api is set to responses, because Codex uses the OpenAI Responses API that LiteLLM serves at /v1/responses. Set the environment variable key in the provider block to the name you chose in the previous step. Then set the top-level model and model_provider keys so Codex selects this provider by default. Check the Codex CLI documentation from LiteLLM for the exact key names your Codex version expects, because the schema can change between Codex releases.

  6. Select the model and run a Responses API test

    Start Codex in a test repository and choose one of the approved models, or set it in config.toml. Send a short prompt that requires no file changes. A normal streamed reply confirms that Codex reached /v1/responses through the gateway, authenticated with the virtual key, and received an answer from the upstream provider. If the request fails, check the proxy logs for the request path and the key's error before changing the Codex configuration.

  7. Confirm limits and spend in the proxy

    Attempt a request for a model that is not on the key's allowed list and confirm the proxy rejects it with an authorization error, which proves the model restriction is enforced at the gateway rather than in Codex. Then open the key's usage view in the admin UI and confirm the test request appears with its token count and spend. These two checks establish that access control and cost tracking both depend on the gateway, so the developer's configuration cannot bypass them.

How requests, keys and model discovery flow through the gateway

Codex sends every model call to the endpoint named in the custom provider block of ~/.codex/config.toml. With wire_api set to responses, Codex posts to the Responses API path, and LiteLLM serves that path at /v1/responses, so the proxy receives the request in the format Codex already speaks. The first thing to confirm in your environment is that the base_url points at the proxy's /v1 prefix and that a request to the responses path succeeds from a developer workstation before any other settings are tested. Route choice happens inside LiteLLM, not in Codex: Codex asks for a model name, and the gateway maps that name to a deployment in its model list and applies the routing strategy you configured. The LiteLLM Codex CLI docs are the reference for the exact provider block.

The virtual key decides who the request belongs to and what it may reach. Codex reads the key from an environment variable that the provider block names, so the key stays out of the config file that developers may share or commit. A virtual key can be restricted to specific models, and its budgets and TPM or RPM limits are checked before the request reaches an upstream provider. If a developer requests a model their key does not allow, the rejection happens at the gateway, which is the control you want to test. Plan one key per developer or per team, record which environment variable each team uses, and confirm that rotating a key does not require editing shared configuration.

The same config.toml can carry MCP server settings and model discovery, so one file governs the developer's Codex setup. Whether Codex lists models from the gateway, and how it registers MCP servers that point back through LiteLLM, depends on the Codex CLI release installed. Confirm both behaviors against the current Codex CLI release and the LiteLLM Codex docs before you write a rollout guide, and test with a key that has a narrow model allowlist so you can see exactly which models appear. Record the Codex CLI version alongside the LiteLLM version, because both sides of this request path change independently.

Codex requests pass through one company-controlled gateway before any provider

The developer runs Codex CLI or the Codex surface in ChatGPT Desktop, which reads the virtual key from an environment variable and sends Responses API calls to the LiteLLM proxy's /v1 endpoint. Inside the company-controlled boundary, the proxy checks the key, applies budgets and limits, and uses PostgreSQL for key and spend records and Redis when more than one proxy instance runs. The router then picks an approved upstream provider. Check that the key never leaves the developer machine except to the proxy, and that provider credentials stay only on the gateway side.

Codex traffic crosses one company-controlled LiteLLM gateway before reaching any approved provider.

Mapping keys, teams and models to developers

The first decision is who owns a virtual key. A key per developer gives you a spend and audit record for each person, which makes per-person budgets and offboarding simple: you revoke one key and the access stops. A shared team key is fewer objects to manage, but every Codex session under it looks identical in the logs, and a leaked key exposes the whole team's budget. Most teams that want individual accountability use per-developer keys and attach them to a team, so that team-level budgets and model lists still apply.

  • Per-developer keys: one key per engineer, tied to a user record, which keeps spend and request history attributable.
  • Team keys: one key shared by a group, suitable only where individual attribution is not required and the blast radius is accepted.
  • Service keys: separate keys for CI jobs or automation, kept apart from laptop keys so they can be rotated independently.
  • Key lifecycle: confirm how keys are created, rotated, expired and revoked in the version you run, and who holds that permission.
  • Naming: agree a convention that maps each key to a person or team so audit questions can be answered quickly.

Before rollout, check the key model against your offboarding process and the number of keys your team expects to manage.

Which LiteLLM objects map to which Codex settings

This table matches each Codex CLI setting to the LiteLLM object it depends on, and names the owner who sets and reviews it. Read it as a checklist when you divide responsibilities between the platform team, the security team and the developers who run Codex.

Object or settingWhat it controlsOwner
model_provider and base_url in config.tomlPoints Codex at the proxy's /v1 path so requests reach LiteLLMPlatform engineering
wire_api set to responsesMakes Codex send OpenAI Responses API calls, which LiteLLM serves at /v1/responsesPlatform engineering
Environment variable holding the virtual keySupplies the caller's key to Codex at runtime without writing it into config.tomlDeveloper, provisioned by platform team
Virtual key identity and ownerTies each request to one person, team or service account for attributionIdentity or platform admin
Per-key budget and rate limitsCaps spend, TPM and RPM for the key, with temporary increases where you allow themTeam lead, approved by finance or platform
Team and user budget fieldsSet shared ceilings that apply across every key in a team or to one userTeam lead and finance
Model allowlist on the keyRestricts which models Codex can request through that keySecurity or platform team
Model discovery and model names in configLists the models developers can select, and must match names the proxy exposesPlatform engineering
MCP gateway entries in config.tomlRoute Codex tool calls to MCP servers registered behind LiteLLMPlatform engineering with security review
Per-request log fieldsRecord key, user, team, model, tokens and spend for each call, with retention set by the operatorSecurity and compliance, with platform team for retention

Controls to set before rolling Codex out to developers

Codex CLI sends every developer prompt and file excerpt through the gateway, so the gateway's keys, model access, limits and admin surface decide what the rollout exposes. Set these controls before the first developer config is distributed, then test each one against a non-production virtual key.

Keep the master key out of dotfiles

The master key (LITELLM_MASTER_KEY, which must start with sk-) grants administrative control over the proxy, so it should live in a secret manager and never in a developer's ~/.codex/config.toml or a repository. Developers only need their own virtual key, read from an environment variable. Check that no shell history, sample config or CI log contains the master key, and rotate it if one does.

Production guide

Scope virtual keys to approved models

A virtual key can be restricted to specific models, so a key issued for Codex should only reach the models your security team has approved for code work. Confirm that the key cannot call a model outside that list, including models a developer might add to a custom config. Test this by requesting a blocked model with the key and confirming the gateway rejects it.

Set request and token limits

Per-key RPM and TPM limits cap how fast a single developer or agent loop can call the gateway, which matters because Codex runs multi-step tasks that can issue many requests quickly. Agree the limits with the platform team using observed usage from a pilot group, and record who approved them. Revisit the limits when a team changes its workflow.

Limit network exposure of the proxy

Decide whether the proxy is reachable only from the corporate network or VPN, or from developer laptops on any network. Developers working remotely need a route to the gateway, so plan that path explicitly rather than opening the port. Confirm TLS termination, the allowed source ranges and whether IP allowlisting is available in your edition.

Restrict admin UI and API access

The admin UI and management endpoints should be reachable only by platform administrators, with SSO for their sign-in. Keep developer keys from being able to create keys, change budgets or read other teams' spend. Test this by signing in as a standard developer and attempting an admin action.

Enable audit logging on Enterprise

Audit logs that record who changed a key, budget or model setting are an Enterprise feature, so confirm the edition before promising them to your security team. On open source, state in your rollout plan what change history you will keep instead. Review who can read request logs, since prompts and code can contain sensitive data.

Enterprise docs

Why Codex requests fail behind LiteLLM

This table pairs each common failure when Codex CLI or the Codex surface in ChatGPT Desktop calls a LiteLLM gateway with its likely cause and fix. Work down the rows in order, since the configuration and endpoint problems are the cheapest to check and often explain the rest. Confirm each fix against your own proxy logs and config before changing anything else.

Symptom to checkLikely causeFix
Requests go to the wrong placebase_url in ~/.codex/config.toml points at the proxy root instead of its /v1 pathSet base_url to the proxy address ending in /v1, since Codex calls /v1/responses on the gateway
Responses format errors or wrong endpointwire_api is missing or set to a value other than responses in the custom model provider blockSet wire_api to responses so Codex uses the Responses API that LiteLLM serves
Authentication rejectedThe virtual key is missing, misspelled, or expired, or the environment variable Codex reads is not exported in that shellConfirm the variable named in config.toml is set in the session that starts Codex, then issue or renew the key in LiteLLM
Model request refused for this keyThe requested model is not in the key's allowed model listAdd the model to the key's permitted models or switch Codex to a model the key already allows
Requests stop after a period of useThe key, user or team budget is exhausted, or the budget reset has not occurredReview spend for the key in LiteLLM, then apply a temporary budget increase or wait for the reset as your policy allows
Intermittent failures with several proxy replicasRedis is not configured, so rate limits and router state are not shared between instancesDeploy Redis 7.0 or newer and point all replicas at it before scaling beyond one proxy instance
ChatGPT Desktop behaves differently from the CLIThe desktop app does not read the same config.toml, so it uses its own provider settingsConfirm the desktop Codex surface reads the gateway settings you intend, and test it with the same key and model as the CLI

Questions buyers ask before connecting Codex to LiteLLM

Can a developer connect Codex to LiteLLM alone?

A developer can edit ~/.codex/config.toml on one laptop alone, once a LiteLLM proxy already exists and they hold a virtual key. The configuration itself is small: a custom model provider whose base URL points at the proxy's /v1 path and whose wire API is set to responses, because Codex uses the OpenAI Responses API that LiteLLM serves at /v1/responses. The harder part is the gateway behind it. Standing up the proxy with PostgreSQL, and Redis once more than one instance runs, along with key issuance, budgets, identity and rollout to other developers, is platform work that usually needs an owner. Confirm the exact configuration keys against the LiteLLM Codex CLI guide for the version you run.

What drives the effort and cost of this integration?

Most of the effort sits in the gateway, not in the Codex file. The main drivers are:

  • Proxy deployment: hosting, database and Redis setup, secret handling for the master key, and the upgrade path.
  • Identity: whether developers use virtual keys distributed by an admin or sign in through SSO, which affects Enterprise licensing needs.
  • Fleet rollout: how many laptops need the same config, and how keys are issued, rotated and revoked.
  • Testing: verifying model discovery, the MCP gateway entries, budgets and logging with real developer workflows.

Costs are one-time for setup and recurring for infrastructure, licenses and support. Ask any quote to separate these items and to state which parts assume open-source LiteLLM and which assume Enterprise.

How long does the integration take?

The duration depends on your environment, and no fixed figure applies to every organization. Timing depends on whether a LiteLLM proxy already runs in your infrastructure, how many identity and secret manager connections you need, how many developers will be onboarded, and how much testing your security and platform teams require. A single developer trial can be short once the gateway works. A governed rollout across a fleet takes longer because it needs key lifecycle rules and review. Ask for a timeline that lists each dependency and who approves it, and confirm the release you plan to run against the LiteLLM releases page.

What must our team provide before the work starts?

Your team provides the infrastructure and accounts the gateway depends on:

  • A PostgreSQL database, the primary supported database, which virtual keys require.
  • Redis 7.0 or newer once more than one proxy instance runs, for shared rate limits and router state.
  • A secret manager to hold LITELLM_MASTER_KEY, which must start with sk-.
  • Model provider accounts and API access for each approved provider.
  • Network paths from developer machines to the proxy, and a decision on whether the proxy is reachable only on internal networks.
  • An identity provider if you want SSO sign-in.

Confirm sizing for each component with your own platform team and with LiteLLM's production guidance before procurement.

Is the Codex integration configuration only, or does it require code changes?

The Codex integration is configuration only on the developer side. No application code changes are needed: Codex reads a custom provider from config.toml and sends its requests to the gateway. The work that is not configuration includes the proxy's model list, provider routes, key limits and the MCP gateway entries if you use them. Those are gateway settings that need review, not changes to Codex itself. Check that the Codex surface in ChatGPT Desktop reads the same file and behaves the same way in your tested version before you promise parity to users.

Who should own virtual keys and budgets for Codex users?

A platform or security owner should own key issuance, budgets and model restrictions, and team leads should own the spend decisions within their limits. LiteLLM supports per-key, per-user and per-team budgets, TPM and RPM limits, temporary budget increases and restricting keys to specific models, according to the LiteLLM virtual keys documentation. Decide before rollout who can grant a temporary increase, how keys are rotated when someone leaves, and where spend reports go. Ask your integrator to document these roles in the scope.

What are the main risks if the gateway is misconfigured?

The main risks are developers bypassing the gateway with direct provider keys, overly broad keys reaching models you did not approve, and logs that miss traffic. A shared master key stored in a developer's config file would also expose spend and model access. Mitigate these by keeping the master key in a secret manager, issuing per-developer virtual keys, restricting models per key and testing that logs appear for every Codex session. Confirm your policy on prompt logging with your compliance team before enabling it.

How DeployOpen scopes and delivers the Codex gateway setup

DeployOpen plans and delivers OpenAI Codex CLI and the Codex surface in ChatGPT Desktop against a self-hosted LiteLLM gateway inside your own infrastructure. The work covers the proxy, the Responses API endpoint, virtual keys, model discovery and the MCP gateway configuration, handed over with documentation your engineers can run.

How we scope

  • Written scope agreed before work starts, listing which developer groups, machines and Codex entry points are included
  • Inventory of approved model providers and private models the gateway will expose to Codex users
  • Decisions on virtual key issuance, budget ownership and whether SSO sign-in is in or out of scope
  • Confirmation of the LiteLLM edition, database and Redis layout, and the network path from developer laptops to the proxy

How we build

  • Deploy the LiteLLM proxy in your environment with PostgreSQL and, when more than one instance runs, Redis
  • Configure the custom model provider in the Codex config file with the /v1 base URL and the responses wire API
  • Load virtual keys from an environment variable and test that Codex calls succeed against the approved models only
  • Wire model discovery and MCP gateway entries into the same configuration and test them with real Codex sessions

How we hand over

  • Written configuration guide for developer machines, including a managed template and steps for rotating keys
  • Runbook covering budget limits, model restrictions, logging locations and what to collect when a Codex request fails
  • Test record showing which checks passed, which were out of scope and which settings you must confirm yourself
  • Walkthrough with your platform and security teams so they can review the setup and operate it without us

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after handover
  • Upgrade planning when the LiteLLM release line or the Codex CLI version changes behavior your setup depends on
  • Retesting of the gateway configuration after changes to providers, keys or identity settings
  • Quotes follow from the written scope, so changes to scope are priced against the agreed document

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.