Codex Manual
Use XAI Router
XAI Router is useful when you want centralized API, account, quota, and model governance for Codex.
~/.codex/config.toml:
model_provider = "xai"
model = "gpt-5.6-sol"
approval_policy = "on-request"
sandbox_mode = "workspace-write"
[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" }Start:
export XAI_API_KEY="sk-Xvs..."
codexPowerShell:
$env:XAI_API_KEY="sk-Xvs..."
codexHTTP, WebSocket, and the routing hint
Current Codex custom providers use wire_api = "responses". The configuration above explicitly uses HTTP. To enable Responses WebSocket, change only:
supports_websockets = truex-codex-routing-hint is an upstream routing hint; it does not replace the request body's model. Codex does not generate this header automatically for a custom provider authenticated with an XAI Router API key, so the configuration supplies a static seed. Before forwarding, the router synchronizes an existing hint with the final mapped model and the current request's service tier. You do not need to edit the seed when switching with codex --model ... or /model.
Continue with the GPT Image 2 Images API guide or see Codex CLI / App API key integration.