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
send alert on all key events
Ishaan Jaff4435a2312138
diff --git a/litellm/integrations/slack_alerting.py b/litellm/integrations/slack_alerting.pyindex 0ad403a9790..d0a76ec9635 100644--- a/litellm/integrations/slack_alerting.py+++ b/litellm/integrations/slack_alerting.py@@ -29,8 +29,8 @@ from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandlerfrom litellm.proxy._types import (AlertType,CallInfo,- KeyCreatedEvent,UserAPIKeyAuth,+ VirtualKeyEvent,WebhookEvent,)from litellm.types.router import LiteLLM_Params@@ -1797,7 +1797,7 @@ Model Info:async def send_virtual_key_event_slack(self,- key_event: KeyCreatedEvent,+ key_event: VirtualKeyEvent,event_name: str,):"""@@ -1811,16 +1811,18 @@ Model Info:key_event_dict = key_event.model_dump()# Add Created by information first- message += "*Created by:*\n"+ message += "*Action Done by:*\n"for key, value in key_event_dict.items():if "created_by" in key:message += f"{key}: `{value}`\n"- # Add all non created by information next+ # Add args sent to function in the alertmessage += "\n*Arguments passed:*\n"- for key, value in key_event_dict.items():- if "created_by" not in key:- message += f"{key}: `{value}`\n"+ request_kwargs = key_event.request_kwargs+ for key, value in request_kwargs.items():+ if key == "user_api_key_dict":+ continue+ message += f"{key}: `{value}`\n"await self.send_alert(message=message,diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.pyindex 0533b39628e..deb496f2e91 100644--- a/litellm/proxy/_types.py+++ b/litellm/proxy/_types.py@@ -1756,10 +1756,8 @@ class SSOUserDefinedValues(TypedDict):budget_duration: Optional[str]-class KeyCreatedEvent(LiteLLMBase):+class VirtualKeyEvent(LiteLLMBase):created_by_user_id: strcreated_by_user_role: strcreated_by_key_alias: Optional[str]- key_alias: Optional[str]- team_id: Optional[str]- max_budget: Optional[float]+ request_kwargs: dictdiff --git a/litellm/proxy/management_helpers/utils.py b/litellm/proxy/management_helpers/utils.pyindex b5a55927626..2de7db35271 100644--- a/litellm/proxy/management_helpers/utils.py+++ b/litellm/proxy/management_helpers/utils.py@@ -13,7 +13,6 @@ from litellm.proxy._types import ( # key request types; user request types; teaDeleteCustomerRequest,DeleteTeamRequest,DeleteUserRequest,- KeyCreatedEvent,KeyRequest,LiteLLM_TeamTable,ManagementEndpointLoggingPayload,@@ -24,6 +23,7 @@ from litellm.proxy._types import ( # key request types; user request types; teaUpdateTeamRequest,UpdateUserRequest,UserAPIKeyAuth,+ VirtualKeyEvent,)from litellm.proxy.common_utils.http_parsing_utils import _read_request_bodyfrom litellm.proxy.utils import PrismaClient@@ -203,24 +203,29 @@ async def send_management_endpoint_alert(if premium_user is not True:return+ key_function_to_event_name = {+ "generate_key_fn": "Virtual Key Created",+ "update_key_fn": "Virtual Key Updated",+ "delete_key_fn": "Virtual Key Deleted",+ }+if (proxy_logging_obj is not Noneand proxy_logging_obj.slack_alerting_instance is not None):- key_event = KeyCreatedEvent(- created_by_user_id=user_api_key_dict.user_id or "Unknown",- created_by_user_role=user_api_key_dict.user_role or "Unknown",- created_by_key_alias=user_api_key_dict.key_alias,- key_alias=request_kwargs.get("key_alias"),- team_id=request_kwargs.get("team_id"),- max_budget=request_kwargs.get("max_budget"),- )- if function_name == "generate_key_fn":- from litellm.proxy.proxy_server import proxy_logging_obj+ # Virtual Key Events+ if function_name in key_function_to_event_name:+ key_event = VirtualKeyEvent(+ created_by_user_id=user_api_key_dict.user_id or "Unknown",+ created_by_user_role=user_api_key_dict.user_role or "Unknown",+ created_by_key_alias=user_api_key_dict.key_alias,+ request_kwargs=request_kwargs,+ )+ event_name = key_function_to_event_name[function_name]await proxy_logging_obj.slack_alerting_instance.send_virtual_key_event_slack(- key_event=key_event, event_name="Virtual Key Created"+ key_event=key_event, event_name=event_name)