Introduction
Codex CLI is an open-source terminal programming agent from OpenAI that can read and write files, run commands, fix bugs, and complete entire coding tasks directly from the command line. By integrating ByteRouter, you can freely use multiple models including GPT and Claude in Codex CLI, while enjoying more flexible and cost-effective billing.Prerequisites
Before getting started, ensure you have:- Node.js Installed Download and install from Node.js official website (recommended LTS version v20 or higher) for npm-based installation of Codex CLI
- ByteRouter API Key Sign in to ByteRouter Console to get your API key
Tip: If you don’t have a ByteRouter account yet, register at ByteRouter first.
Step 1: Install Codex CLI
Choose one of the following installation methods:- npm (Recommended)
- Homebrew (macOS)
Install globally via npm, works on all operating systems:
If you encounter permission issues, prepend
sudo (macOS / Linux).Verify Installation
After installation, run the following command to confirm success:Step 2: Configure ByteRouter API
Codex CLI manages model providers through configuration files in the~/.codex/ directory. We simply need to add a custom provider pointing to ByteRouter.
2.1 Find the Configuration Directory
- macOS / Linux:
~/.codex/ - Windows:
C:\Users\<username>\.codex\
If the directory doesn’t exist, run
codex once in your terminal and press Ctrl + C to exit. The directory will be created automatically.2.2 Configure API Key
Create or edit theauth.json file in the configuration directory with your ByteRouter key:
2.3 Configure Model Provider
Create or edit theconfig.toml file in the configuration directory and add the ByteRouter provider:
After saving both files, restart Codex CLI for changes to take effect.
Step 3: Get Started
Verify Configuration
In any project directory, run the following command to verify your configuration:401, 403 errors, refer to the troubleshooting section below.
Interactive Mode
Runcodex directly to enter the interactive interface, ideal for handling complete coding tasks:
Approval Mode
On first run, Codex will let you choose the approval level for operations:
We recommend starting with Auto mode. Type
/approvals in the interactive interface to adjust anytime.
Switch Models
Type/model command in the interactive interface to quickly switch models, or modify the model field in config.toml and restart.
Supported Models
For Codex CLI, we recommend the following GPT-5 series models:Common Commands
Here are frequently used commands and shortcuts in Codex CLI:Troubleshooting
Q1: Login screen appears after startup?
If a login prompt appears on startup, the configuration hasn’t taken effect. Troubleshooting steps:- Confirm both
config.tomlandauth.jsonare in the~/.codex/directory - Check that
model_providerinconfig.tomlis set tobyterouter - Verify
auth.jsonhas valid JSON format and the key is fully entered
Q2: 401 / 403 errors?
Ensure
base_url is set to https://byterouter.ai/v1.
Q3: Connection failure?
- Check your network connection
- Verify
base_urlinconfig.tomlis correct - If using a proxy, ensure it allows access to
byterouter.ai
Q4: wire_api = "chat" no longer supported?
New Codex CLI (0.84.0 and later) has removed the chat protocol. Change wire_api in config.toml to responses:
Q5: Tool call or execution errors?
Confirmwire_api in config.toml is set to responses. If you encounter compatibility issues, try switching to recommended models (like gpt-4.1 or claude-opus-4.5), which work more reliably with Codex CLI.
Q6: Want to use environment variables instead of auth.json?
You can also configure the key via environment variables. Modify the provider configuration inconfig.toml:
BYTEROUTER_API_KEY to your ByteRouter key. You won’t need auth.json in this case.
Q7: How to switch models?
Two ways:- In interactive mode: Type
/modelcommand to switch - Modify configuration: Change the
modelfield inconfig.tomland restart Codex CLI
Support & Help
If you encounter any issues:- 📧 Technical Support: [email protected]
Get Started with ByteRouter
Register now and get your API key to start using multiple AI models in Codex CLI!