feat - email alerts on /key/generate

This commit is contained in:
Ishaan Jaff 2024-05-24 17:33:15 -07:00
parent fa49833cdf
commit 41879ae002
2 changed files with 20 additions and 0 deletions

View file

@ -5409,6 +5409,25 @@ async def generate_key_fn(
response["soft_budget"] = (
data.soft_budget
) # include the user-input soft budget in the response
event = WebhookEvent(
event="key_created",
event_group="key",
event_message=f"API Key Created",
token=response.get("token", None),
spend=response.get("spend", 0.0),
max_budget=response.get("max_budget", "Unlimited"),
user_id=response.get("user_id", None),
team_id=response.get("team_id", "Default Team"),
key_alias=response.get("key_alias", None),
)
# If user configured email alerting - send an Email letting their end-user know the key was created
asyncio.create_task(
proxy_logging_obj.slack_alerting_instance.send_key_created_email(
webhook_event=event,
)
)
return GenerateKeyResponse(**response)
except Exception as e:
traceback.print_exc()

View file

@ -12,6 +12,7 @@ from litellm.proxy._types import (
LiteLLM_TeamTable,
Member,
CallInfo,
WebhookEvent,
)
from litellm.caching import DualCache, RedisCache
from litellm.router import Deployment, ModelInfo, LiteLLM_Params