unexpected status 502 Bad Gateway Codex
Quick fix
Set 127.0.0.1 to direct in your proxy software, or configure NO_PROXY in the Codex environment, so the local proxy is not intercepted.
Symptom
Section titled “Symptom”unexpected status 502 Bad Gateway: Unknown error, url: http://127.0.0.1:15721/v1/responsescc-switch never returns a 502 of its own accord. The error happens because local proxy software (Clash, Clash Verge) intercepts requests bound for 127.0.0.1, or because the Codex reqwest library reads the system proxy environment variables and the request is hijacked into the proxy software. The proxy does not recognise the /v1/responses path and returns 502 Bad Gateway. In some cases it instead shows as a failed WebSocket upgrade reporting stream disconnected before completion.
In your proxy software config (Clash, for example), force the local address to direct mode, and make sure the rule comes first.
Clash 配置文件 rules:- DOMAIN-SUFFIX,localhost,DIRECT- IP-CIDR,127.0.0.0/8,DIRECT,no-resolveAlternatively, add NO_PROXY to the Codex environment variable file so Codex bypasses the proxy and connects directly when reaching the local cc-switch.
~/.codex/.env HTTP_PROXY=http://127.0.0.1:7890/HTTPS_PROXY=http://127.0.0.1:7890/NO_PROXY=127.0.0.1,localhost,::1With software such as Clash Verge, try turning system proxy mode off and taking over traffic in TUN mode instead.
Affected Versions
Section titled “Affected Versions”Source Issues
Section titled “Source Issues”This page is distilled from 7 real issues
- #2662mac intel电脑codex接其他的api错误
- #3529使用3.16.1版本,按照教程使用codex配置deepseek,启动路由,启动codex提问,发生错误
- #3989使用DEEPSEEK报错unexpected status 502 Bad Gateway: Unknown error, url: http://127.0.0.1:15721/v1/responses
- #4686Unexpected status 502 Bad Gateway: Unknown error, url: http://127.0.0.1:15721/v1/responses
- #4773unexpected status 502 Bad Gateway: Unknown error, url: http://127.0.0.1:57321/v1/responses
- #4789[Bug] Windows 11 + Clash Verge 系统代理模式:Codex 经 cc-switch 转发 502;切到 TUN 模式/关代理后立即恢复(Claude Code 不受影响)
- #6544关于登录遇到的问题
- Why does Claude Code work while only Codex reports 502?
- The Codex Rust CLI uses the reqwest library, which reads system proxy environment variables, so requests get hijacked into the proxy software. Claude Code is unaffected by those variables and reaches cc-switch directly.
- I changed the Clash rules and it still does not work. What now?
- Make sure the DIRECT rules for localhost and 127.0.0.0/8 sit at the very top of the rule list (highest priority), or turn the system proxy off entirely and switch to TUN mode.
Related problems
Section titled “Related problems”This is an unofficial community wiki with no affiliation to the cc-switch authors or the project itself. Its content is compiled from the project's public GitHub issues. This site distributes no software.