Skip to content

fix: 为 Anthropic Messages API 流式转发添加下游 keepalive ping#937

Merged
Wei-Shaw merged 1 commit intoWei-Shaw:mainfrom
lxohi:fix/anthropic-stream-keepalive
Mar 12, 2026
Merged

fix: 为 Anthropic Messages API 流式转发添加下游 keepalive ping#937
Wei-Shaw merged 1 commit intoWei-Shaw:mainfrom
lxohi:fix/anthropic-stream-keepalive

Conversation

@lxohi
Copy link

@lxohi lxohi commented Mar 11, 2026

Anthropic Messages API 的流式转发路径(gateway_service.go)在上游长时间 无数据时(如 Opus extended thinking 阶段)不会向下游发送任何内容,导致Cloudflare Tunnel 等代理因连接空闲而断开。

复用已有的 StreamKeepaliveInterval 配置(默认 10 秒),在 select 循环中 添加 keepalive 分支,定时发送 Anthropic 原生格式的 ping 事件保活,与OpenAI 兼容路径的实现模式保持一致。

Anthropic Messages API 的流式转发路径(gateway_service.go)在上游长时间
无数据时(如 Opus extended thinking 阶段)不会向下游发送任何内容,导致
Cloudflare Tunnel 等代理因连接空闲而断开。

复用已有的 StreamKeepaliveInterval 配置(默认 10 秒),在 select 循环中
添加 keepalive 分支,定时发送 Anthropic 原生格式的 ping 事件保活,与
OpenAI 兼容路径的实现模式保持一致。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Wei-Shaw Wei-Shaw merged commit 1e51de8 into Wei-Shaw:main Mar 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants