メインコンテンツへスキップ
更新日: 2026-06-06
Codex CLI is OpenAI’s terminal coding agent for repo edits, code review, large refactors, and command-driven development. For Crazyrouter, the recommended path is the current config.toml custom-provider setup, not the older configuration style.

Overview

With a custom provider in ~/.codex/config.toml, Codex CLI can send its requests to Crazyrouter:
  • recommended protocol: OpenAI-compatible API
  • API style used by Codex: Responses API
  • base URL: https://api.crazyrouter.com/v1
  • auth variable: OPENAI_API_KEY
  • recommended default model: gpt-5.5
If you previously used only the ChatGPT login flow in Codex, switch to the API-key plus custom-provider path for Crazyrouter. It gives you cleaner control over models, logs, quota, and billing.

View the Codex one-click setup repository

If you want a script to write the environment variables and Codex config for you, review the crazyrouter-codex-cli repository.

Best For

  • users who want Crazyrouter in a terminal agent workflow
  • repo-scale edits, reviews, and automated coding tasks
  • teams that want Codex traffic billed separately from Cursor or Claude Code
  • coding-first workflows built around currently verified latest OpenAI models

Protocol Used

Recommended protocol: OpenAI-compatible API Codex CLI currently works best with a custom model_provider configured like this:
  • base_url = "https://api.crazyrouter.com/v1"
  • wire_api = "responses"
Crazyrouter supports /v1/responses, so this Codex CLI integration can use the Responses API directly. But this path should currently be treated as GPT-only guidance because Claude does not support POST /v1/responses.

System Requirements And Prerequisites

Suggested starter allowlist:
  • gpt-5.5

Full Install Paths By OS

On Windows, the simplest path is: Git + Node.js + npm global install for Codex + PowerShell for environment variables and config. Recommended order:
  1. Install Git
  2. Install Node.js LTS
  3. Install Codex CLI with npm
  4. Write OPENAI_API_KEY through PowerShell
  5. Write $HOME/.codex/config.toml through PowerShell
Recommended verification:
If codex --version is still not found, close and reopen PowerShell before retrying. On macOS, the smoothest path is usually: Homebrew + Git + Node.js + brew or npm install for Codex + ~/.zshrc for persistent environment variables. Recommended order:
  1. Install Xcode Command Line Tools
  2. Install Homebrew if needed
  3. Install Git and Node.js
  4. Install Codex CLI
  5. Persist OPENAI_API_KEY in ~/.zshrc
  6. Write ~/.codex/config.toml
Recommended verification:

Alternative Codex install paths

Besides package managers, the official Codex GitHub repository also publishes binary releases. For most users, the recommended defaults are still:
  • Windows: npm install -g @openai/codex
  • macOS: brew install --cask codex or npm install -g @openai/codex
If you prefer a script that writes the Crazyrouter-related settings automatically, see crazyrouter-codex-cli. That repository provides one-click setup scripts for Windows, macOS, and Linux; this guide keeps the full manual path so you can audit each setting.

Full Setup From Scratch

1

Step 1: Install Git

If Git is not installed yet, install it first and add a global identity.
Then run:
2

Step 2: Install Node.js 20+

Codex CLI is a Node.js tool. Make sure Node and npm are ready first.
If your distro installs an older Node version, upgrade before continuing.
3

Step 3: Install Codex CLI

Recommended: use npm global install directly.
4

Step 4: Create a dedicated Crazyrouter token for Codex

In Crazyrouter, create a token named something like codex. For the first pass, allow only:
  • gpt-5.5
This keeps first-pass debugging and cost control much simpler.
5

Step 5: Set the temporary environment variable

Codex reads OPENAI_API_KEY through the provider config. Start with the current terminal only:
6

Step 6: Persist the API key

For regular use, write the API key into your shell profile or user environment variables.
7

Step 7: Write ~/.codex/config.toml

Codex CLI reads ~/.codex/config.toml at startup.
After writing the file, verify it:
8

Step 8: Prepare the Git repo and create a first snapshot

If the current folder is not a repo yet:
If it is already an existing repo, at least inspect the current state first:
9

Step 9: Launch Codex and run the first validation

In the repo, start with a minimal validation first:
After that, start interactive mode:
Recommended validation 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, use the native Claude POST /v1/messages path or OpenAI-compatible POST /v1/chat/completions instead of putting Claude onto the Codex wire_api = "responses" route.

Token Setup Best Practices

Verification Checklist

  • git --version works
  • node -v works
  • codex --version works
  • OPENAI_API_KEY is set correctly
  • ~/.codex/config.toml contains model_provider = "crazyrouter"
  • base_url is https://api.crazyrouter.com/v1
  • wire_api is responses
  • the first request succeeds
  • Crazyrouter logs show the matching request
  • token quota and allowlist match your intended setup

Common Errors And Fixes

Performance And Cost Tips

  • validate first in a small repo, not a huge production repo
  • keep gpt-5.5 as the main driver and get the GPT / Responses baseline working first
  • separate Codex from IDE tools for cleaner cost attribution
  • use stricter quota caps for higher-risk repos or CI jobs
  • when spend spikes, inspect Crazyrouter logs first to see whether agent loops are the cause

FAQ

Which base URL should I use in Codex CLI?

Use https://api.crazyrouter.com/v1.

On Windows, should I use PowerShell or Git Bash?

For first-time setup, prefer the PowerShell path in this guide. It is the easiest way to keep user-level environment variables and $HOME/.codex/config.toml consistent.

Why do I need wire_api = "responses"?

Because Codex CLI’s custom-provider path is designed around the Responses API, and Crazyrouter supports /v1/responses. Because Claude currently supports only POST /v1/messages and POST /v1/chat/completions, not POST /v1/responses. The Codex path here is fixed to wire_api = "responses", so Claude should not be presented as a recommended model for this route.

Why should I make a Git snapshot before the first real task?

Because Codex can edit files and run commands. A clean snapshot makes review and rollback much easier.

If I already used codex login, do I still need an API key?

Yes. For Crazyrouter, you should still use OPENAI_API_KEY plus the custom provider configuration.

Which model should I try first?

Start with gpt-5.5.
If you want the smoothest terminal agent workflow on the OpenAI / Responses API path, configure Codex around the GPT / Responses route. If you want Claude first, switch to Claude Code or the native Claude API docs instead.

View the crazyrouter-codex-cli repository

Review the one-click setup scripts, README, and latest usage notes.