Skip to main content
Content updated: 2026-06-09
Codex CLI is OpenAI’s command-line coding agent tool, suitable for making code changes, reviews, batch refactoring, and command collaboration in local repositories. When integrating with Crazyrouter, it is recommended to use the currently officially supported config.toml custom provider method instead of the old configuration approach.

Overview

By configuring the custom provider with ~/.codex/config.toml, Codex CLI can send requests to Crazyrouter:
  • Recommended protocol: OpenAI-compatible API
  • Interface type used: Responses API
  • Base URL: https://api.crazyrouter.com/v1
  • Authentication variable: OPENAI_API_KEY
  • Recommended default model: gpt-5.5
If you have only used ChatGPT login before, please switch to API Key + custom provider configuration when connecting with Crazyrouter. This makes models, logs, quota, and billing more manageable.

View the Codex one-click configuration repository

If you want to directly write environment variables and Codex configuration with scripts, you can check out the crazyrouter-codex-cli repository.

Who is this for?

  • People who want to connect Crazyrouter to a terminal agent-style coding workflow
  • People who want to perform batch modification, code review, and automation in local repositories
  • People who want to split billing for Codex, Cursor, Claude Code traffic
  • People who want to prioritize using the latest verified OpenAI models for terminal agent coding

Usage Protocol

Recommended protocol: OpenAI-compatible API Codex CLI currently recommends using the OpenAI-compatible provider via custom model_provider, and specifying:
  • base_url = "https://api.crazyrouter.com/v1"
  • wire_api = "responses"
Crazyrouter supports /v1/responses, so Codex CLI can directly use the Responses API in this integration. However, this path only supports GPT models for now; Claude does not support POST /v1/responses.

System Requirements and Prerequisites

Recommended initial whitelist:
  • gpt-5.5

Complete Installation Steps by Operating System

The simplest path for Codex on Windows is: Git + Node.js + Globally install Codex using npm + Configure environment variables in PowerShell. Recommended sequence:
  1. Install Git
  2. Install Node.js LTS
  3. Use npm to install Codex CLI
  4. Use PowerShell to write OPENAI_API_KEY
  5. Use PowerShell to write $HOME/.codex/config.toml
Recommended verification command:
If codex --version reports command not found, close and reopen PowerShell, then try again. On macOS, the most convenient path is usually: Homebrew + Git + Node.js + brew or install Codex CLI via npm + persist environment variables with ~/.zshrc. Recommended sequence:
  1. Install Xcode Command Line Tools
  2. Install Homebrew (if you don’t have it yet)
  3. Install Git, Node.js
  4. Install Codex CLI
  5. Write ~/.zshrc
  6. Write ~/.codex/config.toml
Recommended verification command:

Alternative Codex CLI Installation Paths

In addition to package managers, the official Codex repository also offers GitHub Releases binary packages. For most users, it is still recommended to prioritize:
  • Windows: npm install -g @openai/codex
  • macOS: brew install --cask codex or npm install -g @openai/codex
If you want to use a script to automatically write Crazyrouter-related configurations, you can refer to crazyrouter-codex-cli. This repository provides one-click configuration scripts for Windows, macOS, and Linux; this documentation still retains complete manual configuration steps to make it easier for you to review every setting.

Complete Installation from Scratch

1

Step 1: Install Git

If you do not have Git yet, install Git and complete the global identity configuration.
It is recommended to execute:
2

Step 2: Install Node.js 20+

Codex CLI is a Node.js tool. First, make sure Node and npm are ready.
If the default version installed by your distribution is too old, please upgrade to a later version before proceeding.
3

Step 3: Install Codex CLI

It is recommended to use npm for global installation directly:
4

Step 4: Create a dedicated Codex token in Crazyrouter

In the Crazyrouter backend, create a token named codex, and for the first time only allow:
  • gpt-5.5
This keeps initial troubleshooting simple and better controls costs.
5

Step 5: First, set a temporary environment variable

