Codex CLI
Use Codex CLI with AIRouter24
AIRouter24 adaptation
supportedCodex supports custom OpenAI-compatible providers. Use AIRouter24 as the provider name, https://airouter24.com/v1 as the base URL, and AIROUTER24_API_KEY as the env key.
What is Codex CLI?
Codex CLI is OpenAI's open-source local coding agent that runs in your terminal. It supports multiple model providers, including AIRouter24, so you can use AIRouter24's unified API, provider failover, and organizational controls with Codex's agentic coding workflows.
Quick Start
Step 1: Install Codex CLI
Follow the Codex CLI installation instructions to install the CLI on your system.
Step 2: Get Your AIRouter24 API Key
- Sign up or log in at AIRouter24
- Navigate to your API Keys page
- Create a new API key
- Copy your key (starts with
sk-***)
Step 3: Configure Codex for AIRouter24
First, open the Codex configuration file for your operating system. Create the .codex directory and config.toml file if they do not exist.
- macOS:
~/.codex/config.toml - Windows:
%USERPROFILE%\.codex\config.toml(also$HOME\.codex\config.tomlin PowerShell)
Then add the following configuration:
model_provider = "azure"
model_reasoning_effort = "high"
model="~openai/gpt-latest"
[model_providers.airouter24]
name = "AIRouter24"
base_url="https://airouter24.com/v1"
env_key="AIROUTER24_API_KEY"model_provider = "azure"
model_reasoning_effort = "high"
model="~openai/gpt-latest"
[model_providers.airouter24]
name = "AIRouter24"
base_url="https://airouter24.com/v1"
env_key="AIROUTER24_API_KEY"Step 4: Set Your API Key
env_key tells Codex which environment variable to read. Set it persistently for your user account so new terminal sessions can run Codex without exporting it each time. Replace the example value with your own key; do not commit it to your project.
# Add this line to ~/.zshrc
export AIROUTER24_API_KEY="sk-***"
# Load the profile and verify without printing the key
source ~/.zshrc
test -n "$AIROUTER24_API_KEY" && echo "API key loaded"# Save as a persistent user environment variable
[Environment]::SetEnvironmentVariable('AIROUTER24_API_KEY', 'sk-***', 'User')
# Verify after reopening PowerShell
if ($env:AIROUTER24_API_KEY) { 'API key loaded' }Note:
~/.zshrcapplies to zsh terminal sessions, not necessarily apps launched from the macOS Dock. Run Codex in a zsh terminal that has loaded the variable. On Windows, reopen PowerShell after setting the variable; restart VS Code too if you use its terminal. Existing processes will not pick up newly saved user variables.
Step 5: Start Codex
Navigate to your project directory and run:
cd /path/to/your/project
codexYour requests will now be routed through AIRouter24.
Configuration Reference
Core Settings
| Setting | Description | Example |
|---|---|---|
model_provider | Provider to use for model requests | "airouter24" |
model | AIRouter24 model ID | "~openai/gpt-latest" |
model_reasoning_effort | Reasoning effort level for Codex models | "low", "medium", "high", "xhigh", "max" |
show_raw_agent_reasoning | Whether to display reasoning tokens in the UI | true or false |
personality | Agent personality preset | "pragmatic", "helpful", etc. |
AIRouter24 Provider Block
[model_providers.airouter24]
name = "AIRouter24"
base_url = "https://airouter24.com/v1"
env_key = "AIROUTER24_API_KEY"base_url: AIRouter24 API endpoint. Usehttps://airouter24.com/v1for production.env_key: Environment variable name for your API key.
Project Trust Levels
Codex supports per-project trust levels. Add project paths to control what the agent can access:
[projects."/path/to/trusted/project"]
trust_level = "trusted"
[projects."/path/to/untrusted/project"]
trust_level = "untrusted"trusted: Agent has full access (e.g., run commands, edit files).untrusted: Agent has restricted access for safety.
Why Use AIRouter24 with Codex CLI?
Provider Failover
AIRouter24 routes requests across multiple providers. If one provider is unavailable or rate-limited, AIRouter24 can fail over to another, keeping your coding sessions uninterrupted.
Organizational Controls
For teams, AIRouter24 provides centralized budget management. Set spending limits, allocate credits, and prevent unexpected cost overruns across developers using Codex.
Usage Visibility
Track Codex usage in real-time via the AIRouter24 Activity Dashboard. Monitor costs, token usage, and request patterns.
Model Flexibility
Point model at any AIRouter24 slug (e.g. ~openai/gpt-latest, ~anthropic/claude-sonnet-latest) or a pinned version to switch models without changing your Codex installation—just update config.toml.
Troubleshooting
- Auth Errors: Ensure
AIROUTER24_API_KEYis set and valid. Check at airouter24.com/keys. - Model Not Found: Verify the model ID on airouter24.com/models. Use the exact format (e.g.,
~openai/gpt-latest). - Privacy: AIRouter24 does not log your source code prompts unless you opt-in to prompt logging. See our Privacy Policy for details.