Skip to main content

Codex CLI

Codex CLI is OpenAI's terminal-based coding assistant. It reads its provider configuration from ~/.codex/config.toml, which lets you point it at the Cequence AI Gateway instead of calling the provider directly.

The gateway supports Codex CLI against multiple provider types. Pick the tab that matches your setup.

Setup

Choose the provider the LLM Registry entry uses, and the mode you want to run in.

The gateway stores your OpenAI credential on the LLM Registry entry, so you don't send an API key from your machine — Codex CLI only sends its Agent Access Key.

In ~/.codex/config.toml:

model_provider = "aigw"

[model_providers.aigw]
name = "AI Gateway"
base_url = "https://<gateway-host>/llm/<url-prefix>/v1"
env_key = "OPENAI_API_KEY"

Then:

export OPENAI_API_KEY="<your-agent-access-key>"

Codex CLI sends the Agent Access Key on Authorization: Bearer. The gateway authenticates the call, attaches the stored OpenAI credential on the outbound side, and forwards to OpenAI.

Where to find each value

PlaceholderWhere to find it
<gateway-host>The gateway host from the LLM Registry entry's Overview tab (e.g., gw.aigateway.example.com)
<url-prefix>The URL prefix field on the LLM Registry entry
<persona-id>The persona's ID on the Agent Persona page
<registry-entry-id>The LLM Registry entry's ID on the entry's URL
<your-agent-access-key>Generate on the Agent Access Keys step of the Connect flow; the plaintext is shown once

Tips

  • One key, two uses. In the persona setup, the same Agent Access Key authenticates both the LLM call (Authorization: Bearer) and the MCP tool socket (X-Agent-Key). You don't need to mint two keys.
  • Restart Codex CLI after any config change. Codex CLI reads ~/.codex/config.toml at startup only.
  • Test the endpoint first. If Codex CLI reports a generic authentication error, run a plain curl against the same base_url with your Agent Access Key to confirm the endpoint and key are correct before debugging Codex's config file.