diff --git a/litellm/integrations/slack_alerting.py b/litellm/integrations/slack_alerting.py index a9aba2f1c..6c855766a 100644 --- a/litellm/integrations/slack_alerting.py +++ b/litellm/integrations/slack_alerting.py @@ -101,7 +101,7 @@ class SlackAlerting: pass return request_info - def _response_taking_too_long_callback( + def _response_taking_too_long_callback_helper( self, kwargs, # kwargs to completion start_time, @@ -166,7 +166,7 @@ class SlackAlerting: return time_difference_float, model, api_base, messages = ( - self._response_taking_too_long_callback( + self._response_taking_too_long_callback_helper( kwargs=kwargs, start_time=start_time, end_time=end_time, @@ -182,6 +182,9 @@ class SlackAlerting: and "metadata" in kwargs["litellm_params"] ): _metadata = kwargs["litellm_params"]["metadata"] + request_info = litellm.utils._add_key_name_and_team_to_alert( + request_info=request_info, metadata=_metadata + ) _deployment_latency_map = self._get_deployment_latencies_to_alert( metadata=_metadata @@ -255,6 +258,11 @@ class SlackAlerting: # in that case we fallback to the api base set in the request metadata _metadata = request_data["metadata"] _api_base = _metadata.get("api_base", "") + + request_info = litellm.utils._add_key_name_and_team_to_alert( + request_info=request_info, metadata=_metadata + ) + if _api_base is None: _api_base = "" request_info += f"\nAPI Base: `{_api_base}`" diff --git a/litellm/utils.py b/litellm/utils.py index 24ebcea91..f65ff9af7 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -7914,6 +7914,11 @@ def exception_type( if _vertex_location is not None: extra_information += f"\nvertex_location: {_vertex_location}\n" + # on litellm proxy add key name + team to exceptions + extra_information = _add_key_name_and_team_to_alert( + request_info=extra_information, metadata=_metadata + ) + ################################################################################ # End of Common Extra information Needed for all providers ################################################################################ @@ -11510,3 +11515,25 @@ def _get_base_model_from_metadata(model_call_details=None): if base_model is not None: return base_model return None + + +def _add_key_name_and_team_to_alert(request_info: str, metadata: dict) -> str: + """ + Internal helper function for litellm proxy + Add the Key Name + Team Name to the error + Only gets added if the metadata contains the user_api_key_alias and user_api_key_team_alias + + [Non-Blocking helper function] + """ + try: + _api_key_name = metadata.get("user_api_key_alias", "") + _user_api_key_team_alias = metadata.get("user_api_key_team_alias", "") + if _api_key_name is not None: + request_info = ( + f"\n\nKey Name: `{_api_key_name}`\nTeam: `{_user_api_key_team_alias}`" + + request_info + ) + + return request_info + except: + return request_info