> For the complete documentation index, see [llms.txt](https://docs.console.zenlayer.com/welcome/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.console.zenlayer.com/welcome/ai-gateway/ai-gateway-integration/openai-codex.md).

# OpenAI Codex

Codex is OpenAI’s coding agent that helps you write, review, and ship code faster. Use it side-by-side in your IDE or delegate larger tasks to the cloud.

You can view [**Help Guide**](https://developers.openai.com/codex/ide) for more details.

## Install Codex

You can install Codex using one of the following methods.

**Option 1: Install via Homebrew**

```bash
brew install codex
```

**Option 2: Install via npm**

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

## Configure Codex

Codex reads its settings from a local configuration file written in TOML format.

**Step 1: Open the configuration file**

```bash
vim ~/.codex/config.toml
```

**Step 2: Define the default model and provider**

```toml
# Default model used by Codex
model = "o3"

# Default model provider
model_provider = "openai-chat-completions"
```

**Step 3: Configure the model provider**

```toml
[model_providers.openai-chat-completions]
# Display name shown in the Codex interface
name = "gateway.theturbo"

# Base URL of the OpenAI-compatible API
base_url = "https://gateway.theturbo.ai"

# Environment variable that stores the API key
env_key = "YOUR_AI_GATEWAY_API_KEY"

# API protocol type (optional, defaults to "chat")
wire_api = "chat"
```

## Set the API Key

Set your API key as an environment variable:

```bash
export YOUR_AI_GATEWAY_API_KEY="sk-xxxxxxxxxxxxxx"
```

This key is generated when you create an AI Gateway instance.

## Use Codex

After configuration, you can start using Codex immediately.

**Start an interactive session**

```bash
codex
```

**Send a one-off request**

```bash
codex "Summarize the purpose of this repository."
```

All requests will be forwarded through the AI Gateway, allowing centralized authentication, routing, and usage tracking.

{% hint style="info" %} <mark style="color:blue;">**Notes**</mark>

* <mark style="color:blue;">Codex requires an</mark> <mark style="color:blue;">**OpenAI-compatible API**</mark><mark style="color:blue;">. AI Gateway provides this interface.</mark>
* <mark style="color:blue;">API keys should always be stored as environment variables, not hard-coded in config files.</mark>
* <mark style="color:blue;">You may change the default model or provider at any time without reinstalling Codex.</mark>
  {% endhint %}
