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

# Thiết lập Codex CLI

> Cài Codex CLI và cấu hình NexusAPI thành custom provider Responses.

Các lệnh và trường `config.toml` dựa trên [kho Codex chính thức](https://github.com/openai/codex) và [tài liệu custom provider](https://learn.chatgpt.com/docs/config-file/config-advanced). NexusAPI chỉ cung cấp URL, API Key và model ID.

## 1. Cài đặt

Chọn một cách chính thức:

```powershell theme={"system"}
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
```

```bash theme={"system"}
curl -fsSL https://chatgpt.com/codex/install.sh | sh
```

Hoặc khi đã có Node.js:

```bash theme={"system"}
npm install -g @openai/codex
codex --version
```

## 2. Tạo key tương thích

Trong **Quản lý token → Thêm token**, chọn nhóm có mô hình dùng cho Codex / Responses. Đọc [ma trận khả năng](/vi/developer/capability-matrix): không được giả định kênh Claude kiểu Anthropic hỗ trợ Responses.

## 3. Cấu hình custom provider

| Hệ thống      | Tệp                                  |
| ------------- | ------------------------------------ |
| Windows       | `%USERPROFILE%\\.codex\\config.toml` |
| macOS / Linux | `~/.codex/config.toml`               |

```toml theme={"system"}
model_provider = "nexusapi"
model = "YOUR_MODEL_ID"

[model_providers.nexusapi]
name = "NexusAPI"
base_url = "https://nexusapi.link/v1"
env_key = "NEXUSAPI_API_KEY"
wire_api = "responses"
```

Không lưu key thật trong tệp này hoặc `~/.codex/auth.json`, vì đó là cache đăng nhập OpenAI của Codex.

## 4. Đặt biến môi trường

```powershell theme={"system"}
setx NEXUSAPI_API_KEY "YOUR_NEXUSAPI_KEY"
```

```bash theme={"system"}
export NEXUSAPI_API_KEY='YOUR_NEXUSAPI_KEY'
```

Sau `setx` phải mở terminal mới. `export` chỉ hiệu lực trong shell hiện tại. Với lưu lâu dài, hãy dùng kho thông tin xác thực hoặc biến môi trường được quản lý, không dùng repository.

## 5. Kiểm tra

Chạy `codex` trong dự án, trước hết yêu cầu một tác vụ chỉ đọc như: “Giải thích cấu trúc repository, không sửa tệp.” Nếu lỗi, kiểm tra terminal mới, key, nhóm và model ID, lưu Request ID rồi làm [tự kiểm tra](/vi/faq/self-check).
