Skip to main content
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://crazyrouter.com/v1
  • auth variable: OPENAI_API_KEY
  • recommended default model: gpt-5.4
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.

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://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

ItemNotes
Crazyrouter accountCreate one at crazyrouter.com
Crazyrouter tokenCreate a dedicated sk-... token for Codex
Gitgit 2.23+ is recommended
Node.jsNode.js 20+ is recommended
Codex CLIUse a current stable version
Allowed modelsAllow at least one coding-friendly model such as gpt-5.4
Suggested starter allowlist:
  • gpt-5.4

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:
git --version
node -v
npm -v
codex --version
where.exe git
where.exe node
where.exe codex
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:
git --version
node -v
npm -v
codex --version
which git
which node
which codex

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

Full Setup From Scratch

1

Step 1: Install Git

If Git is not installed yet, install it first and add a global identity.
winget install --id Git.Git -e --source winget
git --version
Then run:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
2

Step 2: Install Node.js 20+

Codex CLI is a Node.js tool. Make sure Node and npm are ready first.
winget install OpenJS.NodeJS.LTS
node -v
npm -v
If your distro installs an older Node version, upgrade before continuing.
3

Step 3: Install Codex CLI

Recommended: use npm global install directly.
npm install -g @openai/codex
codex --version
where.exe codex
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.4
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:
export OPENAI_API_KEY=sk-xxx
echo $OPENAI_API_KEY
6

Step 6: Persist the API key

For regular use, write the API key into your shell profile or user environment variables.
echo 'export OPENAI_API_KEY=sk-xxx' >> ~/.bashrc
source ~/.bashrc
7

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

Codex CLI reads ~/.codex/config.toml at startup.
mkdir -p ~/.codex
cat > ~/.codex/config.toml <<'EOF'
model = "gpt-5.4"
model_provider = "crazyrouter"

[model_providers.crazyrouter]
name = "Crazyrouter"
base_url = "https://crazyrouter.com/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"

[profiles.crazyrouter]
model = "gpt-5.4"
model_provider = "crazyrouter"
approval_policy = "on-request"
sandbox_mode = "workspace-write"
EOF
After writing the file, verify it:
cat ~/.codex/config.toml
8

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

If the current folder is not a repo yet:
git init
git add .
git commit -m "chore: initial snapshot before Codex"
If it is already an existing repo, at least inspect the current state first:
git status
9

Step 9: Launch Codex and run the first validation

In the repo, start with a minimal validation first:
cd /path/to/your/project
codex --profile crazyrouter "Reply only OK"
After that, start interactive mode:
codex --profile crazyrouter
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.
Use caseRecommended modelWhy
default coding drivergpt-5.4verified successfully in production on March 23, 2026, and best suited for the main Codex / Responses API baseline
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

SettingRecommendationNotes
dedicated tokenRequiredDo not share a Codex token with Cursor or Claude Code
model allowlistStrongly recommendedKeep only the models Codex actually needs
IP restrictionRecommended on fixed-egress environmentsBe careful on devices that change networks often
quota capStrongly recommendedAgent-style execution can consume budget quickly
environment splitRecommendedUse separate tokens for local machines, remote hosts, and CI
leak responseRotate immediatelyShell history, config backups, or screen shares can expose tokens

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://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

SymptomLikely causeFix
codex: command not foundCLI did not install cleanly, or the global npm bin directory is not on PATHreinstall Codex and ensure the global npm bin path is on PATH
401 unauthorizedwrong, expired, or badly pasted OPENAI_API_KEYcreate a new token and reset the variable
403 or model not allowedthe token does not allow the selected modelallow the required model in Crazyrouter
404base_url is wrong or missing /v1change it to https://crazyrouter.com/v1
request-shape errorswire_api is not responsesset wire_api = "responses"
Codex launches but does not use Crazyroutermodel_provider is not switched to crazyrouterre-check config.toml
Git changes are hard to reviewno clean repo snapshot before AI editscommit a first snapshot before real edits
cost grows too quicklylong context, repeated tool use, or one token shared across repossplit tokens, cap quota, and keep the model allowlist small

Performance And Cost Tips

  • validate first in a small repo, not a huge production repo
  • keep gpt-5.4 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://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.4.
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.