输入关键词搜索

Codex 接入

更新时间: 2026/08/27 10:13:38

Codex CLI 可以通过云信大模型 API 平台(简称 AIHub)的 OpenAI Responses 兼容入口接入。Codex 原生支持 custom provider,使用 Responses wire API,因此 Base URL 应指向 AIHub 的 /v1 根路径。

安装 Codex

  1. Codex 依赖 Node.js 运行环境,安装前请确认已安装 Node.js 18 或更高版本:

    bashnode --version
    
  2. 执行以下命令安装 Codex CLI:

    bashnpm install -g @openai/codex
    
  3. 安装完成后,确认命令可用:

    bashcodex --version
    

Windows 用户可在 PowerShell 中直接运行 Codex;若项目依赖 Linux 原生工具链,建议在 WSL2 中安装并运行。

配置接入凭证

Codex 通过配置文件接入 AIHub,需创建以下两个配置文件。

  1. 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>"
    
  2. 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,不要写成 chatchat_completions
experimental_bearer_token AIHub API Key/访问令牌
model AIHub 模型名称

验证配置

  1. 验证 Responses 端点。

    bashcurl "$AIHUB_BASE_URL/v1/responses" \
      -H "Authorization: Bearer $AIHUB_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "'"$AIHUB_MODEL"'",
        "input": "只回复 OK"
      }'
    
  2. 验证 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 配置,请降低或删除相关配置后重试。
此文档是否对你有帮助?
有帮助
去反馈
  • 安装 Codex
  • 配置接入凭证
  • 验证配置
  • 切换模型
  • 常见问题