# Codex tutorial

Configure Codex CLI with a KaiyunCode API key, base URL, and model name.

Canonical: https://kaiyuncode.com/tutorials/codex
Markdown: https://kaiyuncode.com/tutorials/codex.en.md

## Setup

Codex CLI uses OpenAI-compatible authentication. This guide sets wire_api to responses and base_url to https://kaiyuncode.com/v1.

Replace REPLACE_WITH_YOUR_API_KEY with an API key created in KaiyunCode. Change model to a GPT model enabled on your account.

- Config directory: %USERPROFILE%\.codex on Windows, ~/.codex on macOS and Linux.
- auth.json stores OPENAI_API_KEY.
- config.toml stores the model, provider, wire_api, and base_url.
- Check it by running codex and sending a short message, or asking it to inspect the current project.

## Install Codex CLI

Codex CLI requires Node.js 18 or newer. Open a new terminal after installation so the updated PATH is used.

### Windows PowerShell

```powershell
node --version
npm install -g @openai/codex
```

### macOS / Linux

```bash
node --version
npm install -g @openai/codex
```

## Verify Codex

Confirm the files were written, then start codex. A normal reply and a call record in KaiyunCode mean the setup works.

### Windows PowerShell

```powershell
Get-Content "$env:USERPROFILE\.codex\auth.json"
Get-Content "$env:USERPROFILE\.codex\config.toml"
codex
```

### macOS / Linux

```bash
cat "$HOME/.codex/auth.json"
cat "$HOME/.codex/config.toml"
codex
```

## Codex troubleshooting

- If Codex says the model is unavailable, switch to a GPT model enabled on KaiyunCode.
- If it says you are not signed in, check that OPENAI_API_KEY in auth.json replaced only the sample text and that the JSON quotes remain.
- If requests go to official OpenAI, confirm config.toml has base_url = "https://kaiyuncode.com/v1" and model_provider = "custom".
