Codex 接入
更新时间: 2026/08/27 10:13:38
Codex CLI 可以通过云信大模型 API 平台(简称 AIHub)的 OpenAI Responses 兼容入口接入。Codex 原生支持 custom provider,使用 Responses wire API,因此 Base URL 应指向 AIHub 的 /v1 根路径。
安装 Codex
-
Codex 依赖 Node.js 运行环境,安装前请确认已安装 Node.js 18 或更高版本:
bash
node --version -
执行以下命令安装 Codex CLI:
bash
npm install -g @openai/codex -
安装完成后,确认命令可用:
bash
codex --version
Windows 用户可在 PowerShell 中直接运行 Codex;若项目依赖 Linux 原生工具链,建议在 WSL2 中安装并运行。
配置接入凭证
Codex 通过配置文件接入 AIHub,需创建以下两个配置文件。
-
Provider 配置。
在
~/.codex/config.toml中增加 AIHub provider:toml[general] tls_insecure = true [model_providers.aihub-openai] name = "aihub-openai" base_url = "$AIHUB_BASE_URL/v1" wire_api = "responses" requires_openai_auth = true experimental_bearer_token = "<AIHUB_TOKEN>" -
Profile 配置。
创建默认 profile 文件
~/.codex/aihub-openai.config.toml:tomlmodel = "your-logical-model" model_provider = "aihub-openai"
配置项说明:
| 配置项 | 说明 |
|---|---|
tls_insecure |
true;测试环境若使用自签名证书,需开启此项 |
base_url |
$AIHUB_BASE_URL/v1,不要写成完整的 /v1/responses |
wire_api |
固定为 responses,不要写成 chat 或 chat_completions |
experimental_bearer_token |
AIHub API Key/访问令牌 |
model |
AIHub 模型名称 |
验证配置
-
验证 Responses 端点。
bashcurl "$AIHUB_BASE_URL/v1/responses" \ -H "Authorization: Bearer $AIHUB_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "model": "'"$AIHUB_MODEL"'", "input": "只回复 OK" }' -
验证 Codex。
bashcodex exec --profile aihub-openai "只回复 OK"如果控制台请求日志中出现
/v1/responses请求,说明 Codex 已通过 AIHub 访问模型。
切换模型
Codex 0.134.0 及更高版本不再支持在 config.toml 中写入 [profiles.*]。如需切换不同模型,可为每个逻辑模型分别创建 profile 文件:
toml# ~/.codex/aihub-fast.config.toml
model = "your-fast-logical-model"
model_provider = "aihub-openai"
# ~/.codex/aihub-strong.config.toml
model = "your-strong-logical-model"
model_provider = "aihub-openai"
使用方式:
bashcodex --profile aihub-fast
codex exec --profile aihub-strong "解释这个仓库的入口"
模型名称请以控制台授权模型和 GET $AIHUB_BASE_URL/v1/models 接口返回为准。
常见问题
| 现象 | 排查方向 |
|---|---|
wire_api = chat is no longer supported |
Codex custom provider 配置应使用 wire_api = "responses"。 |
/v1/responses 返回 404 |
base_url 配置错误,应使用 $AIHUB_BASE_URL/v1。 |
401 / unauthorized |
experimental_bearer_token 未填写或令牌已禁用。 |
model not allowed/no candidate |
当前访问令牌未授权该模型,或模型无可用路由。 |
| reasoning 参数报错 | 目标模型不兼容 Codex 的 reasoning 配置,请降低或删除相关配置后重试。 |
此文档是否对你有帮助?




