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
Use executors in post-logging hooks (#14332)
Arseny Boykov05741a7c824c
diff --git a/litellm/caching/caching_handler.py b/litellm/caching/caching_handler.pyindex 1dcc0f1fdb2..beeb15aa62d 100644--- a/litellm/caching/caching_handler.py+++ b/litellm/caching/caching_handler.py@@ -301,10 +301,12 @@ class LLMCachingHandler:is_async=False,)- threading.Thread(- target=logging_obj.success_handler,- args=(cached_result, start_time, end_time, cache_hit),- ).start()+ logging_obj.handle_sync_success_callbacks_for_async_calls(+ result=cached_result,+ start_time=start_time,+ end_time=end_time,+ cache_hit=cache_hit+ )cache_key = litellm.cache._get_preset_cache_key_from_kwargs(**kwargs)@@ -530,15 +532,17 @@ class LLMCachingHandler:end_time (datetime): The end time of the operation.cache_hit (bool): Whether it was a cache hit."""- asyncio.create_task(- logging_obj.async_success_handler(- cached_result, start_time, end_time, cache_hit+ from litellm.litellm_core_utils.logging_worker import GLOBAL_LOGGING_WORKER++ GLOBAL_LOGGING_WORKER.ensure_initialized_and_enqueue(+ async_coroutine=logging_obj.async_success_handler(+ result=cached_result, start_time=start_time, end_time=end_time, cache_hit=cache_hit))- threading.Thread(- target=logging_obj.success_handler,- args=(cached_result, start_time, end_time, cache_hit),- ).start()++ logging_obj.handle_sync_success_callbacks_for_async_calls(+ result=cached_result, start_time=start_time, end_time=end_time, cache_hit=cache_hit+ )async def _retrieve_from_cache(self, call_type: str, kwargs: Dict[str, Any], args: Tuple[Any, ...]diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.pyindex 0b152e0dda3..4c95d0053fc 100644--- a/litellm/litellm_core_utils/litellm_logging.py+++ b/litellm/litellm_core_utils/litellm_logging.py@@ -2774,6 +2774,7 @@ class Logging(LiteLLMLoggingBaseClass):result: Any,start_time: datetime.datetime,end_time: datetime.datetime,+ cache_hit: Optional[Any] = None,) -> None:"""Handles calling success callbacks for Async calls.@@ -2788,6 +2789,7 @@ class Logging(LiteLLMLoggingBaseClass):result,start_time,end_time,+ cache_hit,)def _should_run_sync_callbacks_for_async_calls(self) -> bool: