# Codex CLI: install, configure and troubleshoot LYRouter access

Source: https://platform.lyrouter.com/ai_gateway/docs/codex/en
Last updated: 2026-10-14

Codex CLI can connect to LYRouter as a custom model service. This page starts with the installation prerequisites, then shows how to configure the tool and make your first call.

Already installed? Go straight to [Configure LYRouter](#configure-lyrouter).

## Prerequisites

This page covers connecting Codex CLI through a custom model provider, installed with npm. Choose your operating system and prepare Node.js LTS / npm, network access and write permission to your user-level global installation directory. The model service must support Responses.

**Choose your operating system**

Windows:
#### 1. Choose a terminal environment

You can run Codex CLI natively in **PowerShell**. If your project and dependencies are in WSL, run it in the WSL terminal and prepare the environment by following the Linux tab. For how Codex runs and is sandboxed on Windows, see the [official OpenAI documentation](https://developers.openai.com/codex/windows/).

#### 2. Prepare Node.js and npm

If they are not installed, first install Node.js LTS for Windows as described in [environment setup in Your first model call](https://platform.lyrouter.com/ai_gateway/docs/quickstart/en). Reopen PowerShell, then check:

```powershell
node --version
npm.cmd --version
npm.cmd config get prefix
```

Make sure version numbers are shown and the global installation directory is writable. On Windows, use `npm.cmd` to avoid PowerShell's execution policy restrictions on `npm.ps1`.

Linux:
#### 1. Prepare the terminal and project directory

Run it in a **Bash** terminal, with a readable and writable local project directory, network access and a user-level tool installation directory. First check your system and architecture:

```bash
cat /etc/os-release
uname -m
```

#### 2. Prepare Node.js and npm

If they are not installed, install Node.js LTS as described in [Linux environment setup in Your first model call](https://platform.lyrouter.com/ai_gateway/docs/quickstart/en), then check:

```bash
node --version
npm --version
npm config get prefix
```

Use a writable user-level installation directory. For installation permission problems, first check the Node.js / npm paths and how they were installed.

macOS:
#### 1. Prepare the terminal and project directory

Open **Terminal**, use Bash / Zsh, and prepare a readable and writable project directory and network access:

```bash
sw_vers -productVersion
uname -m
```

#### 2. Prepare Node.js and npm

If they are not installed, install Node.js LTS as described in [macOS environment setup in Your first model call](https://platform.lyrouter.com/ai_gateway/docs/quickstart/en). Once PATH is configured, check:

```bash
node --version
npm --version
npm config get prefix
```

This page uses npm. If you use the official standalone installer or Homebrew, follow the [official CLI guide](https://developers.openai.com/codex/cli/).

To connect to LYRouter you also need an enabled API key and a model available in the current workspace. Replace `MODEL_ID` in the examples with an actual system model identifier. Your tool account and your LYRouter account are two separate identities.

## Install the app

**Install for your operating system**

Windows PowerShell:
```powershell
npm.cmd install -g @openai/codex@latest
codex --version
```

Linux / WSL:
```bash
npm install -g @openai/codex@latest
codex --version
```

macOS:
```bash
npm install -g @openai/codex@latest
codex --version
```

Reopen the terminal after installation and check the version. For other installation methods, see the official guides below.

## Configure LYRouter

Merge the custom provider configuration into `~/.codex/config.toml`:

```toml
model = "MODEL_ID"
model_provider = "lyrouter"

[model_providers.lyrouter]
name = "LYRouter"
base_url = "https://api.lyrouter.com/v1"
env_key = "LYROUTER_API_KEY"
wire_api = "responses"
```

In the current official configuration, `wire_api` supports only `responses`; do not use the old `chat` value. Put the key in the environment variable that the configuration names:

**Set the API key**

macOS / Linux / WSL:
```bash
export LYROUTER_API_KEY="YOUR_LYROUTER_API_KEY"
codex
```

Windows PowerShell:
```powershell
$env:LYROUTER_API_KEY="YOUR_LYROUTER_API_KEY"
codex
```

The model and its source must actually support [Responses](https://platform.lyrouter.com/ai_gateway/docs/responses-api/en). Choosing a Chat-only source makes calls fail.

## Verify your first call

Start the app, explicitly select the model you just configured, and send a minimal task such as "Reply OK". Then check the generation endpoint, status and actual model in LYRouter's [request logs](https://platform.lyrouter.com/ai_gateway/docs/logs/en). A successful connection test does not mean that full generation or tool calling works.

## Everyday use and troubleshooting

### The command is not found after installation. What should I do?

**Answer:** Reopen the terminal, run the version check command from this page's installation steps, and check whether the installation directory is on PATH. Use the same terminal and runtime environment as in the installation steps. If it still does not work, check the installation against the official installation guide.

### How should I configure the Base URL and the wire protocol?

**Answer:** On this page, `base_url` is `https://api.lyrouter.com/v1` and `wire_api` is `responses`. Make sure the `lyrouter` provider is selected and the model and its service source support [Responses](https://platform.lyrouter.com/ai_gateway/docs/responses-api/en). Do not add `/v1` to the address twice.

### What should I check before switching models?

**Answer:** Make sure the new model is enabled in the current workspace, has at least one valid service source, and supports the protocol and tool capabilities the app needs. Use the system model identifier, not the display name.

### Why does my configuration stop working after an app update?

**Answer:** First check the current app version and which configuration location it actually reads, then check the provider, address, key and model against "Configure LYRouter" on this page. The official resources linked on this page define the configuration requirements of each version.

### A request returns 401 / 403. What should I check first?

**Answer:** Make sure you entered an enabled LYRouter API key, and check the model sources and access policies of the workspace the key belongs to. Use the specific error and the logs to find what rejected the request; see [401 / 403: authentication and access](https://platform.lyrouter.com/ai_gateway/docs/auth-errors/en).

### A request returns 429. Does retrying repeatedly help?

**Answer:** First find out whether a platform limit or an exhausted upstream quota caused it, then adjust concurrency, call frequency or resource configuration. Retry with bounded backoff instead of retrying immediately and repeatedly; see [429: rate limits and quotas](https://platform.lyrouter.com/ai_gateway/docs/rate-errors/en).

### The app replies, but I cannot find the request in the LYRouter logs. What should I do?

**Answer:** Make sure the LYRouter provider and model configured on this page are the ones in effect, and check the gateway address. After verifying with a minimal generation task, search the [request logs](https://platform.lyrouter.com/ai_gateway/docs/logs/en) in the correct workspace by time and key. Listing models alone does not appear in the regular call list.

## Official resources

The requirements and installation methods below come from the tool's official documentation. For later versions, the official instructions take precedence.

- [Codex CLI](https://developers.openai.com/codex/cli/)
- [Current configuration reference](https://developers.openai.com/codex/config-reference/)
- [Codex open-source repository and npm installation](https://github.com/openai/codex)
