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

# Codex CLI

> Install the Codex CLI and register Triw as a model provider in config.toml.

Codex is OpenAI's terminal agent. Custom providers live in `~/.codex/config.toml`, so Triw is a normal provider block with a base URL and an env key.

## Requirements

| Item | Minimum |
| - | - |
| OS | macOS 13+, Linux, Windows (native or WSL) |
| Node | 20+ for the npm install |
| Network | outbound HTTPS to `router.triw.io` |

## Install

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

```bash Homebrew (macOS) theme={null}
brew install --cask codex
```

```bash theme={null}
codex --version
```

## Configure Triw

```toml ~/.codex/config.toml theme={null}
model = "claude-sonnet-4-5"
model_provider = "triw"

[model_providers.triw]
name = "Triw"
base_url = "https://router.triw.io/v1"
env_key = "TRIW_API_KEY"
```

```bash theme={null}
export TRIW_API_KEY="sk-..."
```

Two details matter:

* `base_url` ends with `/v1`. Codex appends `/chat/completions` or `/responses`.
* `env_key` names the environment variable; the key itself never lives in the file.

If you only need to redirect the built-in OpenAI provider (no second provider id), Codex also accepts `openai_base_url = "https://router.triw.io/v1"` at the top level. The explicit provider block above is clearer when you keep both.

## Pick a model

```bash theme={null}
curl https://router.triw.io/v1/models -H "Authorization: Bearer $TRIW_API_KEY"
```

Use the exact id in `model =`. Coding ids usually come from the `gpt-5*`, `codex`, or `claude-*` families, depending on what the operator connected.

## Verify

```bash theme={null}
codex exec "reply with the single word: ready"
```

Interactive mode: `codex`, then `/status` to confirm provider and model. Cross-check with **Logs** in the Triw console.

## Troubleshooting

| Symptom | Cause | Fix |
| - | - | - |
| `401` on every call | `TRIW_API_KEY` unset in the shell Codex runs in | Export it, or point `env_key` at a variable you do set |
| `404` on every call | `base_url` missing `/v1` or including a path | Use `https://router.triw.io/v1` |
| Wrong provider used | `model_provider` still set to `openai` | Set it to `triw` |
| Tool calls rejected | Model lacks tool-calling support | Switch to a coding model |
| `wire_api` errors | Some builds expect an explicit protocol | Add `wire_api = "chat"` inside the provider block |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.