Repository navigation
fix(streaming): handle anthropic ping chunk silently #2089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -304,6 +304,23 @@ export function transformStreamingToOpenai( | |
| ], | ||
| usage: normalizeAnthropicUsage(data.usage), | ||
| }; | ||
| } else if (data.type === "ping") { | ||
| transformedData = { | ||
| id: data.id ?? `chatcmpl-${Date.now()}`, | ||
| object: "chat.completion.chunk", | ||
| created: data.created ?? Math.floor(Date.now() / 1000), | ||
| model: data.model ?? usedModel, | ||
| choices: [ | ||
| { | ||
| index: 0, | ||
| delta: { | ||
| role: "assistant", | ||
| }, | ||
| finish_reason: null, | ||
| }, | ||
| ], | ||
| usage: normalizeAnthropicUsage(data.usage), | ||
| }; | ||
|
||
| } else { | ||
| logger.warn("[streaming] Unrecognized Anthropic chunk", { | ||
| provider: usedProvider, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anthropic
pingis a keepalive with no user-visible delta; transforming it into an OpenAIchat.completion.chunkadds extra downstream SSE traffic and can interfere with buffering logic that forwards chunks whendelta.roleis present (seeapps/gateway/src/chat/chat.ts:6443-6453). Consider returningnullhere (like the OpenAIkeepalivecase) or emitting an actually-empty delta (norole) so ping events are ignored instead of forwarded.