Codex reads OPENAI_API_KEY from the provider configuration. First set in the current terminal:
6

Step 6: Save the API Key into a persistent environment variable

For daily use, it is recommended to write into your shell configuration file or user environment variables.
7

Step 7: Write the Codex configuration file to ~/.codex/config.toml

When Codex CLI starts, it will read ~/.codex/config.toml.
You can check after configuration:
8

Step 8: Prepare the Git repository and make the first snapshot

If the directory is not yet a Git repository:
If it is already an existing repository, at least check:
9

Step 9: Start Codex and complete the first verification

Once inside the repository directory, you can first perform a minimal verification:
After success, enter interactive mode:
Initial verification is recommended in the following order:
  1. Reply only OK
  2. Read the repository structure only. Do not edit files.
  3. Find the highest-risk file in this repo and explain why, but do not change anything.
If you need Claude, please use native POST /v1/messages or OpenAI-compatible POST /v1/chat/completions; do not configure Claude for this Codex wire_api = "responses" route.

Native Support for Domestic Models

Based on 2026-05-15 production retesting, the domestic models on Crazyrouter that support native POST /v1/responses and can be properly consumed by Codex CLI, are currently only recommended as follows: If you want to try domestic models in Codex, it is recommended to first narrow the token whitelist to:
  • gpt-5.5
  • kimi-k2.5
  • kimi-k2.6
It is not recommended to add MiniMax-M2.7, deepseek-v4-pro, glm-5.1 directly to Codex’s default whitelist unless you clearly accept experimental behavior and stream reconnection attempts.

Switching to Domestic Models

Keep base_url = "https://api.crazyrouter.com/v1" and wire_api = "responses" unchanged, only replace the model field. For example:
When switching to a domestic model for the first time, it’s recommended to still verify in this order:
  1. Reply only OK
  2. Read the repository structure only. Do not edit files.
  3. Read agent.md and reply with exactly the first Markdown heading text.

Token Best Practices

Verification Checklist

  • git --version is working
  • node -v is working
  • codex --version is working
  • OPENAI_API_KEY is correctly set
  • ~/.codex/config.toml is written to model_provider = "crazyrouter"
  • base_url is set as https://api.crazyrouter.com/v1
  • wire_api is set as responses
  • First request returned successfully
  • Crazyrouter backend logs show corresponding request
  • Token quota and model allowlist match expectations

Common Errors and Fixes

Performance and Cost Recommendations

  • Initially verify with a small repository, do not start by running full tasks in a huge repository
  • Main recommendation: gpt-5.5, run the GPT / Responses main path first
  • Separate accounting for Codex and IDE tools to identify sources of high consumption
  • Set stricter token quota for high-risk repositories or CI scenarios
  • On encountering unusually high usage, first check Crazyrouter logs to see if it was caused by multi-turn proxy actions

FAQ

What Base URL should Codex CLI use?

Use https://api.crazyrouter.com/v1. For initial setup, prioritize the PowerShell approach in the documentation, as it easiest keeps user environment variables and $HOME/.codex/config.toml consistent.

Why configure wire_api = "responses" here?

Because Codex CLI’s custom provider is currently recommended to work through the Responses API, which Crazyrouter supports /v1/responses. Because Claude currently only supports POST /v1/messages and POST /v1/chat/completions, not POST /v1/responses. This Codex integration goes through wire_api = "responses" by default, so Claude should not be used as the recommended model for this route. Because Codex, as a proxy, can modify files and run commands. Taking a snapshot first makes review and rollback much easier.

If I have already done codex login, do I still need to set up an API Key?

Yes. When connecting to Crazyrouter, you should still use OPENAI_API_KEY and custom provider settings. Start with gpt-5.5.
If you want the smoothest terminal agent experience using the OpenAI / Responses API, configure Codex as per GPT / Responses. If you want to use Claude first, refer to the Claude Code or Claude native interface documentation.

View the crazyrouter-codex-cli repository

View one-click setup scripts, README, and the latest instructions.