> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nexusapi.link/llms.txt
> Use this file to discover all available pages before exploring further.

# Codex CLI setup

> Install Codex CLI and configure NexusAPI as a custom Responses provider.

Codex CLI is OpenAI's local coding agent. The commands and `config.toml` fields below follow the [official Codex repository](https://github.com/openai/codex) and [custom-provider reference](https://learn.chatgpt.com/docs/config-file/config-advanced). NexusAPI supplies only the Base URL, API key, and model ID.

## 1. Install Codex CLI

Choose one official installation method.

### Windows PowerShell

```powershell theme={"system"}
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
```

### macOS, Linux, or WSL

```bash theme={"system"}
curl -fsSL https://chatgpt.com/codex/install.sh | sh
```

### With Node.js already installed

```bash theme={"system"}
npm install -g @openai/codex
```

Verify installation:

```bash theme={"system"}
codex --version
```

## 2. Create a compatible key

In **NexusAPI console → Token Management → Add token**, select a group containing the exact Codex-compatible model you need. Use a recognizable name and a suitable project limit. Check the [capability matrix](/en/developer/capability-matrix) rather than assuming a Claude-type channel works with Responses.

## 3. Configure a custom provider

Open the user configuration file:

| System        | File                               |
| ------------- | ---------------------------------- |
| Windows       | `%USERPROFILE%\.codex\config.toml` |
| macOS / Linux | `~/.codex/config.toml`             |

```toml theme={"system"}
model_provider = "nexusapi"
model = "YOUR_MODEL_ID"

[model_providers.nexusapi]
name = "NexusAPI"
base_url = "https://nexusapi.link/v1"
env_key = "NEXUSAPI_API_KEY"
wire_api = "responses"
```

Replace `YOUR_MODEL_ID` with the exact model ID available to the key. Do not put the actual key in this file.

<Warning>
  **Do not write a NexusAPI key to `auth.json`**

  `~/.codex/auth.json` is Codex's OpenAI login cache. The configuration above reads the key from `env_key`; keep NexusAPI credentials out of `auth.json`, source code, and screenshots.
</Warning>

## 4. Set the environment variable

### Windows PowerShell

```powershell theme={"system"}
setx NEXUSAPI_API_KEY "YOUR_NEXUSAPI_KEY"
```

Open a new terminal after running this command.

### macOS, Linux, or WSL

```bash theme={"system"}
export NEXUSAPI_API_KEY='YOUR_NEXUSAPI_KEY'
```

This affects only the current shell. For long-term storage, use your system's credential or shell-environment management; never add the key to a repository.

## 5. Verify safely

```bash theme={"system"}
cd your-project-folder
codex
```

For the first task, use a read-only instruction such as: `Explain the repository layout without changing files.` Then check the console usage log.

## Troubleshooting

1. Use a newly opened terminal so `NEXUSAPI_API_KEY` is available.
2. Confirm the key is enabled, funded, and assigned to the right group.
3. Recopy the exact model ID from the Model Marketplace or `/v1/models`.
4. Save the complete error and Request ID, then use the [self-check guide](/en/faq/self-check).

For editor use, install the [Codex extension published by OpenAI](https://marketplace.visualstudio.com/items?itemName=OpenAI.chatgpt). It uses the same user-level Codex configuration; do not add legacy `chatgpt.apiBase` settings.
