claude-code-hub icon indicating copy to clipboard operation
claude-code-hub copied to clipboard

供应商支持http转换为websocket协议

Open 251392463 opened this issue 6 months ago • 10 comments

问题背景: 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)

Image

相关问题: https://github.com/router-for-me/CLIProxyAPI/issues/3530 https://linux.do/t/topic/2236806?u=jasper007

251392463 avatar May 25 '26 08:05 251392463

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:

  1. 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.create frames (line 360-363)
    • Receives upstream WS events and re-emits them as SSE for downstream
    • Supports persistent sessions for previous_response_id continuation
  2. src/app/v1/_lib/responses-ws/eligibility.ts - The eligibility gate. Currently requires ALL of:

    • Client must connect via WebSocket (x-cch-client-transport: websocket header, set by server.js)
    • Provider type must be codex (line 95)
    • System setting enableOpenaiResponsesWebsocket must be on (line 104)
    • Endpoint must not be in the WS-unsupported cache (line 114)
  3. 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:

  1. Provider-level configuration (src/types/provider.ts, the Provider interface) - Add a new field (e.g., upstreamWsMode or forceUpstreamWs) to allow per-provider WS upgrade configuration, independent of client transport.

  2. 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.

  3. 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.

  4. Protocol scope - The current upstream-adapter.ts only supports the OpenAI Responses API format (response.create frame 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

github-actions[bot] avatar May 25 '26 09:05 github-actions[bot]

看到0.8.1发版好像又说支持了,,但是实际测试还是不支持。搞不懂。

ceozero avatar May 25 '26 10:05 ceozero

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.

github-actions[bot] avatar Jun 24 '26 01:06 github-actions[bot]

所以说这个问题确实还没有修复吗? 本来我之前用的也是 cch -> sub2api, 不支持ws的话, 只能直接用sub2api了

bufferducky avatar Jun 29 '26 10:06 bufferducky

@ding113 使用最新版本还是会报 Falling back from WebSockets to HTTPS transport. stream disconnected before completion: failed to send websocket request: Connection closed normally 麻烦看下是否是BUG

bxhzzx avatar Jul 11 '26 14:07 bxhzzx

hi,目前 OpenAI 的 WebSocket 依然不是必选项,客户端会有 fallback,不会影响正常使用。 由于架构演进的需要,WebSocket 的支持将被延后到重构版本 CCHP 中提供。

ding113 avatar Jul 11 '26 14:07 ding113

好吧, 谢谢佬的解答

bxhzzx avatar Jul 11 '26 14:07 bxhzzx

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.

github-actions[bot] avatar Aug 10 '26 00:08 github-actions[bot]

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.

github-actions[bot] avatar Aug 31 '26 01:08 github-actions[bot]

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.

github-actions[bot] avatar Sep 15 '26 02:09 github-actions[bot]