全部命令在 PowerShell(管理员) 里跑。每条命令前面带
① ② ③编号,照着顺序复制粘贴即可。
打开 https://nodejs.org/ ,下 Node 22 LTS 或更新,全部默认安装。
装完新开 PowerShell,验证:
node -v
npm -v
输出像 v22.x.x 和 10.x.x 就行。
没装的用 npm:
npm install -g @openai/codex --no-audit --no-fund
或者微软官方安装脚本(推荐,连二进制 vendor 一并装好):
irm https://chatgpt.com/codex/install.ps1 | iex
codex --version
输出 codex-cli 0.144.1 即可。
https://api.ai-pioneer.cn/v1sk-ZDUcMtXm 开头加 ai-pioneer provider 段(不动旧的 minimax,保留备用):
$cfg = "$env:USERPROFILE\.codex\config.toml"
$toml = @"
[model_providers.ai-pioneer]
name = "擎创云"
base_url = "https://api.ai-pioneer.cn/v1"
wire_api = "chat_completions"
requires_openai_auth = true
[profiles.hub-flash]
model = "deepseek-v4-flash"
model_provider = "ai-pioneer"
model_reasoning_effort = "high"
[profiles.hub-pro]
model = "deepseek-v4-pro"
model_provider = "ai-pioneer"
model_reasoning_effort = "high"
[profiles.hub-glm]
model = "glm-5.2"
model_provider = "ai-pioneer"
model_reasoning_effort = "high"
[profiles.hub-minimax]
model = "MiniMax-M3"
model_provider = "ai-pioneer"
model_reasoning_effort = "high"
[profiles.hub-claude]
model = "claude-opus-4-8"
model_provider = "ai-pioneer"
model_reasoning_effort = "high"
"@ | Add-Content -Path $cfg -Encoding UTF8
设 OPENAI_API_KEY 环境变量(Codex 从这里读 key,因为 requires_openai_auth = true):
[System.Environment]::SetEnvironmentVariable("OPENAI_API_KEY", "替换sk-擎创云 API密钥", "User")
也可以写到
~/.codex/.env(Codex 0.40+ 支持),但OPENAI_API_KEY是 Codex 默认就会认的环境变量,最省事。不想全局设,就用codex -c "OPENAI_API_KEY=sk-..." exec那种形式(见 ④)。
切默认 provider 到 Hub:
# 用 -replace 改完写回(不动其它字段)
$cfg = "$env:USERPROFILE\.codex\config.toml"
(Get-Content $cfg -Raw) `
-replace '^model_provider = "custom"', 'model_provider = "ai-pioneer"' `
-replace '^model = "MiniMax-M3"', 'model = "deepseek-v4-flash"' `
| Set-Content -Path $cfg -Encoding UTF8
确认配置文件长相正确:
Select-String -Path "$env:USERPROFILE\.codex\config.toml" -Pattern "ai-pioneer|model_provider|wire_api"
期望看到:
model_provider = "ai-pioneer"
model = "deepseek-v4-flash"
[model_providers.ai-pioneer]
wire_api = "chat_completions"
## ④ 验证
跑一句最便宜的模型试链路:
```powershell
codex exec "用一句话中文自我介绍,证明连接成功" -m deepseek-v4-flash
期望看到中文输出。如果返回空 / 报错,跳到末尾「报错自查」。
用 -c 临时覆盖(不动配置文件):
codex exec "ping" -c model="MiniMax-M3" -c model_provider="ai-pioneer"
跑 doctor 看 provider 健康状态:
codex doctor
期望看到 reachability 那行变 ✓(之前本机是 ✗,因为默认 provider 不可达)。
用 responses wire_api 探针确认 Hub 不支持(仅排查用,平时别用):
$body = '{"model":"deepseek-v4-flash","input":"hi","max_output_tokens":8}'
$tmp = "$env:TEMP\probe.json"
[System.IO.File]::WriteAllText($tmp, $body, [System.Text.UTF8Encoding]::new($false))
$env:HTTP_PROXY=''; $env:HTTPS_PROXY=''; $env:ALL_PROXY=''
curl.exe -sS -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $env:OPENAI_API_KEY" --data-binary "@$tmp" "https://api.ai-pioneer.cn/v1/responses"
期望看到 not implemented —— 这就是为什么必须用 wire_api = "chat_completions"。
codex exec "你好" -p hub-flash
codex exec "你好" -p hub-pro
codex exec "你好" -p hub-glm
codex exec "你好" -p hub-minimax
codex exec "你好" -p hub-claude
codex exec "你好" -m glm-5.2
codex exec "你好" -m MiniMax-M3
codex exec "你好" -m deepseek-v4-pro
$cfg = "$env:USERPROFILE\.codex\config.toml"
(Get-Content $cfg -Raw) `
-replace '^model = ".*"', 'model = "MiniMax-M3"' `
| Set-Content -Path $cfg -Encoding UTF8
Select-String -Path "$env:USERPROFILE\.codex\config.toml" -Pattern "^model |^model_provider"
上新模型时去 接入地址.txt 看 Base URL 有没有变;然后在 ~/.codex/config.toml 里加一个 profile:
[profiles.hub-newmodel]
model = "新模型id"
model_provider = "ai-pioneer"
model_reasoning_effort = "high"
加完跑一下:
codex exec "ping" -p hub-newmodel
~/.codex/config.toml:影响所有项目-p <name> 临时切换<你的工程目录>\.codex\config.toml:项目独立配置,Codex 自动读取如果某个仓库想临时切回官方 OpenAI(不动全局),在该仓库根目录放一个 config.toml:
model_provider = "openai"
model = "gpt-5"
进项目时 codex 自动用项目配置。
| 报错 | 处理 |
|---|---|
codex: command not found |
npm bin -g 看全局 bin 目录,加到 PATH;或重开 PowerShell |
OPENAI_API_KEY not set |
回到 ③ 那一段设环境变量;或用 codex -c "OPENAI_API_KEY=sk-..." exec 临时塞 |
wire_api "responses" not supported / not implemented |
把 [model_providers.ai-pioneer].wire_api 改成 chat_completions |
401 / 403 unauthorized |
Key 错或没权限;去 https://api.ai-pioneer.cn/ 检查 Key |
Request not allowed (request id: ...) |
Hub 后台没给这个 Key 开该模型权限;换 Key 或去后台授权 |
model not found |
模型 id 拼错;先跑 curl https://api.ai-pioneer.cn/v1/models 看真名 |
fetch failed / ECONNREFUSED |
清代理:$env:HTTP_PROXY=''; $env:HTTPS_PROXY=''; $env:ALL_PROXY=''; $env:NO_PROXY='*',再重试 |
reachability: ✗ one or more required provider endpoints are unreachable |
codex doctor 看哪个 provider 不通;多半是 base_url 拼错或者代理没清 |
status=200 但回复空 |
余额不足,去 https://api.ai-pioneer.cn/ 充值或换正式 Key |
| TOML parse 报错 | 配置有中文 / 特殊字符没引号;改完用 [System.IO.File]::ReadAllText 重新读一遍确认 |