diff --git a/litellm/llms/anthropic/experimental_pass_through/messages/streaming_iterator.py b/litellm/llms/anthropic/experimental_pass_through/messages/streaming_iterator.py index e0ddd54c24f..a282d5f4d4f 100644 --- a/litellm/llms/anthropic/experimental_pass_through/messages/streaming_iterator.py +++ b/litellm/llms/anthropic/experimental_pass_through/messages/streaming_iterator.py @@ -367,12 +367,6 @@ class BaseAnthropicMessagesStreamingIterator: deferred_dispatch_armed: Final = ( getattr(self.litellm_logging_obj, "_on_deferred_stream_complete", None) is not None ) - # Post-call guardrails run their end-of-stream scan AFTER this iterator - # is exhausted, so enqueueing now would build the spend log before the - # scan writes guardrail_information. Park the coroutine instead; the - # proxy fires it via _fire_deferred_stream_logging once the guardrail - # chain drains. Teardown (client disconnect) keeps enqueueing - # immediately: the scan never runs there and billing must not be lost. if deferred_dispatch_armed and not stream_teardown: self.litellm_logging_obj._deferred_stream_complete_args = (logging_coroutine,) return diff --git a/litellm/proxy/common_request_processing.py b/litellm/proxy/common_request_processing.py index 936ca1607b5..ff6c8d1b1f8 100644 --- a/litellm/proxy/common_request_processing.py +++ b/litellm/proxy/common_request_processing.py @@ -2377,11 +2377,6 @@ class ProxyBaseLLMRequestProcessing: and route_type == "anthropic_messages" and self._is_streaming_response(response) ): - # Native /v1/messages SSE streams bypass CSW, so the raw - # iterator parks its logging coroutine at stream end (see - # BaseAnthropicMessagesStreamingIterator._handle_streaming_logging) - # and _fire_deferred_stream_logging hands it here after the - # guardrail end-of-stream scans complete. from litellm.litellm_core_utils.logging_worker import ( GLOBAL_LOGGING_WORKER, ) diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index 516a50610d0..9fbe1b4bd06 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -3227,12 +3227,6 @@ class ProxyLogging: ), ) - # Actually iterate through the chained async generator and yield chunks. - # A guardrail block raised after upstream exhaustion (e.g. - # unified_guardrail re-raising HTTPException) must still flush any - # parked deferred logging, or the blocked stream loses its spend log. - # GeneratorExit/CancelledError stay untouched: disconnect cleanup owns - # those. try: async for chunk in current_response: yield chunk