AnRouter

Configure Codex CLI with AnRouter

Install Codex, add AnRouter as a provider, verify the Responses route, and launch with your key.

Codex CLI, IDE extensions, and Codex in the ChatGPT desktop app share the user-level ~/.codex/config.toml. Configure AnRouter as a separate provider. Do not edit auth.json to impersonate the built-in OpenAI login.

1. Install and verify

# macOS / Linux
curl -fsSL https://chatgpt.com/codex/install.sh | sh

# Check
codex --version

Windows PowerShell: irm https://chatgpt.com/codex/install.ps1 | iex

2. Get an AnRouter API key

  • Register at anrouter.com and sign in.
  • Open the dashboard and go to API Keys.
  • Create a key and copy it. Treat it like a password — never commit it to a repository.

3. Verify the Responses route first

curl https://api.anrouter.com/v1/responses \
  -H "Authorization: Bearer $ANROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"glm-5.3","input":"Reply with only: ok"}'

4. Add the user-level configuration

# ~/.codex/config.toml
model = "glm-5.3"
model_provider = "anrouter"

[model_providers.anrouter]
name = "AnRouter"
base_url = "https://api.anrouter.com/v1"
env_key = "ANROUTER_API_KEY"
wire_api = "responses"
The .codex folder and config.toml location in macOS Finder
macOS: open ~/.codex/ in Finder and edit config.toml. On Windows, use %USERPROFILE%\.codex\config.toml. Open the image at full size for detail.
Protocol requirement: responses is the only wire API supported for a Codex custom provider and is also the default when omitted. The selected AnRouter model and channel must work through POST /v1/responses.

5. Available models: DeepSeek, GLM, Qwen, MiniMax and MiMo model IDs

Use the exact ID in model =. These are the nine models AnRouter currently serves.

  • DeepSeek — deepseek-v4.1-flash-1017
  • Z.AI / GLM — glm-5.2 · glm-5.3 · glm-5.3-flash
  • MiniMax — minimax-m3.1-flash
  • Qwen — qwen3.8-27b · qwen3.8-flash-next
  • Xiaomi MiMo — mimo-v2.6-pro · mimo-v2.6-flash

Switching models means changing one line. The provider block stays as it is:

# ~/.codex/config.toml
model = "deepseek-v4.1-flash-1017"
model_provider = "anrouter"

[model_providers.anrouter]
name = "AnRouter"
base_url = "https://api.anrouter.com/v1"
env_key = "ANROUTER_API_KEY"
wire_api = "responses"

A route existing does not mean every model supports that capability. The model, upstream channel, and request fields must all be compatible, so verify tool calls and other features after switching. The model catalog lists context limits and pricing per model.

6. Supply the key and launch

export ANROUTER_API_KEY="your_anrouter_api_key"
codex --model glm-5.3

# Open the desktop app
codex app

The desktop app or IDE extension may not inherit shell variables. Put ANROUTER_API_KEY=… in ~/.codex/.env, fully restart the app, and start a new session.

Do not hand-edit auth.json: auth.json and the built-in openai provider belong to the OpenAI sign-in flow. A separate AnRouter provider is clearer and does not overwrite an existing OpenAI login.

Reference: OpenAI Codex custom model providers