From 788cfa3e9a1a98b2f4fffb683d7fe1c080c8452a Mon Sep 17 00:00:00 2001 From: Juan Camilo Date: Wed, 1 Apr 2026 17:03:28 +0200 Subject: [PATCH] fix: handle empty string delta.content in OpenAI streaming Some providers send an empty string as the first delta to signal streaming start. The falsy check `if (delta.content)` treated "" as absent, skipping content_block_start. The next delta with actual content was emitted without it, violating the Anthropic protocol. Changed to `delta.content != null` to distinguish between absent field and empty string. Relates to #42 Co-Authored-By: Juan Camilo --- src/services/api/openaiShim.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/services/api/openaiShim.ts b/src/services/api/openaiShim.ts index f7a5f6b7..a4dfb68b 100644 --- a/src/services/api/openaiShim.ts +++ b/src/services/api/openaiShim.ts @@ -345,8 +345,9 @@ async function* openaiStreamToAnthropic( for (const choice of chunk.choices ?? []) { const delta = choice.delta - // Text content - if (delta.content) { + // Text content — use != null to distinguish absent field from empty string, + // some providers send "" as first delta to signal streaming start + if (delta.content != null) { if (!hasEmittedContentStart) { yield { type: 'content_block_start',