# Codex

[Codex](https://learn.chatgpt.com/docs/codex/cli) is OpenAI's official AI coding agent. It includes Codex CLI (terminal), IDE extensions (VS Code, Cursor, and more), and the ChatGPT desktop app. Codex uses only the **OpenAI Responses** API format, which BeeRoute supports natively.

## 1. Get an API Key

1. Open the [API Keys](https://beeroute.ai/keys) page and click **Create API Key**.
2. Set **Group** to `CodeX`, save, and copy the key (it starts with `sk-`).

?> The `CodeX` group is dedicated to Codex. It has lower prices, includes models such as `gpt-6.2-sol`, and can only be used in the Codex client.

## 2. Install Codex CLI

Choose any one of the following methods:

| Method | Command |
| :--- | :--- |
| npm | `npm install -g @openai/codex` |
| Homebrew (macOS) | `brew install --cask codex` |
| Official install script (macOS / Linux) | `curl -fsSL https://chatgpt.com/codex/install.sh \| sh` |
| Official install script (Windows PowerShell) | `powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 \| iex"` |

Verify the installation:

```bash
codex --version
```

## 3. Configure BeeRoute

### Step 1: Edit config.toml

Edit the configuration file (create it if it does not exist):

- macOS / Linux: `~/.codex/config.toml`
- Windows: `%USERPROFILE%\.codex\config.toml`

```toml
model_provider = "beeroute"
model = "gpt-6.2-sol"
model_reasoning_effort = "high"

[model_providers.beeroute]
name = "BeeRoute"
base_url = "https://beeroute.ai/v1"
wire_api = "responses"
requires_openai_auth = true
```

| Setting | Description |
| :--- | :--- |
| `model_provider` | Uses the `beeroute` provider defined below |
| `model` | Default model. `gpt-6.2-sol` is recommended for the `CodeX` group |
| `model_reasoning_effort` | Reasoning effort, such as `low`, `medium`, `high`, or `xhigh`. Higher values mean deeper thinking and longer response times |
| `base_url` | Must include `/v1`; Codex appends `/responses` automatically |
| `wire_api` | Must be `"responses"` (newer versions of Codex no longer support `"chat"`) |
| `requires_openai_auth` | Authenticates with the API key you log in with in the next step |

!> Top-level settings such as `model_provider` and `model` must be placed before the first `[...]` table header, otherwise they do not take effect.

### Step 2: Log In with Your API Key

**macOS / Linux:**

```bash
export OPENAI_API_KEY="sk-xxx"
printenv OPENAI_API_KEY | codex login --with-api-key
```

**Windows PowerShell:**

```powershell
$env:OPENAI_API_KEY = "sk-xxx"
$env:OPENAI_API_KEY | codex login --with-api-key
```

The login is saved in `~/.codex/auth.json` or the system credential store, so you do not need to log in again.

?> You can also create `~/.codex/auth.json` directly with the content `{"OPENAI_API_KEY": "sk-xxx"}`. This is exactly what the BeeRoute one-click scripts write: on Windows, [download win_codex_setup.bat](https://beeroute.ai/static/cli/win_codex_setup.bat); on macOS / Linux, run `bash <(curl -fsSL https://beeroute.ai/static/cli/linux_codex_setup.sh)`. After running a script, check that `model` in `config.toml` is a model available in the `CodeX` group.

## 4. Launch and Verify

```bash
cd /path/to/your-project
codex
```

After it starts, enter `/status` and confirm that the provider is `beeroute` and the model is the one you configured. Then send a message to test.

- Switch models: enter `/model` in Codex, or specify a model at startup with `codex -m gpt-6.2-sol`.
- Override a setting temporarily: `codex -c model_reasoning_effort="medium"`.

## 5. IDE Extensions and ChatGPT Desktop App

The Codex IDE extensions share the same configuration as the CLI (`~/.codex/config.toml`), so they work as soon as you complete the configuration above:

- **IDE extensions**: install **Codex** from the VS Code / Cursor extension marketplace. If a login page appears, choose **Use API Key** and enter your BeeRoute key. To open the configuration file directly, click the gear icon in the upper-right corner of the extension and choose **Codex Settings > Open config.toml**.
- **ChatGPT desktop app**: also reads `~/.codex/config.toml`. On the signed-out page, choose **Sign in another way** and enter your BeeRoute key. Restart the desktop app after changing the configuration.

## 6. Configuration with Environment Variables Only (Optional)

If you only use Codex CLI in the terminal, you can skip the login and have Codex read the key from an environment variable instead:

```toml
model_provider = "beeroute"
model = "gpt-6.2-sol"

[model_providers.beeroute]
name = "BeeRoute"
base_url = "https://beeroute.ai/v1"
wire_api = "responses"
env_key = "BEEROUTE_API_KEY"
```

Then add `export BEEROUTE_API_KEY="sk-xxx"` to your shell configuration file (such as `~/.zshrc` or `~/.bashrc`). Note: IDEs and the ChatGPT desktop app launched from a desktop icon usually cannot read environment variables set in the terminal. In that case, use the login method above.

## 7. FAQ

**Getting the error `wire_api = "chat" is no longer supported`?**

Change `wire_api` in `config.toml` to `"responses"`.

**Getting a 401 error?**

The key is wrong or you are not logged in. Run `codex login --with-api-key` from Step 2 again, or check the key in `~/.codex/auth.json`.

**Getting a 403 error?**

Make sure the key belongs to the `CodeX` group.

**Model not found, or no available channel?**

Make sure `model` is a model in the `CodeX` group (such as `gpt-6.2-sol`). Model IDs are case-sensitive.

**Previous sessions disappeared after switching configurations?**

Codex groups session history by login method. After you switch, old sessions are only hidden, not deleted. Switch back to the original login method to see them again.

For more settings, see the official Codex documentation: [Configuration reference](https://learn.chatgpt.com/docs/config-file/config-reference).
