The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
_handle_logging_completed_response
Ishaan Jaff35e9bba154a7
diff --git a/litellm/responses/streaming_iterator.py b/litellm/responses/streaming_iterator.pyindex 7325e4e6454..cc8711c3e10 100644--- a/litellm/responses/streaming_iterator.py+++ b/litellm/responses/streaming_iterator.py@@ -6,7 +6,9 @@ from typing import Any, AsyncIterator, Dict, Optional, Unionimport httpxfrom litellm.constants import STREAM_SSE_DONE_STRING+from litellm.litellm_core_utils.asyncify import run_async_functionfrom litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj+from litellm.litellm_core_utils.thread_pool_executor import executorfrom litellm.llms.base_llm.responses.transformation import BaseResponsesAPIConfigfrom litellm.types.llms.openai import (ResponsesAPIStreamEvents,@@ -72,7 +74,7 @@ class BaseResponsesAPIStreamingIterator:== ResponsesAPIStreamEvents.RESPONSE_COMPLETED):self.completed_response = openai_responses_api_chunk- self._handle_completed_response()+ self._handle_logging_completed_response()return openai_responses_api_chunk@@ -81,7 +83,7 @@ class BaseResponsesAPIStreamingIterator:# If we can't parse the chunk, continuereturn None- def _handle_completed_response(self):+ def _handle_logging_completed_response(self):"""Base implementation - should be overridden by subclasses"""pass@@ -128,7 +130,7 @@ class ResponsesAPIStreamingIterator(BaseResponsesAPIStreamingIterator):self.finished = Trueraise e- def _handle_completed_response(self):+ def _handle_logging_completed_response(self):"""Handle logging for completed responses in async context"""asyncio.create_task(self.logging_obj.async_success_handler(@@ -139,6 +141,14 @@ class ResponsesAPIStreamingIterator(BaseResponsesAPIStreamingIterator):))+ executor.submit(+ self.logging_obj.success_handler,+ result=self.completed_response,+ cache_hit=None,+ start_time=self.start_time,+ end_time=datetime.now(),+ )+class SyncResponsesAPIStreamingIterator(BaseResponsesAPIStreamingIterator):"""@@ -181,11 +191,20 @@ class SyncResponsesAPIStreamingIterator(BaseResponsesAPIStreamingIterator):self.finished = Trueraise e- def _handle_completed_response(self):+ def _handle_logging_completed_response(self):"""Handle logging for completed responses in sync context"""- self.logging_obj.success_handler(+ run_async_function(+ async_function=self.logging_obj.async_success_handler,result=self.completed_response,start_time=self.start_time,end_time=datetime.now(),cache_hit=None,)++ executor.submit(+ self.logging_obj.success_handler,+ result=self.completed_response,+ cache_hit=None,+ start_time=self.start_time,+ end_time=datetime.now(),+ )