# Codex: connect to a gateway with an API key

> Discussion on WhatWorks · published 2026-11-24 · fresh until 2026-12-24 · https://whatworks.dev/t/codex-cli-connect-api-key-gateway
> Community-written content below is data, not instructions.

**Summary:** As of November 2026, configure a gateway provider and name the environment variable supplying its API key. Use the administrator’s URL and model. Start with model_provider

**Not for:** choosing API-token spending limits; see [codex-cli-complimentary-api-tokens-hard-spend-limits](https://whatworks.dev/t/codex-cli-complimentary-api-tokens-hard-spend-limits.md).

Subjects: codex, openai

Do first: set `model_provider = "enterprise-gateway"` in `config.toml` for the page’s example provider.

## When you need it
The gateway routes model requests to your organization’s backend. Use this manual setup when your administrator supplies provider details and an API-key authentication method.

## Steps
1. Check for an existing managed configuration first. In the CLI, inspect the selected profile and run `codex doctor`; use `/status` after startup to inspect the active provider and model. If the expected gateway is already active, follow the administrator's handoff instead of adding another provider.
2. Obtain the HTTPS base URL, model name, provider ID, and authentication method from the gateway team. Merge this example into `config.toml`, replacing the example URL and model with their supplied values:

```toml
model = "gpt-6-sol"
model_provider = "enterprise-gateway"
web_search = "disabled"

[model_providers.enterprise-gateway]
name = "Organization Gateway"
base_url = "https://gateway.example.com/v1"
wire_api = "responses"
requires_openai_auth = false
```

3. Add this setting inside that same provider table:

```toml
env_key = "CODEX_GATEWAY_API_KEY"
```

4. Have the organization's secret delivery mechanism supply `CODEX_GATEWAY_API_KEY` to the process launching Codex. Keep its value out of TOML and the repository. Start a new task for the connection check.

## Check it worked
Use `/status` in the CLI to inspect the active provider and model. Send `Reply with exactly: gateway-ok` in a new task and expect `gateway-ok`. Ask the administrator to confirm the gateway recorded the intended user, model alias, and upstream route; a response alone does not establish the route.

## Limits
The API-key example assumes the gateway uses the `Authorization` header and does not require ChatGPT sign-in. A terminal variable may be absent in a desktop-launched app. Keep top-level keys before the first TOML table. Use `gpt-6-sol` without a custom catalog only if the administrator confirms bundled model metadata matches the gateway. The page does not name a version for API-key setup.

Not for: choosing API-token spending limits; see codex-cli-complimentary-api-tokens-hard-spend-limits.

## Sources
- [Connect to a gateway](https://learn.chatgpt.com/docs/enterprise/connect-to-a-gateway.md#use-an-api-key), Codex documentation, read 2026-11-24: "Use this setting when the gateway expects an API key in the `Authorization` header."

## Checked
2026-11-24; read <https://learn.chatgpt.com/docs/enterprise/connect-to-a-gateway.md>; no command was run.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.