Codex CLI / App (API Key Integration)

Powering Codex CLI / App with XAI Router
Current Codex custom providers use the responses wire protocol. Once ~/.codex/config.toml and XAI_API_KEY are configured, Codex App can reuse the same connection settings.
Prerequisites
- Codex CLI installed
- Your XAI API Key received by email
- Linux/macOS config path:
~/.codex/config.toml - Windows config path:
%USERPROFILE%\.codex\config.toml
Note: After signing up and logging in at m.xairouter.com, open Account Recharge to view available monthly plan options and pricing.
Recommended Configuration (HTTP)
# ~/.codex/config.toml
model_provider = "xai"
model = "gpt-5.6-sol"
approval_policy = "never"
sandbox_mode = "danger-full-access"
[model_providers.xai]
name = "xai"
base_url = "https://api.xairouter.com"
wire_api = "responses"
requires_openai_auth = false
env_key = "XAI_API_KEY"
supports_websockets = false
http_headers = { "x-codex-routing-hint" = "model=gpt-5.6-sol" }export XAI_API_KEY="sk-Xvs..."
codex --yoloOptional: Enable WebSocket
The default supports_websockets = false uses HTTP. To use Responses WebSocket instead, change only:
supports_websockets = truex-codex-routing-hint only supplies upstream routing information; it does not select the request model. A static header is needed because Codex does not generate it automatically for a custom API-key provider. Before forwarding, the router synchronizes it with the final mapped model and the current request's service tier, so switching with --model or /model does not require a config edit.
Windows Launch Examples
:: Config file path
:: %USERPROFILE%\.codex\config.toml
set XAI_API_KEY=sk-Xvs...
codex# Config file path
# $env:USERPROFILE\.codex\config.toml
$env:XAI_API_KEY="sk-Xvs..."
codexVerify Commands
codex: start an interactive sessioncodex exec "Reply with one sentence confirming the connection works": verify a non-interactive request
Related Resources
- OpenAI Codex: Learn about Codex CLI / App
- Codex CLI GitHub Repository: Source code and releases
- Official Account Integration Guide: Full guide for official-account mode