Codex 中转介绍
⚙️ 手动配置
Codex CLI 的 config.toml / auth.json 详细配置参考(含 macOS / Linux / Windows + WebSocket 变体)。
懒人方案:如果不想手改文件,用 CC-Switch 图形化配置 一键搞定。下面是手动配置的完整参考。
配置文件位置
| 平台 | config.toml | auth.json |
|---|---|---|
| macOS / Linux | ~/.codex/config.toml | ~/.codex/auth.json |
| Windows | %userprofile%\.codex\config.toml | %userprofile%\.codex\auth.json |
目录不存在?
- macOS / Linux:
mkdir -p ~/.codex - Windows:按
Win+R,输入%userprofile%\.codex回车,若提示不存在则先在资源管理器手动创建
一、Codex CLI(标准 HTTP)
config.toml
model_provider = "OpenAI"
model = "gpt-5.4"
review_model = "gpt-5.4"
model_reasoning_effort = "xhigh"
disable_response_storage = true
network_access = "enabled"
windows_wsl_setup_acknowledged = true
model_context_window = 1000000
model_auto_compact_token_limit = 900000
[model_providers.OpenAI]
name = "OpenAI"
base_url = "https://nexor.nexoraivision.com"
wire_api = "responses"
requires_openai_auth = true
请确保上面的内容位于
config.toml 文件的开头部分。如果 [model_providers.*] section 出现在其他 section 之后,可能被覆盖。auth.json
{
"OPENAI_API_KEY": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
把 sk-xxxx 换成你在 控制台 生成的 API Key。
二、Codex CLI(WebSocket v2,推荐长会话)
WebSocket 模式用长连接传输流式响应,比 SSE 更稳定,长文本生成不易中断。
config.toml
model_provider = "OpenAI"
model = "gpt-5.4"
review_model = "gpt-5.4"
model_reasoning_effort = "xhigh"
disable_response_storage = true
network_access = "enabled"
windows_wsl_setup_acknowledged = true
model_context_window = 1000000
model_auto_compact_token_limit = 900000
[model_providers.OpenAI]
name = "OpenAI"
base_url = "https://nexor.nexoraivision.com"
wire_api = "responses"
supports_websockets = true
requires_openai_auth = true
[features]
responses_websockets_v2 = true
auth.json
与标准模式完全相同:
{
"OPENAI_API_KEY": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
何时用 WebSocket?
- 长会话(>30 分钟)
- 网络环境不稳(移动热点、跨境)
- 经常出现「流式响应中断」「连接被重置」错误
三、字段详解
| 字段 | 必填 | 默认 | 说明 |
|---|---|---|---|
model_provider | ✅ | — | 固定填 "OpenAI"(中转使用 OpenAI 协议) |
model | ✅ | — | 默认调用的模型,见 模型清单 |
review_model | — | 同 model | 代码审阅子任务用的模型 |
model_reasoning_effort | — | medium | 推理强度:low / medium / high / xhigh |
disable_response_storage | — | false | true 不在中转端存储响应(隐私优先) |
network_access | — | enabled | 允许 Codex 访问网络(curl、fetch 等) |
windows_wsl_setup_acknowledged | — | false | Windows 下设 true 跳过 WSL 提示 |
model_context_window | — | 模型默认 | 上下文窗口大小(不超过模型上限) |
model_auto_compact_token_limit | — | 0(不压缩) | 超过此 Token 数后自动压缩历史会话 |
base_url | ✅ | — | 中转地址:https://nexor.nexoraivision.com |
wire_api | ✅ | responses | 协议:responses(新 Responses API) |
requires_openai_auth | — | false | 必须设 true,否则 Bearer 头不会带上 |
supports_websockets | — | false | WebSocket 模式时设 true |
responses_websockets_v2 | — | false | WebSocket v2 功能开关 |
模型清单
文本模型(用于 Codex CLI)
| 模型 ID | 显示名 | 上下文 | 输出 | 推荐场景 |
|---|---|---|---|---|
gpt-5.5 | GPT-5.5 | 1,050K | 128K | 超长上下文、整库重构 |
gpt-5.4 | GPT-5.4 | 1,050K | 128K | 默认推荐,平衡性能与成本 |
gpt-5.4-mini | GPT-5.4 Mini | 400K | 128K | 轻量任务、高频补全 |
gpt-5.3-codex | GPT-5.3 Codex | 400K | 128K | 代码专用,长上下文 |
gpt-5.3-codex-spark | GPT-5.3 Codex Spark | 128K | 32K | 快速代码补全 |
gpt-5.2 | GPT-5.2 | 400K | 128K | 老版本兼容、稳定基线 |
所有文本模型支持 4 档推理强度:low / medium / high / xhigh。
图像模型(用于 Images API)
| 模型 ID | 显示名 | 用途 |
|---|---|---|
gpt-image-2 | GPT Image 2 | 推荐最新,文生图 + 参考图编辑 |
gpt-image-1.5 | GPT Image 1.5 | 上一代版本 |
gpt-image-1 | GPT Image 1 | 经典稳定版 |
服务功能
| 功能 | 说明 |
|---|---|
codex-auto-review | Codex 自动代码审查(CI/PR 集成),详见 自动审查 |
验证配置
# 1. 查看 Codex 是否能加载配置
codex config show
# 2. 测试请求
codex "用 TypeScript 写一个防抖函数"
# 3. 切换模型测试
codex --model gpt-5.5 "解释一下 Go 的 GMP 调度模型"
正常返回结果即配置成功。出错请参考 故障排查。
