# Codex

Codex CLI talks to kenari through a custom provider in `~/.codex/config.toml`. Recent Codex versions only use the Responses API format, so the provider must point at kenari's `/v1/responses` endpoint. See [Responses](/en/docs/responses) for the endpoint itself.

## Configure the provider

Create or edit `~/.codex/config.toml`:

```toml
model = "step-3-7-flash:free"
model_provider = "kenari"

[model_providers.kenari]
name = "kenari"
base_url = "https://kenari.id/v1"
wire_api = "responses"
env_key = "KENARI_API_KEY"
requires_openai_auth = false
```

| Setting | Value |
| --- | --- |
| `model` | A model id from [Models and pricing](/en/docs/models). `step-3-7-flash:free` runs with zero balance. |
| `base_url` | `https://kenari.id/v1`. Unlike Claude Code, Codex needs the `/v1`. |
| `wire_api` | `responses`. Codex no longer accepts `chat`. |
| `env_key` | The name of the environment variable that holds your key. |

Then export your key in the shell that runs Codex:

```bash
export KENARI_API_KEY=kn-...
```

Create the key under **API Keys** in the dashboard. See [Authentication and API keys](/en/docs/authentication).

### Store the key in auth.json instead

If you would rather keep the key in `~/.codex/auth.json`, set `requires_openai_auth = true` and remove the `env_key` line. Then store the kenari key in that file by running this command, which reads the key from the environment variable and writes it to `auth.json`:

```bash
printenv KENARI_API_KEY | codex login --with-api-key
```

The file should then hold the kenari key and nothing else:

```json
{ "OPENAI_API_KEY": "kn-..." }
```

The field is named `OPENAI_API_KEY` because Codex uses that name for any API key. The value is your kenari key.

## Verify the connection

Start Codex and send a short prompt:

```bash
codex
```

A reply means the connection works.

## Troubleshooting

| Symptom | Cause | Fix |
| --- | --- | --- |
| `401` with `invalid key` or `missing authorization` | `KENARI_API_KEY` is not set in this shell, or the key does not start with `kn-`. | Export the key again, then restart Codex. |
| `400` with `model_not_found` | The model id is misspelled or not in the catalog. | Copy the id from [Models and pricing](/en/docs/models). |
| `402` with `insufficient_balance` | The model is paid and your balance is empty. | Use a `:free` model, or top up. See [How billing works](/en/docs/billing). |
| `405` | `base_url` has a doubled `/v1` or is missing it. | Set `base_url` to exactly `https://kenari.id/v1`. |

## See also

- [Responses](/en/docs/responses)
- [kenari CLI](/en/docs/cli)
- [Integrations overview](/en/docs/integrations)
- [Errors](/en/docs/errors)
