Codex CLI 配置参考
本页用于手动配置、模型参数说明和排障。日常使用默认推荐先看CC Switch 统一配置。
配置方式一:CC Switch(默认推荐)
CC Switch 是最简单的配置方式,自动写入config.toml和auth.json,无需手动编辑文件。完整步骤、渠道与模型对应关系见CC Switch 统一配置。
配置步骤:
- 打开 CC Switch,框架选Codex,点击"添加配置"
- 请求地址填写
https://duoapi.zeabur.app(不要以/结尾) - 填写 API Key(
sk-xxx) - 点击添加,应用后重启终端
配置方式二:手动编辑配置文件
文件位置
| 系统 | config.toml | auth.json |
|---|---|---|
| Windows | C:\Users\<USERNAME>\.codex\config.toml | C:\Users\<USERNAME>\.codex\auth.json |
| macOS / Linux | ~/.codex/config.toml | ~/.codex/auth.json |
config.toml
model_provider = "duoduo"
model = "gpt-5.4"
model_reasoning_effort = "high"
disable_response_storage = true
[model_providers.duoduo]
name = "duoduo"
base_url = "https://duoapi.zeabur.app/v1"
wire_api = "responses"
requires_openai_auth = true
model_context_window = 1000000
model_auto_compact_token_limit = 900000
Codex 的 Base URL需要
/v1后缀,与 Claude Code 不同。
1M 上下文配置
如果你当前使用的是支持长上下文的 Codex 接入方案,建议同时确认以下两项:
model_context_window = 1000000
model_auto_compact_token_limit = 900000
含义分别是:
| 参数 | 作用 |
|---|---|
model_context_window | 将可用上下文窗口设为 1,000,000 |
model_auto_compact_token_limit | 接近上限前提前触发压缩,避免对话直接撞满 |
如果你通过 CC Switch 一键写入配置,优先以 CC Switch 生成结果为准;只有在手动排障时才建议自己改config.toml。
auth.json
{
"OPENAI_API_KEY": "sk-xxx"
}
配置参数说明
| 参数 | 说明 | 可选值 |
|---|---|---|
model_provider | 模型提供商标识 | 自定义名称 |
model | 使用的模型 | 见下方模型列表 |
model_reasoning_effort | 推理深度 | low/medium/high |
disable_response_storage | 禁用响应存储 | true(推荐) |
wire_api | API 协议 | responses |
支持的模型
| 模型 | 说明 |
|---|---|
gpt-5.4 | 最新版本(推荐) |
gpt-5.3-codex | 稳定版本 |
gpt-5.3 | GPT-5.3 标准版 |
gpt-5.2-codex | 上一代稳定版 |
gpt-5.2 | GPT-5.2 标准版 |
gpt-5.1-codex-max | 最强推理 |
gpt-5.1-codex | 5.1 代码版 |
gpt-5.1 | GPT-5.1 标准版 |
常见问题
Base URL 格式问题
| 工具 | Base URL 格式 |
|---|---|
| Claude Code | https://站点地址(不带 /v1) |
| Codex | https://站点地址/v1(带 /v1) |
外接调用返回 403 block?
如果你不是直接使用官方默认链路,而是把 Codex 接到第三方平台、网关、自定义客户端或其他外接场景,除了 Base URL 和 API Key 之外,还要同时满足:
- 使用 Codex 对应分组:
codex0.3 - 请求头中携带 Codex 对应的
User-Agent
示例:
{
"Authorization": "Bearer sk-xxx",
"User-Agent": "codex_cli_rs/0.77.0 (Windows 10.0.26100; x86_64) WindowsTerminal"
}
缺少对应 UA 时,常见报错就是403 block或403 Forbidden。
如果你外接的不是 Codex,也同样需要按对应类型补User-Agent;不要把“只有 Codex 才要 UA”当成通用规则。
API Key 无效?
- 检查
~/.codex/auth.json中的 Key 是否正确 - 确认中转站余额充足
- 确认 Token 未过期
推理速度慢?
将model_reasoning_effort从high改为medium或low,响应速度可显著提升。
同时使用 Claude Code 和 Codex?
两者配置文件独立,互不冲突。使用 CC Switch 可统一管理:
- Claude Code →
~/.claude/settings.json - Codex →
~/.codex/config.toml+~/.codex/auth.json
外接分组与 UA 的统一说明见外接调用 User-Agent 说明。