修复 Codex 在"多资源 Azure OpenAI 中转"后面的高频报错:
The requested item was created under a different Azure OpenAI resource.
Use the same resource that created the item to access it.
一个本地小代理,无第三方依赖。启动后把 Codex 的 base_url 指到它即可。
- Azure OpenAI 的 Responses API 是有状态的:返回的 item(
msg_…、工具调用、rs_…)与加密思维链encrypted_content都按“创建它的那个 Azure 资源”存储和加密。 - 很多中转(one-api 系网关)背后是多个 Azure 资源按请求轮转,不做会话粘性;同一个会话的相邻两次请求可能落在不同资源上。
- Codex 每轮会把整个历史原样回传,包括服务端 id 与加密思维链。请求一旦落到非原资源,就会被 Azure 拒绝(400),常见两类文案:
The requested item was created under a different Azure OpenAI resource. …
The encrypted content for item rs_… could not be verified. Reason: …
本代理在转发前把这类“绑定在资源上”的状态剥离,让每个请求都变成任何资源都能接受的无状态形态。
仅对 POST /v1/responses 生效,其它路径原样透传:
| 剥离项 | 说明 |
|---|---|
input 里每个 item 的 id |
msg_… / ctc_… / rs_… 等 |
所有 encrypted* 字段 |
加密思维链等 |
顶层 previous_response_id |
服务端状态链 |
消息正文、工具调用(call_id 与参数)、请求头、响应 SSE 流全部原样透传。
真实故障时段实测:带状态的请求形态失败率 50–80%;剥离后的形态 16/16 通过,真实 Codex 客户端经本代理端到端会话也全部 200。
依赖:Python 3.8+,无第三方库。Windows 下 python codex_strip_proxy.py 同样可用。
# 1) 获取并启动(默认监听 127.0.0.1:8899,默认上游 https://agentrouter.org)
git clone https://github.com/AnnaofArendelle/codex-strip-proxy.git
cd codex-strip-proxy
python3 -I codex_strip_proxy.py
# 自定义端口 / 上游:
python3 -I codex_strip_proxy.py 8899 https://你的中转域名后台常驻,任选其一:
# nohup
nohup python3 -I codex_strip_proxy.py >/tmp/codex_strip_proxy.out 2>&1 &systemd user service(把路径换成脚本实际路径):
# ~/.config/systemd/user/codex-strip-proxy.service
[Unit]
Description=codex strip proxy
[Service]
ExecStart=/usr/bin/python3 -I /path/to/codex_strip_proxy.py
Restart=always
[Install]
WantedBy=default.targetsystemctl --user daemon-reload
systemctl --user enable --now codex-strip-proxy# 2) 修改 ~/.codex/config.toml,把 base_url 指向代理:[model_providers.custom]
base_url = "http://127.0.0.1:8899/v1"改完重启 Codex 会话。VS Code 扩展、桌面 App、CLI 都读这份配置。
日志默认在 /tmp/codex_strip_proxy.log,每个请求一行:
2026-10-18 20:18:03 /v1/responses http=200 stripped=20 req=64161B
stripped:本次剥离的字段数,重放历史时通常大于 0(首轮请求可能为 0)。http:转发到上游的最终状态码,200即成功。
- 模型不再跨轮“接续”隐藏思维链,每轮重新推理;对话内容与工具调用不受影响。
- 只监听
127.0.0.1,不对外暴露。 - 中转侧修复后(会话粘性路由或网关层剥离),把
base_url改回原地址并停掉代理即可。 - 换端口时,记得同步修改
base_url。
升级 Codex 能解决吗? 不能。测试覆盖的 0.162 / 0.163 版本都会在重放中携带服务端 id 与加密思维链(已抓包验证)。
wire_api = "chat" 能绕开吗?
多数中转对这类模型只开放 /responses,chat completions 会被直接拒绝。
适用于其它中转吗? 适用。只要上游是“Responses API + 多资源 Azure 后端 + 无会话粘性”的组合,把代理的上游地址换成对应域名即可。
codex-strip-proxy is a tiny local proxy that works around Codex errors such as
The requested item was created under a different Azure OpenAI resource.
when using a relay that load-balances requests across several Azure OpenAI
resources. It removes resource-bound state (item ids, encrypted reasoning
content, previous_response_id) from /v1/responses requests before
forwarding, so any resource in the pool can serve the request.
Run python3 codex_strip_proxy.py [port] [upstream], then point base_url
in ~/.codex/config.toml to http://127.0.0.1:8899/v1.