# Codex CLI

Set Codex CLI up on OpenDunes once, with a profile for each kind of work.

Codex sends every request to `POST /v1/responses`, in the Responses shape: it speaks no other. [Coding agents](/docs/coding-agents) shows its provider block; this recipe adds the key it reads, a second profile, and a run from a script.

1. [Install Codex CLI](#1-install-codex-cli).
2. [Add OpenDunes as a provider](#2-add-opendunes-as-a-provider).
3. [Add a profile for harder work](#3-add-a-profile-for-harder-work).
4. [Check the connection](#4-check-the-connection).
5. [Run it from a script](#5-run-it-from-a-script).

## 1. Install Codex CLI

| With | Install line |
|---|---|
| npm | `npm install -g @openai/codex` |
| Homebrew | `brew install --cask codex` |

Run `codex --version` to see it answer.

## 2. Add OpenDunes as a provider

Create an API key for Codex alone, and cap it on *API Keys*: an agent sends many requests for one task, and the cap stops this key alone ([API keys](/docs/api-keys) shows how). Put it in your shell profile, `~/.zshrc` or `~/.bashrc`:

```bash
export OPENDUNES_API_KEY="…"
```

Then write the provider into `~/.codex/config.toml`:

```toml
model = "anthropic/claude-sonnet-4.5"
model_provider = "opendunes"

[model_providers.opendunes]
name = "OpenDunes"
base_url = "https://opendunes.com/v1"
env_key = "OPENDUNES_API_KEY"
wire_api = "responses"
supports_websockets = false
request_max_retries = 4
```

| Key | Holds |
|---|---|
| `model` | the model ID Codex starts on |
| `model_provider` | the provider it sends to: the name of the block below it |
| `base_url` | the address, with `/v1` |
| `env_key` | the variable Codex reads the key from: no `codex login` is needed |
| `wire_api` | `responses`, the one shape Codex speaks |
| `supports_websockets` | `false`: Codex sends each request over HTTPS |
| `request_max_retries` | how often Codex tries a request again after a failure |

<div class="watch-out">
<p>The provider goes in <code>~/.codex/config.toml</code>, in your home folder. Codex ignores <code>model_provider</code> and <code>model_providers</code> in a project's <code>.codex/config.toml</code>.</p>
</div>

## 3. Add a profile for harder work

A profile is a file of its own, `~/.codex/‹name›.config.toml`, whose keys win over `config.toml` when you start Codex with it. This one keeps the OpenDunes provider and changes the model and how long it thinks. Save it as `~/.codex/deep.config.toml`:

```toml
model = "openai/gpt-5.5"
model_reasoning_effort = "high"
```

Start Codex with it for a hard change, and without it for the day's work:

```bash
codex --profile deep
```

Each model is charged at its own rate, shown on its page in [Models](/docs/models). Thinking longer writes more tokens, and each one is charged.

## 4. Check the connection

Start `codex` in your project and run `/status`: it shows the provider and the model of the session. `/model` switches the model for the session.

The request is on *Activity*, in the app, with its charge in DA.

## 5. Run it from a script

`codex exec` runs one task without the interface, prints the result and exits: a script, a git hook or a CI job can call it.

```bash
codex exec "List the functions in src/ that have no test."
```

It reads the same `config.toml`, so it runs on OpenDunes with the same key. In CI, set `OPENDUNES_API_KEY` from the CI's secrets, and give that job a key and a cap of its own.

## Errors

| Status | Means | Do |
|---|---|---|
| 401 | the key is missing, wrong, paused, revoked or expired | check `OPENDUNES_API_KEY` is set in the terminal Codex starts from |
| 402 | the balance is at zero or below, cannot pay the request's hold, or the key's cap is spent | make a deposit, or raise the cap |
| 404 | the model ID is not on sale | copy the ID from Models |

Every other status: [Errors and retries](/docs/errors-and-retries).

Next: [Codex Desktop](/docs/cookbook/codex-desktop) · [Automatic code review](/docs/cookbook/automatic-code-review)
