# Codex Desktop 一键接入 4SToken

本文档仅适用于 **Codex Desktop**。它是桌面客户端，和 **Codex CLI** 分开配置；不要把 CLI 的 `~/.codex/config.toml`、`codex --profile` 或 `npm install -g @openai/codex` 当成 Desktop 安装步骤。

## 安装前准备

1. 已安装 Codex Desktop（若尚未安装，见 [OpenAI Codex 文档](https://developers.openai.com/codex)）。
2. 已创建 Portal Client Key，格式为 `sk-...`。
3. 确认网关 Base URL：`https://api.4stoken.cn`。
4. 确认要使用的 Codex Desktop 支持模型名，例如 `gpt-5.5`、`gpt-5.3-codex`、`gpt-5.3-codex-xhigh`。

## Windows 一键接入

```powershell
$f = Join-Path $env:TEMP 'codex-desktop.ps1'
Invoke-WebRequest -Uri '{PORTAL}/docs/scripts/codex-desktop.ps1' -OutFile $f -UseBasicParsing
powershell -NoProfile -ExecutionPolicy Bypass -File $f -ApiKey sk-你的Key
```

如需脚本尝试重启 Codex Desktop，可追加 `-Restart`：

```powershell
powershell -NoProfile -ExecutionPolicy Bypass -File $f -ApiKey sk-你的Key -Restart
```

脚本会自动尝试重启 Codex Desktop；如果你的系统没有自动拉起，再手动打开一次即可。

## macOS / Linux 一键接入

```bash
curl -fsSL '{PORTAL}/docs/scripts/codex-desktop.sh' \
  | GATEWAY_BASE_URL='https://api.4stoken.cn' bash -s -- sk-你的Key
```

如需脚本尝试重启 Codex Desktop，可加 `CODEX_DESKTOP_RESTART=1`：

```bash
curl -fsSL '{PORTAL}/docs/scripts/codex-desktop.sh' \
  | GATEWAY_BASE_URL='https://api.4stoken.cn' CODEX_DESKTOP_RESTART=1 bash -s -- sk-你的Key
```

脚本会自动尝试重启 Codex Desktop；如果你的系统没有自动拉起，再手动打开一次即可。

## 启动对话时报 feature override precedence

如果 Codex Desktop 弹出 `failed to resolve feature override precedence: No such file or directory (os error 2)`，通常是本地 `~/.codex/config.toml` 里还残留了旧的 `model_catalog_json` 或其他失效路径。删掉这些旧字段后，再重新运行本页脚本。

Desktop 用户只运行本页 `codex-desktop.sh` / `codex-desktop.ps1`；不要运行 Codex CLI 的 `codex.sh` / `codex.ps1`。

## Codex Desktop 模型映射

| Codex Desktop 支持模型名 | 系统实际 modelCode |
| --- | --- |
| `gpt-5.5` | `gpt-5.5` |
| `gpt-5.4` | `gpt-5.4` |
| `gpt-5.4-mini` | `gpt-5.4-mini` |
| `gpt-5.4-nano` | `gpt-5.4-nano` |
| `gpt-5.3-codex` | `gpt-5.3-codex` |
| `gpt-5.1-codex` | `claude-opus-4-6` |
| `gpt-5.3-codex-xhigh` | `claude-opus-4-8` |

Codex Desktop 与 Codex CLI 支持模型不同；以 `GET /v1/models` 返回为准。

## 配置检查

Windows PowerShell 请使用 `curl.exe`，避免被别名影响：

```powershell
curl.exe -sS "https://api.4stoken.cn/v1/models" -H "Authorization: Bearer sk-你的Key"
```

macOS / Linux 可直接使用 `curl`：

```bash
curl -sS 'https://api.4stoken.cn/v1/models' -H 'Authorization: Bearer sk-你的Key'
```

如果你更习惯 PowerShell，也可以用：

```powershell
Invoke-RestMethod "https://api.4stoken.cn/v1/models" -Headers @{ Authorization = "Bearer sk-你的Key" }
```

然后在 Codex Desktop 内发起一次对话或代码任务，确认模型能正常返回。

## 常见问题

### 不要安装 Codex CLI

Codex Desktop 教程不需要 `npm install -g @openai/codex`。这条命令只属于 Codex CLI 页面。

### Desktop 没有读取新配置

请完全退出 Codex Desktop 后重新打开。只关闭窗口可能不会重新加载 Provider 设置。
