Codex CLI

Codex CLI 通过自定义 Provider,以 OpenAI Responses 接入 ApiGo。Base URL 使用 https://api.apigo.ai/v1,最终请求 /v1/responses。

从模型详情一键复制

打开 模型目录,选择目标模型,再打开 快速接入 → Codex CLI。选择 临时命令(Temporary command) 可只执行一次接入;选择 配置文件(Configuration file) 可保留 config.toml 配置。模型 ID 会自动填入。

只有 Chat Completions 或 Messages 的模型不适用这套配置。快速接入要求模型目录提供 Responses;编程任务还需要验证流式输出和工具调用。

安装

npm install -g @openai/codex
codex --version

各平台安装说明见 Codex CLI 官方指南。

1. 临时命令

只需在本次启动中使用 ApiGo Provider 时,采用此方式。先在 工作空间 → API Keys 创建密钥,再替换占位符后运行命令。

macOS / Linux

export APIGO_API_KEY='YOUR_APIGO_API_KEY'

codex --model 'YOUR_MODEL_ID' \
  -c 'model_provider="apigo"' \
  -c 'model_providers.apigo.name="ApiGo"' \
  -c 'model_providers.apigo.base_url="https://api.apigo.ai/v1"' \
  -c 'model_providers.apigo.env_key="APIGO_API_KEY"' \
  -c 'model_providers.apigo.wire_api="responses"'

Windows PowerShell

$env:APIGO_API_KEY = 'YOUR_APIGO_API_KEY'

codex --model 'YOUR_MODEL_ID' `
  -c 'model_provider="apigo"' `
  -c 'model_providers.apigo.name="ApiGo"' `
  -c 'model_providers.apigo.base_url="https://api.apigo.ai/v1"' `
  -c 'model_providers.apigo.env_key="APIGO_API_KEY"' `
  -c 'model_providers.apigo.wire_api="responses"'

此命令只覆盖本次启动。选择的模型仍须支持 ApiGo Responses。

2. 配置文件

创建或编辑 ~/.codex/config.toml(Windows:%USERPROFILE%\.codex\config.toml)。将 YOUR_MODEL_ID 替换为 ApiGo 的准确模型 ID:

model = "YOUR_MODEL_ID"
model_provider = "apigo"

[model_providers.apigo]
name = "ApiGo"
base_url = "https://api.apigo.ai/v1"
env_key = "APIGO_API_KEY"
wire_api = "responses"

model、model_provider 必须位于顶层,即任何 [table] 之前。已有 apigo 配置块时合并字段,不要重复追加;保留其它设置,密钥不写入 TOML。

旧教程中的 wire_api = "chat" 不适用于本指南。不要同时配置 env_key 和 [model_providers.apigo.auth],应选择一种鉴权方式;本例只使用 env_key。参见 官方 Provider 配置。

设置 API Key

先在 工作空间 → API Keys 创建密钥,再替换占位符。

macOS / Linux

export APIGO_API_KEY='YOUR_APIGO_API_KEY'

Windows PowerShell

$env:APIGO_API_KEY = 'YOUR_APIGO_API_KEY'

从同一个终端启动 Codex。需要持久化时,将赋值语句加入 ~/.zshrc、~/.bashrc 或 PowerShell $PROFILE,然后重新打开终端。不要将真实凭据提交到仓库。

启动与切换模型

codex --model 'YOUR_MODEL_ID'

为新会话覆盖已保存的模型:

codex --model 'ANOTHER_MODEL_ID'

该参数只更换模型,不更换 Provider。目标模型同样需要支持 ApiGo Responses。如果项目配置或已选 profile 改变了默认设置,请检查当前启用的 Provider。

可选:独立 ApiGo profile

在使用文件式 profile 的版本中,可以把同一份配置保存到 ~/.codex/apigo.config.toml,保留原来的默认 Provider。然后运行:

codex --profile apigo

该 profile 会覆盖 ~/.codex/config.toml 中的对应设置。旧版本可能采用不同的 profile 格式,请按已安装版本的文档配置,不要混用;前面的默认 config.toml 方案无需 profile。参见 Profile 参考。

3. 验证请求

让 Codex 只读总结当前目录。到 调用日志 核对模型、最终状态和用量,再用测试项目验证一次工具调用、结果回传与完整流式回答。HTTP 200 或收到第一个 Token 不代表整条流程已完成。

故障排除

现象 检查项
缺少 APIGO_API_KEY 或 401 启动 Codex 的终端必须已设置变量,密钥本身也需有效。
重复字段或 TOML 解析错误 合并字段而非重复追加 Provider 块;顶层字段不能放在其它表内。
404 或协议错误 Base URL 带 /v1,不带 /responses;使用 wire_api = "responses"。
模型不可用 准确 ID、Responses 协议、API Key 模型权限及 Workspace 可用性。
请求发往其它服务 当前 model_provider、项目设置和选中的 profile;无需删除其它 Provider 的凭据。
工具或流式失败 查看失败请求;单纯调大超时不能补齐 Responses 事件或工具支持。

只有确认目标路由支持后,再设置推理强度、搜索或上下文等模型特定选项。

相关文档:Claude Code · 模型目录 · 用量与日志。