Skip to content

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]

fix proxy pre call hook - only use if user is using alerting (#7683)

Ishaan Jaff2d1c90b688d0
diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py
index 31ea9c80b73..a669c592c3b 100644
--- a/litellm/proxy/utils.py
+++ b/litellm/proxy/utils.py
@@ -473,10 +473,8 @@ class ProxyLogging:
3. /image/generation
"""
verbose_proxy_logger.debug("Inside Proxy Logging Pre-call hook!")
- ## ALERTING ###
- asyncio.create_task(
- self.slack_alerting_instance.response_taking_too_long(request_data=data)
- )
+
+ self._init_response_taking_too_long_task(data=data)
if data is None:
return None
@@ -1012,6 +1010,23 @@ class ProxyLogging:
raise e
return new_response
+ def _init_response_taking_too_long_task(self, data: Optional[dict] = None):
+ """
+ Initialize the response taking too long task if user is using slack alerting
+
+ Only run task if user is using slack alerting
+
+ This handles checking for if a request is hanging for too long
+ """
+ ## ALERTING ###
+ if (
+ self.slack_alerting_instance
+ and self.slack_alerting_instance.alerting is not None
+ ):
+ asyncio.create_task(
+ self.slack_alerting_instance.response_taking_too_long(request_data=data)
+ )
+
### DB CONNECTOR ###
# Define the retry decorator with backoff strategy