diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index 6df6b4fe4e0..d77d096e94f 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -407,7 +407,9 @@ class ProxyChatCompletionRequest(LiteLLMBase): deployment_id: Optional[str] = None request_timeout: Optional[int] = None - model_config = ConfigDict(extra="allow") # allow params not defined here, these fall in litellm.completion(**kwargs) + model_config = ConfigDict( + extra="allow" + ) # allow params not defined here, these fall in litellm.completion(**kwargs) class ModelInfoDelete(LiteLLMBase): @@ -579,6 +581,7 @@ class NewUserRequest(GenerateKeyRequest): auto_create_key: bool = ( True # flag used for returning a key as part of the /user/new response ) + send_invite_email: Optional[bool] = None class NewUserResponse(GenerateKeyResponse): @@ -918,7 +921,9 @@ class KeyManagementSettings(LiteLLMBase): class TeamDefaultSettings(LiteLLMBase): team_id: str - model_config = ConfigDict(extra="allow") # allow params not defined here, these fall in litellm.completion(**kwargs) + model_config = ConfigDict( + extra="allow" + ) # allow params not defined here, these fall in litellm.completion(**kwargs) class DynamoDBArgs(LiteLLMBase): @@ -1112,6 +1117,7 @@ class LiteLLM_VerificationToken(LiteLLMBase): model_config = ConfigDict(protected_namespaces=()) + class LiteLLM_VerificationTokenView(LiteLLM_VerificationToken): """ Combined view of litellm verification token + litellm team table (select values) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 1ddf0e0687a..b1816b67ccc 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -8108,6 +8108,7 @@ async def new_user(data: NewUserRequest): - teams: Optional[list] - specify a list of team id's a user belongs to. - organization_id: Optional[str] - specify the org a user belongs to. - user_email: Optional[str] - Specify a user email. + - send_invite_email: Optional[bool] - Specify if an invite email should be sent. - user_role: Optional[str] - Specify a user role - "admin", "app_owner", "app_user" - max_budget: Optional[float] - Specify max budget for a given user. - models: Optional[list] - Model_name's a user is allowed to call. (if empty, key is allowed to call all models) @@ -8144,6 +8145,27 @@ async def new_user(data: NewUserRequest): ), ) ) + + if data.send_invite_email is True: + event = WebhookEvent( + event="key_created", + event_group="key", + event_message=f"API Key Created", + token=response.get("token", ""), + spend=response.get("spend", 0.0), + max_budget=response.get("max_budget", 0.0), + 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 NewUserResponse( key=response.get("token", ""), expires=response.get("expires", None),