Codex 是 OpenAI 官方的命令行 AI 编程助手,支持通过 cch 代理使用。

注意:Codex 使用 OpenAI 兼容格式,端点需要包含 /v1 路径。

注意:Codex CLI、Codex App、Visual Studio Code Codex插件都可用该指南

注意:不需要安装Codex CLI的用户请直接跳转到 codex配置一栏

Curl测试

  • windows

curl.exe https://sub.anzhiyu.com/v1/responses `

  -H "Content-Type: application/json" `

  -H "Authorization: Bearer your-api-key" `

  -d '{\"model\":\"gpt-5.4\",\"input\":[{\"role\":\"user\",\"content\":[{\"type\":\"input_text\",\"text\":\"你好\"}]}],\"store\":false,\"stream\":true,\"include\":[\"reasoning.encrypted_content\"]}'
  • Linux

curl https://sub.anzhiyu.com/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key" \
  -d '{
  "model": "gpt-5.4",
  "input": [
    {
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "你好"
        }
      ]
    }
  ],
  "store": false,
  "stream": true,
  "include": [
    "reasoning.encrypted_content"
  ]
}'

模型列表

  • gpt-5.5

  • gpt-5.4

  • gpt-5.3-codex

  • gpt-5.2

Windows

安装 Node.js

需要 Node.js 环境才能运行(需 v18 或更高版本)。

方法一:官网下载(推荐)

  1. 访问 https://nodejs.org/

  1. 下载 LTS 版本(需 v18 或更高)

  1. 双击 .msi 文件,按向导安装(保持默认设置)

方法二:使用包管理器

# 使用 winget (windows 11以上)
winget install nodejs

# 或使用 Chocolatey
choco install nodejs

# 或使用 Scoop
scoop install nodejs

提示:建议使用 PowerShell 而不是 CMD,以获得更好的体验

安装完成后,打开终端/命令行,输入以下命令验证:

node --version
npm --version

如果显示版本号,说明安装成功了!

安装 Codex

codex cli

以管理员身份运行 PowerShell,执行:

npm i -g @openai/codex --registry=https://registry.npmmirror.com

验证安装:

codex --version

如果存在老版本,更新最新版本:

npm i -g @openai/codex --registry=https://registry.npmmirror.com

codex 配置

  1. 打开文件资源管理器,找到 C:\Users\你的用户名\.codex 文件夹(不存在则创建)

  1. 创建 config.toml 文件 和 auth.json 文件

  1. 使用文本编辑器打开 config.toml,添加以下内容:

model_provider = "OpenAI"
model = "gpt-5.4"
model_reasoning_effort = "xhigh"
disable_response_storage = true
sandbox_mode = "workspace-write"
windows_wsl_setup_acknowledged = true

[features]
plan_tool = true
apply_patch_freeform = true
view_image_tool = true
unified_exec = false
streamable_shell = false
rmcp_client = true

[model_providers.OpenAI]
name = "OpenAI"
base_url = "https://sub.anzhiyu.com/v1"
wire_api = "responses"
requires_openai_auth = true

[sandbox_workspace_write]
network_access = true
  1. 打开 auth.json 文件,添加以下内容,将your-api-key-here替换为自己的API key:

{
  "OPENAI_API_KEY": "your-api-key-here"
}
  1. 关闭命令行窗口,重新打开,输入 codex


MacOS

安装 Node.js

需要 Node.js 环境才能运行(需 v18 或更高版本)。

方法一:使用 Homebrew(推荐)

# 更新 Homebrew
brew update

# 安装 Node.js
brew install node

方法二:官网下载

  1. 访问 https://nodejs.org/

  1. 下载适合 macOS 的 LTS 版本(需 v18 或更高)

  1. 打开下载的 .pkg 文件,按照安装向导完成

安装完成后,打开终端/命令行,输入以下命令验证:

node --version
npm --version

如果显示版本号,说明安装成功了!

安装 Codex

codex cli

执行:

npm i -g @openai/codex --registry=https://registry.npmmirror.com

验证安装:

codex --version

codex 配置

  1. 打开文件资源管理器,找到 ~/.codex 文件夹(不存在则创建)

  1. 创建 config.toml 文件 和 auth.json

  1. 使用文本编辑器打开 config.toml,添加以下内容:

model_provider = "OpenAI"
model = "gpt-5.4"
model_reasoning_effort = "xhigh"
disable_response_storage = true
sandbox_mode = "workspace-write"
windows_wsl_setup_acknowledged = true


[features]
plan_tool = true
apply_patch_freeform = true
view_image_tool = true
unified_exec = false
streamable_shell = false
rmcp_client = true

[model_providers.OpenAI]
name = "OpenAI"
base_url = "https://sub.anzhiyu.com/v1"
wire_api = "responses"
requires_openai_auth = true

[sandbox_workspace_write]
network_access = true

[windows]
sandbox = "elevated"
  1. 打开 auth.json 文件,添加以下内容,将your-api-key-here替换为自己的API key:

{
  "OPENAI_API_KEY": "your-api-key-here"
}
  1. 关闭命令行窗口,重新打开,输入 codex


Linux

安装 Node.js

需要 Node.js 环境才能运行(需 v18 或更高版本)。

方法一:使用包管理器(推荐)

Ubuntu / Debian:

# 添加 NodeSource 仓库(Node.js 18 LTS)
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

CentOS / RHEL / Fedora:

# 添加 NodeSource 仓库(Node.js 18 LTS)
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
sudo yum install -y nodejs

Arch Linux:

sudo pacman -S nodejs npm

方法二:使用 nvm(版本管理器,推荐多版本场景)

# 安装 nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

# 重新加载 shell 配置
source ~/.bashrc

# 安装 Node.js 18 LTS
nvm install 18
nvm use 18

方法三:官网下载

  1. 访问 https://nodejs.org/

  1. 下载适合 Linux 的 LTS 版本(需 v18 或更高)

  1. 解压并配置环境变量

安装完成后,打开终端,输入以下命令验证:

node --version
npm --version

如果显示版本号,说明安装成功了!

安装 Codex

codex cli

执行:

npm i -g @openai/codex --registry=https://registry.npmmirror.com

验证安装:

codex --version

codex 配置

  1. 找到 ~/.codex 文件夹(不存在则创建)

  1. 创建 config.toml 文件 和 auth.json

  1. 使用文本编辑器打开 config.toml,添加以下内容:

model_provider = "OpenAI"
model = "gpt-5.4"
model_reasoning_effort = "xhigh"
disable_response_storage = true
sandbox_mode = "workspace-write"


[features]
plan_tool = true
apply_patch_freeform = true
view_image_tool = true
unified_exec = false
streamable_shell = false
rmcp_client = true

[model_providers.OpenAI]
name = "OpenAI"
base_url = "https://sub.anzhiyu.com/v1"
wire_api = "responses"
requires_openai_auth = true

[sandbox_workspace_write]
network_access = true
  1. 打开 auth.json 文件,添加以下内容,将your-api-key-here替换为自己的API key:

{
  "OPENAI_API_KEY": "your-api-key-here"
}
  1. 关闭命令行窗口,重新打开,输入 codex