> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://www.respan.ai/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://www.respan.ai/docs/_mcp/server.

# Codex CLI (gateway)

> Set up Codex CLI 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://api.respan.ai/api/responses`, so only your `RESPAN_API_KEY` is needed.

## Setup

#### Install Codex CLI

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

#### 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.

#### Configure Codex

Add to `~/.codex/config.toml` (user-level) or `.codex/config.toml` (project-level):

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

[model_providers.respan]
name = "Respan Gateway"
base_url = "https://api.respan.ai/api/"
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.

#### Run Codex

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

All LLM calls now route through Respan.

## 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).

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