供应商支持http转换为websocket协议
问题背景: 2026年5月23号开始,openai 报错: Post "https://chatgpt.com/backend-api/codex/responses": http2: timeout awaiting response headers" 需要转换为wss协议才能解决超时问题
解决措施: codex 开启ws 、 sub2api开启wss, 然后就不报错了
核心诉求: cch 可以支持供应商http协议转换成wss协议,这样可以减少客户端的配置项; 访问链路:client (http/sse) -> cch(ws) -> sub2api(ws) -> openai(ws)
相关问题: https://github.com/router-for-me/CLIProxyAPI/issues/3530 https://linux.do/t/topic/2236806?u=jasper007
Thank you for this feature suggestion. I have analyzed the codebase thoroughly and can provide a detailed assessment.
Current State
CCH already has a WebSocket upstream adapter for the OpenAI Responses API, but it currently only activates when the client also connects via WebSocket.
Key existing code:
-
src/app/v1/_lib/responses-ws/upstream-adapter.ts- The core WS upstream adapter. It already:- Converts HTTP URLs to WSS URLs (
toWsUrl, line 140-144) - Sends request bodies as WS
response.createframes (line 360-363) - Receives upstream WS events and re-emits them as SSE for downstream
- Supports persistent sessions for
previous_response_idcontinuation
- Converts HTTP URLs to WSS URLs (
-
src/app/v1/_lib/responses-ws/eligibility.ts- The eligibility gate. Currently requires ALL of:- Client must connect via WebSocket (
x-cch-client-transport: websocketheader, set byserver.js) - Provider type must be
codex(line 95) - System setting
enableOpenaiResponsesWebsocketmust be on (line 104) - Endpoint must not be in the WS-unsupported cache (line 114)
- Client must connect via WebSocket (
-
src/app/v1/_lib/proxy/forwarder.ts(around line 2893-2986) - The forwarder already attempts the WS path before falling back to HTTP, but only after passing the eligibility check above.
The gap
Your request is specifically: allow CCH to upgrade the upstream connection to WebSocket even when the client connects via regular HTTP/SSE. The current evaluateResponsesWsEligibility() function (eligibility.ts:85-129) blocks this because isWebsocketClientRequest() (eligibility.ts:48-64) requires the x-cch-client-transport: websocket header AND a valid internal secret from server.js, which only exists when the client itself used WebSocket.
Implementation Considerations
To support client (http/sse) -> cch(ws) -> upstream(ws), the following areas would need changes:
-
Provider-level configuration (
src/types/provider.ts, theProviderinterface) - Add a new field (e.g.,upstreamWsModeorforceUpstreamWs) to allow per-provider WS upgrade configuration, independent of client transport. -
Eligibility logic (
src/app/v1/_lib/responses-ws/eligibility.ts) - Add an alternative eligibility path that checks the provider-level WS setting without requiring the client to also be on WebSocket. -
Forwarder dispatch (
src/app/v1/_lib/proxy/forwarder.ts, line ~2893) - Extend the existing WS attempt logic to also trigger for the new provider-level setting. -
Protocol scope - The current
upstream-adapter.tsonly supports the OpenAI Responses API format (response.createframe type). If the goal includes WS upgrade for non-Responses endpoints (e.g.,/v1/chat/completions), additional frame protocol handling would be needed.
Related Issues
- #1095 - Requesting OpenAI WebSocket release
- #969 - Requesting Codex WebSocket mode override support
- #1150 - Fixed a WS connection reset issue for Codex + CPA upstream
Automated response from Claude AI
看到0.8.1发版好像又说支持了,,但是实际测试还是不支持。搞不懂。
This issue has been automatically marked as stale because it has not had any activity in the last 30 days.
If this issue is still relevant:
- Please comment to keep it open
- Add any new information that might help resolve it
This issue will be automatically closed in 14 days if there is no further activity.
所以说这个问题确实还没有修复吗? 本来我之前用的也是 cch -> sub2api, 不支持ws的话, 只能直接用sub2api了
@ding113 使用最新版本还是会报 Falling back from WebSockets to HTTPS transport. stream disconnected before completion: failed to send websocket request: Connection closed normally 麻烦看下是否是BUG
hi,目前 OpenAI 的 WebSocket 依然不是必选项,客户端会有 fallback,不会影响正常使用。 由于架构演进的需要,WebSocket 的支持将被延后到重构版本 CCHP 中提供。
好吧, 谢谢佬的解答
This issue has been automatically marked as stale because it has not had any activity in the last 30 days.
If this issue is still relevant:
- Please comment to keep it open
- Add any new information that might help resolve it
This issue will be automatically closed in 14 days if there is no further activity.
This issue has been automatically marked as stale because it has not had any activity in the last 30 days.
If this issue is still relevant:
- Please comment to keep it open
- Add any new information that might help resolve it
This issue will be automatically closed in 14 days if there is no further activity.
This issue has been automatically closed due to inactivity.
If you believe this issue is still relevant, please feel free to reopen it with additional information.