From 108798b78f4583699d35296258a5d5b99be36fb7 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 27 May 2026 14:29:29 +0000 Subject: [PATCH] fix(anthropic): flush held content chunk in async streaming path Mirror the sync __next__ behavior: always flush a buffered holding_chunk after the stream ends, even when usage was already merged + emitted. Previously the async __anext__ kept the flush inside the 'if not self.queued_usage_chunk:' guard, silently dropping the last content delta on the proxy's primary path. Co-authored-by: Yassin Kortam --- .../adapters/streaming_iterator.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py b/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py index d1e65dad252..3a0775e4b56 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py @@ -614,9 +614,14 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): ) self.holding_stop_reason_chunk = None - if self.holding_chunk is not None: - self.chunk_queue.append(self.holding_chunk) - self.holding_chunk = None + # Always flush any buffered content delta, even when usage has + # already been merged + emitted: dropping it would silently lose + # provider-emitted content, which is worse than the SSE ordering + # nit of trailing a content chunk after the final message_delta + # (the prior async ``__anext__`` behavior). + if self.holding_chunk is not None: + self.chunk_queue.append(self.holding_chunk) + self.holding_chunk = None if not self.sent_last_message: self.sent_last_message = True