> ## 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.

# Codex CLI 安裝與設定

> 安裝 Codex CLI，並把 NexusAPI 設為自訂 Responses Provider。

本頁的安裝命令和 `config.toml` 欄位依據 [OpenAI Codex 官方儲存庫](https://github.com/openai/codex)及[自訂 Provider 參考](https://learn.chatgpt.com/docs/config-file/config-advanced)。NexusAPI 僅提供位址、API Key 和模型 ID。

## 1. 安裝

選擇一種官方方式即可：

```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
```

已安裝 Node.js 時可使用：

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

## 2. 建立相容的 Key

在控制台 **令牌管理 → 新增令牌** 選擇包含目標 Codex／Responses 模型的群組，設定名稱和專案額度。請先看[能力矩陣](/zh-TW/developer/capability-matrix)，不要假設 Anthropic 類 Claude 渠道可使用 Responses。

## 3. 設定自訂 Provider

| 系統          | 設定檔                                  |
| ----------- | ------------------------------------ |
| 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"
```

請將 `YOUR_MODEL_ID` 替換成目前 Key 可用的準確模型 ID。不要在設定檔中保存真實 Key。

<Warning>
  `~/.codex/auth.json` 是 Codex 的 OpenAI 登入快取。請不要把 NexusAPI Key 寫進它；上方設定會從 `env_key` 讀取環境變數。
</Warning>

## 4. 設定環境變數

Windows PowerShell：

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

macOS、Linux 或 WSL：

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

Windows 的 `setx` 需要新開終端才生效；臨時 `export` 僅對目前 Shell 生效。請使用系統憑證或受控的環境變數管理方案長期保存，不要提交到儲存庫。

## 5. 驗證與排查

執行 `codex` 後，先提出「說明目前儲存庫結構，不要修改檔案」之類的唯讀任務。若失敗，確認新終端已取得 Key、Key／群組／模型 ID 正確，並保留錯誤及 Request ID 後依[問題自查](/zh-TW/faq/self-check)處理。
