---
title: "Codex CLI (gateway)"
description: "Set up Codex, in the terminal or the ChatGPT desktop app, with the Respan gateway."
---

Route Codex CLI's LLM calls through the Respan gateway for automatic logging, caching, and model switching. Codex uses the OpenAI Responses API, which the gateway serves at `https://gateway.respan.ai/responses`, so only your `RESPAN_API_KEY` is needed.

Paste this into your coding agent:

```text
Help me set up the Respan gateway with the Codex CLI integration.
Follow https://www.respan.ai/docs/integrations/gateway/codex-cli.md
```

## Setup

<Tabs>
<Tab title={"Desktop app"}>

Codex in the ChatGPT desktop app reads the same `~/.codex/config.toml` as the CLI (`%USERPROFILE%\.codex\config.toml` on Windows).

<Steps>
<Step title="Make your key visible to the app">

On macOS, put the export in your shell profile (`~/.zshrc`). An export typed into one terminal window does not reach the app.

```bash
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
```

On Windows, save the key as a user environment variable:

```powershell
setx RESPAN_API_KEY "YOUR_RESPAN_API_KEY"
```

</Step>

<Step title="Point Codex at the Respan gateway">

Add to `~/.codex/config.toml`:

```toml
model = "gpt-5.5"
model_provider = "respan"

[model_providers.respan]
name = "Respan Gateway"
base_url = "https://gateway.respan.ai"
wire_api = "responses"
env_key = "RESPAN_API_KEY"
```

`env_key` is the name of the environment variable, not the key itself.

</Step>

<Step title="Restart the app">

Quit and reopen the ChatGPT desktop app. New Codex chats now route through Respan.

</Step>
</Steps>

<Accordion title="The app cannot find the key">

Have Codex read the key with a command instead of an environment variable. On macOS, store it in Keychain:

```bash
security add-generic-password -a "$USER" -s respan-api-key -w "YOUR_RESPAN_API_KEY"
```

Then replace the `env_key` line with an `auth` block:

```toml
[model_providers.respan]
name = "Respan Gateway"
base_url = "https://gateway.respan.ai"
wire_api = "responses"

[model_providers.respan.auth]
command = "security"
args = ["find-generic-password", "-s", "respan-api-key", "-w"]
```

With an `auth` block, Codex logs `failed to refresh available models` when it starts. The message is harmless: requests still go through the gateway.

</Accordion>

</Tab>
<Tab title={"CLI"}>

<Steps>
<Step title="Install Codex CLI">

```bash
npm install -g @openai/codex
```

</Step>

<Step title="Set environment variable">

```bash
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
```

No `OPENAI_API_KEY` is needed in your shell. The Respan gateway handles provider authentication.

</Step>

<Step title="Configure Codex">

Add to `~/.codex/config.toml`. Codex ignores provider settings in a project-level `.codex/config.toml`.

```toml
model = "gpt-5.5"
model_provider = "respan"

[model_providers.respan]
name = "Respan Gateway"
base_url = "https://gateway.respan.ai"
wire_api = "responses"
env_key = "RESPAN_API_KEY"
```

<Note>
`env_key` is the **name of the environment variable** that holds your API key, not the actual key. Current Codex CLI requires `wire_api = "responses"`; `wire_api = "chat"` is rejected by Codex itself. Both `model = "gpt-5.5"` and the provider-prefixed `model = "openai/gpt-5.5"` work.
</Note>

</Step>

<Step title="Run Codex">

```bash
codex "your prompt"
```

All LLM calls now route through Respan.

</Step>
</Steps>

</Tab>
</Tabs>

## Switch models

Change the `model` parameter in `~/.codex/config.toml` to use any OpenAI model the gateway exposes.

```toml
model = "gpt-5.5"
# model = "gpt-5-mini"
# model = "gpt-5.3-codex"
```

<Note>
The gateway's Responses API route serves OpenAI models only. Claude and Gemini models are available on the Chat Completions route, which Codex does not use. To run those models from a terminal agent, see [OpenCode](/docs/integrations/gateway/open-code), [pi](/docs/gateway/pi), or [Kilo Code](/docs/gateway/kilo-code).
</Note>

See the [full model list](https://platform.respan.ai/platform/models).
