From 166a97e3690bac17d5e7ac0bc0bd7dbedb4c5ca5 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 6 Aug 2026 21:17:56 -0700 Subject: [PATCH] fix(anthropic adapter): type _handle_choiceless_chunk param as ModelResponseStream --- .../experimental_pass_through/adapters/streaming_iterator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 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 aeb990c7bb4..1660f56378f 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py @@ -348,7 +348,7 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): merged_chunk["context_management"] = ContextManagementResponse(applied_edits=list(self.applied_edits)) return self._augment_message_delta_usage(merged_chunk) - def _handle_choiceless_chunk(self, chunk: Any) -> bool: + def _handle_choiceless_chunk(self, chunk: "ModelResponseStream") -> bool: """Consume an OpenAI-compatible chunk that carries no ``choices``. ``choices`` is legitimately empty on metadata-only chunks; the final @@ -361,7 +361,7 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): into the held stop-reason chunk); False when the chunk should be skipped entirely. """ - if self.holding_stop_reason_chunk is not None and getattr(chunk, "usage", None) is not None: + if self.holding_stop_reason_chunk is not None and _optional_attr(chunk, "usage") is not None: self.chunk_queue.append(self._merge_usage_into_held_stop_reason_chunk(chunk)) self.queued_usage_chunk = True self.holding_stop_reason_chunk = None