From 7039b6da9635cb58e2ff2c809017b98955da723c Mon Sep 17 00:00:00 2001 From: kerry Date: Fri, 25 Sep 2026 00:43:17 +0000 Subject: [PATCH] fix(anthropic-adapter): expose streamed chunks so disconnects bill partial spend Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../adapters/streaming_iterator.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 4486eb0985a..82e4d6d6a1d 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py @@ -119,6 +119,14 @@ class _CombinedChunkSplitter: self._async_iter: AsyncIterator[ModelResponseStream] | None = None self._buffer: deque[ModelResponseStream] = deque() + @property + def chunks(self) -> list | None: + return getattr(self._stream, "chunks", None) + + @property + def messages(self) -> list | None: + return getattr(self._stream, "messages", None) + @staticmethod def _is_combined(chunk: "ModelResponseStream") -> bool: """True if ``chunk`` carries response content AND a finish_reason.""" @@ -355,6 +363,14 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): text="", ) + @property + def chunks(self) -> list | None: + return getattr(self.completion_stream, "chunks", None) + + @property + def messages(self) -> list | None: + return getattr(self.completion_stream, "messages", None) + def _merge_usage_into_held_stop_reason_chunk(self, chunk: Any) -> MessageBlockDelta: """Merge usage data from ``chunk`` into the held ``message_delta`` chunk.