Codex 是 OpenAI 官方的命令行 AI 编程助手,支持通过 cch 代理使用。
注意:Codex 使用 OpenAI 兼容格式,端点需要包含 /v1 路径。
注意:Codex CLI、Codex App、Visual Studio Code Codex插件都可用该指南
注意:不需要安装Codex CLI的用户请直接跳转到 codex配置一栏
Curl测试
windows
PLAINTEXT
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
PLAINTEXT
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 或更高版本)。
方法一:官网下载(推荐)
下载 LTS 版本(需 v18 或更高)
双击 .msi 文件,按向导安装(保持默认设置)
方法二:使用包管理器
PLAINTEXT
# 使用 winget (windows 11以上)
winget install nodejs
# 或使用 Chocolatey
choco install nodejs
# 或使用 Scoop
scoop install nodejs提示:建议使用 PowerShell 而不是 CMD,以获得更好的体验
安装完成后,打开终端/命令行,输入以下命令验证:
PLAINTEXT
node --version
npm --version如果显示版本号,说明安装成功了!
安装 Codex
codex cli
以管理员身份运行 PowerShell,执行:
PLAINTEXT
npm i -g @openai/codex --registry=https://registry.npmmirror.com验证安装:
PLAINTEXT
codex --version如果存在老版本,更新最新版本:
PLAINTEXT
npm i -g @openai/codex --registry=https://registry.npmmirror.comcodex 配置
打开文件资源管理器,找到
C:\Users\你的用户名\.codex文件夹(不存在则创建)
创建
config.toml文件 和auth.json文件
使用文本编辑器打开
config.toml,添加以下内容:
PLAINTEXT
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
打开
auth.json文件,添加以下内容,将your-api-key-here替换为自己的API key:
PLAINTEXT
{
"OPENAI_API_KEY": "your-api-key-here"
}关闭命令行窗口,重新打开,输入
codex
MacOS
安装 Node.js
需要 Node.js 环境才能运行(需 v18 或更高版本)。
方法一:使用 Homebrew(推荐)
PLAINTEXT
# 更新 Homebrew
brew update
# 安装 Node.js
brew install node方法二:官网下载
下载适合 macOS 的 LTS 版本(需 v18 或更高)
打开下载的 .pkg 文件,按照安装向导完成
安装完成后,打开终端/命令行,输入以下命令验证:
PLAINTEXT
node --version
npm --version如果显示版本号,说明安装成功了!
安装 Codex
codex cli
执行:
PLAINTEXT
npm i -g @openai/codex --registry=https://registry.npmmirror.com验证安装:
PLAINTEXT
codex --versioncodex 配置
打开文件资源管理器,找到
~/.codex文件夹(不存在则创建)
创建
config.toml文件 和auth.json
使用文本编辑器打开
config.toml,添加以下内容:
PLAINTEXT
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"打开
auth.json文件,添加以下内容,将your-api-key-here替换为自己的API key:
PLAINTEXT
{
"OPENAI_API_KEY": "your-api-key-here"
}关闭命令行窗口,重新打开,输入
codex
Linux
安装 Node.js
需要 Node.js 环境才能运行(需 v18 或更高版本)。
方法一:使用包管理器(推荐)
Ubuntu / Debian:
PLAINTEXT
# 添加 NodeSource 仓库(Node.js 18 LTS)
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejsCentOS / RHEL / Fedora:
PLAINTEXT
# 添加 NodeSource 仓库(Node.js 18 LTS)
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
sudo yum install -y nodejsArch Linux:
PLAINTEXT
sudo pacman -S nodejs npm方法二:使用 nvm(版本管理器,推荐多版本场景)
PLAINTEXT
# 安装 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方法三:官网下载
下载适合 Linux 的 LTS 版本(需 v18 或更高)
解压并配置环境变量
安装完成后,打开终端,输入以下命令验证:
PLAINTEXT
node --version
npm --version如果显示版本号,说明安装成功了!
安装 Codex
codex cli
执行:
PLAINTEXT
npm i -g @openai/codex --registry=https://registry.npmmirror.com验证安装:
PLAINTEXT
codex --versioncodex 配置
找到
~/.codex文件夹(不存在则创建)
创建
config.toml文件 和auth.json
使用文本编辑器打开
config.toml,添加以下内容:
PLAINTEXT
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打开
auth.json文件,添加以下内容,将your-api-key-here替换为自己的API key:
PLAINTEXT
{
"OPENAI_API_KEY": "your-api-key-here"
}关闭命令行窗口,重新打开,输入
codex
