# 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/welcome/ai-gateway/ai-gateway-integration/openai-codex.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
