> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mixroute.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Codex

## 1. Introduction

This document is designed to guide users in successfully connecting **Codex CLI** to **Mixroute**. Codex CLI is a command-line AI-assisted coding tool that runs in your terminal. By modifying the configuration files under its official configuration directory `~/.codex`, you can establish a stable and easily manageable multi-model access environment.

## 2. Prerequisites

Before configuring, please ensure you have completed the following preparations:

1. **Install Codex CLI**: Ensure that the tool package is installed globally in your development environment.
2. **Obtain Mixroute Credentials (API Key)**:
   * Visit the official Mixroute console and register or log into your account.
   * Navigate to the API key management page, generate, and copy your exclusive **API Key** (usually starting with `sk-`).
3. **Verify Network Connectivity**: Ensure your development device's current network environment can access Mixroute's service address: `https://api.mixroute.ai`.

## 3. Configuration Phase

The core configuration for Codex CLI is located in the `.codex` folder within your user directory. The configuration primarily involves two files: `config.toml` (handles interface and model parameters) and `auth.json` (handles secure key storage).

### 3.1 Locate or Create the Configuration Directory

**Windows Users:** Press `Win+R` on your keyboard, type `%userprofile%\.codex`, and hit Enter.

**MacOS / Linux Users:** Enter `~/.codex` in your terminal or access it via your file manager.

*Important Note: If you are installing Codex CLI for the first time, this directory or the files within it may not exist. Please create the directory and the two files mentioned below manually.*

### 3.2 Configure Config.toml

Create or edit the `.codex/config.toml` file, copy and save the following Mixroute configuration:

```toml theme={null}
# Set the global default provider to mixroute
model_provider = "mixroute"
# Set the default model (fill in according to models supported by Mixroute, e.g., gpt-5.4-mini, claude-sonnet-5, etc.)
model = "openai/gpt-5.4-mini"
model_reasoning_effort = "high"
disable_response_storage = true
model_verbosity = "high"

[model_providers.mixroute]
name = "mixroute API Gateway"
base_url = "https://api.mixroute.ai/v1"
# Use the compatible chat interface
wire_api = "chat"
# It is recommended to disable mandatory sk- verification for third-party gateways
requires_openai_auth = false
```

> **Note:**
>
> 1. `base_url` must end with `/v1` and should not have a trailing slash.
> 2. It is recommended to keep `wire_api` as `"chat"` because most third-party proxy gateways implement `/chat/completions`. If you encounter a 404 error, you can try changing it to `"responses"` depending on the platform's specific compatibility.

### 3.3 Configure auth.json

Create or edit the `.codex/auth.json` file. For security, do not write your API Key directly in the TOML file; instead, store it in this JSON file:

```json theme={null}
{
  "OPENAI_API_KEY": "sk-yourMixrouteKeyxxxxxxxxxxxx"
}
```

Please replace `"sk-yourMixrouteKeyxxxxxxxxxxxx"` with your actual Mixroute API Key obtained during the preparation phase.

## 4. Verification and Testing

After completing the configuration, invoke Codex CLI in your terminal to test the conversation:

```bash theme={null}
codex
```

When the interactive interface appears in the terminal, try entering a simple test prompt (e.g., "Hello, please write a Python hello world script").

* If Codex responds normally, it indicates that the connection to Mixroute is successful.
* If you encounter an error (such as unauthorized or connection failure), please carefully check if the key format in `auth.json` is correct (including double quotes) and if the `base_url` in `config.toml` is accurately set to `https://api.mixroute.ai/v1`.
