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
(fix) slack alerting - don't spam the failed cost tracking alert for the same model (#6543)
Ishaan Jaff9545b0e5cde2
diff --git a/litellm/integrations/SlackAlerting/slack_alerting.py b/litellm/integrations/SlackAlerting/slack_alerting.pyindex dbe9e4161da..85d54a337d1 100644--- a/litellm/integrations/SlackAlerting/slack_alerting.py+++ b/litellm/integrations/SlackAlerting/slack_alerting.py@@ -550,8 +550,14 @@ class SlackAlerting(CustomBatchLogger):alerting_metadata=alerting_metadata,)- async def failed_tracking_alert(self, error_message: str):- """Raise alert when tracking failed for specific model"""+ async def failed_tracking_alert(self, error_message: str, failing_model: str):+ """+ Raise alert when tracking failed for specific model++ Args:+ error_message (str): Error message+ failing_model (str): Model that failed tracking+ """if self.alerting is None or self.alert_types is None:# do nothing if alerting is not switched onreturn@@ -560,7 +566,7 @@ class SlackAlerting(CustomBatchLogger):_cache: DualCache = self.internal_usage_cachemessage = "Failed Tracking Cost for " + error_message- _cache_key = "budget_alerts:failed_tracking:{}".format(message)+ _cache_key = "budget_alerts:failed_tracking:{}".format(failing_model)result = await _cache.async_get_cache(key=_cache_key)if result is None:await self.send_alert(diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yamlindex 95eff095c22..23834f75970 100644--- a/litellm/proxy/proxy_config.yaml+++ b/litellm/proxy/proxy_config.yaml@@ -1,11 +1,11 @@model_list:- model_name: gpt-4olitellm_params:- model: gpt-4o+ model: openai/gpt-5api_key: os.environ/OPENAI_API_KEYapi_base: https://exampleopenaiendpoint-production.up.railway.app/-litellm_settings:- callbacks: ["prometheus"]- service_callback: ["prometheus_system"]- cache: true++general_settings:+ alerting: ["slack"]+ alerting_threshold: 0.001diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex 1f0271f3451..ca6befef603 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -265,6 +265,7 @@ from litellm.types.llms.anthropic import ()from litellm.types.llms.openai import HttpxBinaryResponseContentfrom litellm.types.router import RouterGeneralSettings+from litellm.types.utils import StandardLoggingPayloadtry:from litellm._version import version@@ -778,7 +779,6 @@ async def _PROXY_track_cost_callback(if kwargs.get("response_cost", None) is not None:response_cost = kwargs["response_cost"]user_api_key = metadata.get("user_api_key", None)-if kwargs.get("cache_hit", False) is True:response_cost = 0.0verbose_proxy_logger.info(@@ -838,13 +838,14 @@ async def _PROXY_track_cost_callback(f"Cost tracking failed for model={model}.\nDebug info - {cost_tracking_failure_debug_info}\nAdd custom pricing - https://docs.litellm.ai/docs/proxy/custom_pricing")except Exception as e:- error_msg = f"error in tracking cost callback - {traceback.format_exc()}"+ error_msg = f"Error in tracking cost callback - {str(e)}\n Traceback:{traceback.format_exc()}"model = kwargs.get("model", "")metadata = kwargs.get("litellm_params", {}).get("metadata", {})error_msg += f"\n Args to _PROXY_track_cost_callback\n model: {model}\n metadata: {metadata}\n"asyncio.create_task(proxy_logging_obj.failed_tracking_alert(error_message=error_msg,+ failing_model=model,))verbose_proxy_logger.debug("error in tracking cost callback - %s", e)diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.pyindex 656e97a6c5c..8919da97861 100644--- a/litellm/proxy/utils.py+++ b/litellm/proxy/utils.py@@ -667,13 +667,18 @@ class ProxyLogging:raise ereturn data- async def failed_tracking_alert(self, error_message: str):+ async def failed_tracking_alert(+ self,+ error_message: str,+ failing_model: str,+ ):if self.alerting is None:returnif self.slack_alerting_instance:await self.slack_alerting_instance.failed_tracking_alert(- error_message=error_message+ error_message=error_message,+ failing_model=failing_model,)async def budget_alerts(