Skip to content

Codex CLI 自定义 Provider 报错全解:stream disconnected、401、404 与 wire_api ​

在 ~/.codex/config.toml 里接入第三方网关后,一发消息就报 unexpected status 404、401、wire_api = "chat" is no longer supported,或者输出一半断流报 stream disconnected before completion——这些报错文本直接来自 Codex CLI(codex-rs)源码,按下面对号入座,改一两行配置就能彻底修好。

标准可用配置模板(直接抄这一份即可避开 95% 的坑)

把以下内容放在 ~/.codex/config.toml 最顶部(注意顶层字段必须在 [model_providers.byesu] 之前):

toml
model = "gpt-6.2-sol"
model_provider = "byesu"

[model_providers.byesu]
name = "byesu"
base_url = "https://byesu.com/v1"
env_key = "BYESU_API_KEY"
wire_api = "responses"

然后在终端执行 export BYESU_API_KEY="sk-YOUR_TOKEN" 后启动 codex。完整步骤见 Codex CLI 接入指南。

报错一:wire_api = "chat" is no longer supported ​

text
`wire_api = "chat"` is no longer supported.
How to fix: set `wire_api = "responses"` in your provider config.

原因与修复: 早期网贴常教大家给兼容网关写 wire_api = "chat",但当前版本的 Codex CLI 已全面切至 OpenAI Responses API 并移除了 chat 模式。

  • 将 wire_api 改为 "responses"(或删掉该行,默认即为 "responses");
  • 半页酥(byesu)原生支持 https://byesu.com/v1/responses,搭配 gpt-6.2-sol、gpt-6.2-astra、gpt-6.1-sol 开箱即用。

报错二:unexpected status 404 Not Found ​

报错末尾的 url: 字段已经把案发现场打印出来了:

你在 config.toml 里写的 base_urlCodex 实际拼接请求的 URL结果
https://byesu.com(漏了 /v1)https://byesu.com/responses404(注意这跟 Claude Code 不带 /v1 正好相反!)
https://byesu.com/v1/responses(多写了路径)https://byesu.com/v1/responses/responses404
https://byesu.com/v1https://byesu.com/v1/responses正常 200

如果 URL 已经是 https://byesu.com/v1/responses 仍报 404 或无可用渠道,请核对 model 是否写成了已退役快照(如 2026-07-23 已关停的 gpt-5-codex / gpt-5.1-codex),改成当前在售的 gpt-6.2-sol 或 gpt-6.1-sol。

报错三:unexpected status 401 或 Missing environment variable ​

  1. Missing environment variable: BYESU_API_KEY:config.toml 里写的是环境变量名字(env_key = "BYESU_API_KEY"),不是直接把 sk-... 填进 env_key!真正的令牌要在启动终端里 export BYESU_API_KEY="sk-YOUR_TOKEN"。
  2. 401 Unauthorized:检查 [model_providers.byesu] 里是不是误加了 requires_openai_auth = true。一旦开启该项,Codex 会强制读取 codex login 存下的官方账号凭证并忽略 env_key——把 requires_openai_auth 删掉即可。

报错四:model_provider 被无视,仍然连往官方接口 ​

两个隐藏的 TOML 规则:

  1. 表头作用域污染:如果你把 model_provider = "byesu" 写在了 [mcp_servers.xxx] 或 [projects.xxx] 下面,TOML 解析器会把它当成那个子表的属性,顶层根本没读到。务必把 model 和 model_provider 放在文件第一行、任何 [...] 方括号之前。
  2. 项目级配置限制:仓库目录里的 .codex/config.toml 出于安全限制不允许自定义 model_providers,请写在用户主目录 ~/.codex/config.toml。

报错五:stream disconnected before completion ​

text
stream disconnected before completion: stream closed before response.completed
stream disconnected before completion: idle timeout waiting for SSE

说明 SSE 流在收到最终 response.completed 事件前被掐断或超时(Codex 默认已自动重试 5 次):

  • 排查本地代理缓冲:部分透明代理或公司防火墙会缓存或截断长连接 SSE,可先用 curl https://byesu.com/v1/responses ... 直连对比;
  • 超长推理心跳等待:跑 gpt-6.2-astra 高强度推理(xhigh)处理超大仓库时,可在 provider 配置下适当调大 stream_idle_timeout_ms = 600000。

遇到问题?联系客服或加交流群。