Login
Back to Blog
EnglishTutorial

Crazyrouter Codex CLI: Use Codex with One API Key and an OpenAI-Compatible Gateway

Set up OpenAI Codex CLI through Crazyrouter with one command on Windows, macOS, and Linux. Use an OpenAI-compatible base URL, one API key, and model routing for GPT, Claude, Gemini, DeepSeek, and Qwen-style workflows.

C
Crazyrouter Team
June 4, 2026 / 319 views
Share:
Crazyrouter Codex CLI: Use Codex with One API Key and an OpenAI-Compatible Gateway

Crazyrouter Codex CLI: Use Codex with One API Key and an OpenAI-Compatible Gateway#

OpenAI Codex CLI is useful when you want an AI coding agent directly inside your terminal. The painful part is not the idea — it is the setup: API keys, base URLs, model names, Windows environment variables, macOS shell profiles, Linux config files, and different providers for different models.

The new crazyrouter-codex-cli repo solves one specific problem:

connect Codex CLI to Crazyrouter with one API key and an OpenAI-compatible API endpoint.

Repository:

text
https://github.com/xujfcn/crazyrouter-codex-cli

What this repo does#

The repo provides simple install scripts for:

  • Windows PowerShell
  • Windows batch file
  • macOS
  • Linux

It configures Codex CLI to use:

bash
OPENAI_BASE_URL=https://cn.crazyrouter.com/v1
OPENAI_API_KEY=your-crazyrouter-key

That means Codex CLI can talk to Crazyrouter through an OpenAI-compatible interface, while Crazyrouter handles the model/provider side.

Important rule:

Do not add UTM parameters to API endpoints. UTM belongs on human-clickable website links, not OPENAI_BASE_URL.

Correct:

bash
export OPENAI_BASE_URL=https://cn.crazyrouter.com/v1

Wrong:

bash
export OPENAI_BASE_URL=https://cn.crazyrouter.com/v1?utm_source=...

Why use Codex CLI through Crazyrouter?#

A terminal coding agent is most useful when it can become part of your normal development loop:

  1. open a project directory;
  2. ask the agent to inspect code;
  3. let it patch files;
  4. run tests;
  5. review the diff;
  6. repeat.

But real developer teams often want more than one model. Some tasks need a fast low-cost model. Some need a stronger reasoning model. Some need Claude-style code review. Some need Gemini-style long-context analysis. Some teams also need a more stable route from regions where direct access is unreliable.

Crazyrouter gives Codex CLI a single OpenAI-compatible gateway:

  • one API key;
  • one base URL;
  • multiple model choices;
  • OpenAI-compatible client configuration;
  • easier switching between coding models.

One-command install#

Windows PowerShell#

Open PowerShell as a normal user and run:

powershell
iwr -UseB https://raw.githubusercontent.com/xujfcn/crazyrouter-codex-cli/main/install-crazyrouter-codex.ps1 | iex

Or download and run:

text
install-crazyrouter-codex.bat

macOS / Linux#

bash
curl -fsSL https://raw.githubusercontent.com/xujfcn/crazyrouter-codex-cli/main/install-crazyrouter-codex.sh | bash

The script asks for your Crazyrouter API key, writes the needed environment variables, and backs up existing Codex configuration when needed.

Manual setup#

If you prefer to configure it yourself, install Codex CLI first:

bash
npm install -g @openai/codex

Node.js 22+ is recommended.

Then set the environment variables.

macOS / Linux#

bash
export OPENAI_API_KEY=sk-your-crazyrouter-key
export OPENAI_BASE_URL=https://cn.crazyrouter.com/v1

Windows PowerShell#

powershell
setx OPENAI_API_KEY "sk-your-crazyrouter-key"
setx OPENAI_BASE_URL "https://cn.crazyrouter.com/v1"

After setx, reopen your terminal.

Then start Codex:

bash
codex

Codex config.toml example#

Some Codex CLI versions support provider configuration in:

  • Windows: %USERPROFILE%\.codex\config.toml
  • macOS / Linux: ~/.codex/config.toml

Example:

toml
model = "gpt-5.5"
model_provider = "crazyrouter"

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

[model_providers.crazyrouter.query_params]

If you see this error:

text
wire_api = "chat" is no longer supported

change:

toml
wire_api = "chat"

to:

toml
wire_api = "responses"

