# Codex Setup (CLI)

Codex is OpenAI's AI coding assistant that can read and write code, fix bugs, and explain code directly on your machine. Just describe what you need in natural language, and it will automatically read and modify your code files.

## Prerequisites

- You've obtained a NovAPI APIKey (created in the console under "APIKey Management").
- You've installed Node.js 18+ (run `node -v` to confirm; if not installed, download the LTS version from nodejs.org).

## Step 1: Install the Codex CLI

```bash
npm install -g @openai/codex
```

Verify the installation (seeing a version number means success):

```bash
codex --version
```

## Step 2: Create the config file

Codex config file path:

- Windows: `C:\Users\{username}\.codex\config.toml`
- macOS / Linux: `~/.codex/config.toml`

Create the directory:

```bash
# Windows (PowerShell)
mkdir "$env:USERPROFILE\.codex"

# macOS / Linux
mkdir -p ~/.codex
```

The `.codex` folder usually contains files such as `auth.json` and `config.toml`:

![.codex config folder](https://www.novapi.ai/docs/cli/rc-3.webp)

## Step 3: Write the config

Write the following into `config.toml`. There are two ways to provide the APIKey—**pick just one**.

### Option 1: Write it directly into the config file (recommended for personal use)

Windows users:

```toml
model = "gpt-5.3-codex"
model_provider = "novapi"
approval_policy = "never"
sandbox_mode = "danger-full-access"

[model_providers.novapi]
name = "novapi"
base_url = "https://api.novapi.ai/v1"
requires_openai_auth = false
api_key = "your-APIKey"

[windows]
sandbox = "elevated"
```

macOS / Linux users:

```toml
model = "gpt-5.3-codex"
model_provider = "novapi"
approval_policy = "never"

[model_providers.novapi]
name = "novapi"
base_url = "https://api.novapi.ai/v1"
requires_openai_auth = false
api_key = "your-APIKey"
```

> ⚠️ With this option the key is stored in plaintext in the file—do not commit `config.toml` to git or share it with others.

### Option 2: Read from an environment variable (recommended for teams/shared use)

The config file only references the environment variable name; the key lives separately in a system environment variable, so the config file can be shared safely.

Use `env_key` in the config file:

```toml
[model_providers.novapi]
name = "novapi"
base_url = "https://api.novapi.ai/v1"
requires_openai_auth = false
env_key = "NOVAPI_API_KEY"
```

Set the system environment variable:

```bash
# Windows (PowerShell, permanent; restart the terminal after setting)
[System.Environment]::SetEnvironmentVariable("NOVAPI_API_KEY", "your-APIKey", "User")

# macOS / Linux (bash)
echo 'export NOVAPI_API_KEY="your-APIKey"' >> ~/.bashrc && source ~/.bashrc

# macOS (zsh, default)
echo 'export NOVAPI_API_KEY="your-APIKey"' >> ~/.zshrc && source ~/.zshrc
```

### Field reference

- `model`: the model name to use; any gpt model works (e.g. `gpt-5.3-codex` / `gpt-4o`).
- `model_provider`: points to the `[model_providers.xxx]` name below.
- `base_url`: the NovAPI endpoint `https://api.novapi.ai/v1`.
- `api_key`: for Option 1, the APIKey written directly.
- `env_key`: for Option 2, the name of the environment variable holding the APIKey.
- `approval_policy = "never"`: run all operations automatically. To confirm manually before each file change, set it to `"suggest"`.

## Step 4: Verify the connection

Enter any project directory and run; seeing a directory analysis means the setup works:

```bash
codex "hello, list files in current directory"
```

When you see Codex's startup info (model, directory) and it chats normally, the setup is complete:

![Codex running successfully](https://www.novapi.ai/docs/cli/rc-4.webp)

## Step 5: Start using it

In a project directory, just describe what you need and Codex will read files, understand the context, and act:

```bash
codex "check this project for code issues"
codex "add exception handling to main.js"
codex "explain what this function does"
```

## Available models

Codex now supports **all gpt-series models** (e.g. `gpt-5.3-codex`, `gpt-4o`, etc.); just change `model` in `config.toml` to the gpt model you want. Available models are as returned by `GET /v1/models` or as published by the platform.

## FAQ

- **401 Unauthorized (authentication failed)**: Check that `api_key` is correct with no extra spaces, and confirm the APIKey hasn't expired.
- **503 model_not_found**: Confirm `model` is a gpt model available on the platform, spelled exactly (see `GET /v1/models`).
- **Windows sandbox error (Couldn't set up admin sandbox)**: Confirm `config.toml` contains `sandbox_mode = "danger-full-access"` and `[windows] sandbox = "elevated"`; or run the terminal as administrator.
- **macOS npm permission error**: `sudo npm install -g @openai/codex`.
