Skip to main content

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:
  1. Node.js Installed Download and install from Node.js official website (recommended LTS version v20 or higher) for npm-based installation of Codex CLI
  2. 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:

Verify Installation

After installation, run the following command to confirm success:
If a version number is displayed, the installation is successful.

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 the auth.json file in the configuration directory with your ByteRouter key:

2.3 Configure Model Provider

Create or edit the config.toml file in the configuration directory and add the ByteRouter provider:
After saving both files, restart Codex CLI for changes to take effect.
Ensure auth.json is valid JSON and config.toml is valid TOML. Don’t use Chinese quotes, or the configuration won’t work.

Step 3: Get Started

Verify Configuration

In any project directory, run the following command to verify your configuration:
If you receive an AI response, the configuration is successful. If you see a login screen or 401, 403 errors, refer to the troubleshooting section below.

Interactive Mode

Run codex directly to enter the interactive interface, ideal for handling complete coding tasks:
Once inside, describe your requirements in natural language, for example:
Codex will automatically analyze your project, generate code, run commands, and request confirmation before sensitive operations.

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:
Model Selection Recommendation: The above GPT-5 series models work best with Codex CLI. For optimal results, we recommend prioritizing gpt-5.5; gpt-5.3-codex is specifically optimized for Codex’s agent-based coding scenarios.

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:
  1. Confirm both config.toml and auth.json are in the ~/.codex/ directory
  2. Check that model_provider in config.toml is set to byterouter
  3. Verify auth.json has 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?

  1. Check your network connection
  2. Verify base_url in config.toml is correct
  3. 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:
ByteRouter supports Responses API. After making this change, restart Codex.

Q5: Tool call or execution errors?

Confirm wire_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 in config.toml:
Then set the environment variable BYTEROUTER_API_KEY to your ByteRouter key. You won’t need auth.json in this case.

Q7: How to switch models?

Two ways:
  1. In interactive mode: Type /model command to switch
  2. Modify configuration: Change the model field in config.toml and restart Codex CLI

Support & Help

If you encounter any issues:

Get Started with ByteRouter

Register now and get your API key to start using multiple AI models in Codex CLI!