Model selection#

Once the gateway is configured, you can start Codex with the default model or specify one explicitly:

bash
codex
codex --model gpt-5.5
codex --model gpt-4o-mini
codex --model claude-sonnet-4-6

Model availability can vary by account, provider route, and current upstream status. Check the current model list here:

Crazyrouter model list

Practical workflow example#

A simple Codex CLI coding loop:

bash
cd your-project
codex

Then ask:

text
Inspect this repo and explain the architecture. Do not edit files yet.

After the summary:

text
Find the smallest safe fix for the failing login test. Make the change, then run the relevant test only.

Then review:

bash
git diff
npm test -- login

The gateway setup does not replace careful review. It makes the model/provider configuration less annoying so you can focus on the actual engineering loop.

Troubleshooting#

codex: command not found#

Install Codex globally:

bash
npm install -g @openai/codex

Then check:

bash
which codex
codex --help

On Windows, reopen the terminal after installation.

API key not found#

Check whether the environment variable exists.

macOS / Linux:

bash
echo $OPENAI_API_KEY

Windows PowerShell:

powershell
$env:OPENAI_API_KEY

If empty, set it again.

Wrong base URL#

The base URL should be exactly:

text
https://cn.crazyrouter.com/v1

Do not add /chat/completions, /responses, or UTM parameters. Client libraries append the final API path themselves.

Existing Codex config conflict#

If you had another provider configured before, check:

bash
cat ~/.codex/config.toml

Make sure the selected model_provider points to the Crazyrouter provider block.

When this setup is useful#

This repo is especially useful for developers who:

  • use Codex CLI but want an OpenAI-compatible gateway;
  • want to try multiple models from one CLI setup;
  • work across Windows, macOS, and Linux machines;
  • need a repeatable install script for teammates;
  • want a simpler path for AI coding workflows in regions where direct provider access can be unstable.

Bottom line#

crazyrouter-codex-cli is a small repo, but it removes a common setup tax: configuring Codex CLI to use an OpenAI-compatible gateway correctly.

If you want Codex CLI with one key, one base URL, and easier model routing, start here:

text
https://github.com/xujfcn/crazyrouter-codex-cli

Implementation Guides

Related Posts

Claude API Key: Complete Setup, Security, and Troubleshooting GuideTutorial

Claude API Key: Complete Setup, Security, and Troubleshooting Guide

One wrong header format can turn every Claude request into a 401 “Invalid API key” error in seconds. Most teams assume **claude api key** issues start at the model layer, but the real breakpoints u...

Mar 18
GPT Agent Mode Complete Guide: Autonomous AI Tasks in 2026Tutorial

GPT Agent Mode Complete Guide: Autonomous AI Tasks in 2026

"Learn how GPT Agent Mode works, how to use it via API, and how it compares to standard chat completions for autonomous task execution."

Feb 27
Sora API: The Complete Guide to Building with OpenAI Video GenerationTutorial

Sora API: The Complete Guide to Building with OpenAI Video Generation

OpenAI's current Sora API is asynchronous and tier-based, not a fire-and-forget video button. The official guide recommends polling every 10 to 20 seconds, and Sora access is not available on the F...

Mar 26
Build a World Cup Odds Movement Monitor with Claude Code and claude-fable-5Tutorial

Build a World Cup Odds Movement Monitor with Claude Code and claude-fable-5

A second Claude Code project in the World Cup analytics series: build an odds movement monitor, compute implied probability shifts, and use claude-fable-5 through Crazyrouter to generate validated JSON analysis without betting advice.

Jun 13
How to Get a Claude API Key in 2026: Secure Setup, Rotation, and AlternativesTutorial

How to Get a Claude API Key in 2026: Secure Setup, Rotation, and Alternatives

how to get claude api key: practical 2026 developer guide with comparisons, code examples, pricing breakdown, FAQ, and Crazyrouter API routing tips.

Jun 18
Can Claude Code Build a World Cup 2026 Match Predictor? A Real Crazyrouter API TestTutorial

Can Claude Code Build a World Cup 2026 Match Predictor? A Real Crazyrouter API Test

We built a reproducible World Cup 2026 match predictor demo with Claude Code-style workflow, Elo/Poisson probabilities, charts, and real Crazyrouter API calls through https://cn.crazyrouter.com/v1.

Jun 12