Implementation:BerriAI Litellm Base Email Alerting
| Attribute | Value |
|---|---|
| Sources | enterprise/litellm_enterprise/enterprise_callbacks/send_emails/base_email.py |
| Domains | Alerting, Email, Enterprise Callbacks, Budget Management |
| Last Updated | 2026-02-15 16:00 GMT |
Overview
BaseEmailLogger is an abstract base class for sending email notifications to users for events such as user invitations, virtual key creation, key rotation, soft budget alerts, team budget alerts, and max budget alerts.
Description
The BaseEmailLogger class extends CustomLogger and provides a framework for email-based alerting in the LiteLLM proxy. It defines methods for six types of email events:
- User Invitation -- Sends an invitation email with a unique invitation link generated via the Prisma database.
- Key Created -- Notifies a user when a new virtual API key is created for them, optionally including the key value (controlled by
EMAIL_INCLUDE_API_KEYenv var). - Key Rotated -- Notifies a user when their API key has been rotated with the new key value.
- Soft Budget Alert -- Alerts a user when their spending exceeds the configured soft budget threshold.
- Team Soft Budget Alert -- Alerts multiple team members (via
alert_emails) when team spending exceeds the soft budget. - Max Budget Alert -- Alerts a user when spending reaches a percentage threshold of the maximum budget.
The class supports customization of email logo, support contact, signature, and subject templates via environment variables (EMAIL_LOGO_URL, EMAIL_SUPPORT_CONTACT, EMAIL_SIGNATURE, EMAIL_SUBJECT_INVITATION, EMAIL_SUBJECT_KEY_CREATED). Custom values require an enterprise/premium license.
Budget alerts use a DualCache to prevent duplicate alert emails within a 24-hour TTL window.
The send_email method is abstract (no-op in base) and must be implemented by concrete subclasses.
Usage
Subclass BaseEmailLogger and implement the send_email method with your email provider (e.g., SMTP, SendGrid, SES). Register the subclass as a callback in the LiteLLM proxy configuration.
Code Reference
Source Location
enterprise/litellm_enterprise/enterprise_callbacks/send_emails/base_email.py
Signature
class BaseEmailLogger(CustomLogger):
def __init__(self, internal_usage_cache: Optional[DualCache] = None, **kwargs): ...
async def send_user_invitation_email(self, event: WebhookEvent): ...
async def send_key_created_email(self, send_key_created_email_event: SendKeyCreatedEmailEvent): ...
async def send_key_rotated_email(self, send_key_rotated_email_event: SendKeyRotatedEmailEvent): ...
async def send_soft_budget_alert_email(self, event: WebhookEvent): ...
async def send_team_soft_budget_alert_email(self, event: WebhookEvent): ...
async def send_max_budget_alert_email(self, event: WebhookEvent): ...
async def budget_alerts(
self,
type: Literal["token_budget", "soft_budget", "max_budget_alert", "user_budget", "team_budget", "organization_budget", "proxy_budget", "projected_limit_exceeded"],
user_info: CallInfo,
): ...
async def send_email(self, from_email: str, to_email: List[str], subject: str, html_body: str): ...
Import
from litellm_enterprise.enterprise_callbacks.send_emails.base_email import BaseEmailLogger
I/O Contract
Inputs
| Parameter | Type | Description |
|---|---|---|
internal_usage_cache |
Optional[DualCache] |
Cache for preventing duplicate budget alert emails (24h TTL). |
event / send_key_created_email_event |
WebhookEvent / SendKeyCreatedEmailEvent |
Event data containing user info, budget values, and email addresses. |
type |
Literal[...] |
Budget alert type for the budget_alerts method.
|
user_info |
CallInfo |
User/team/org budget and spend information. |
Environment Variables:
| Variable | Description |
|---|---|
EMAIL_LOGO_URL |
Custom logo URL for email templates (enterprise only). |
EMAIL_SUPPORT_CONTACT |
Custom support email address (enterprise only). |
EMAIL_SIGNATURE |
Custom email footer/signature (enterprise only). |
EMAIL_INCLUDE_API_KEY |
Boolean; whether to include the API key in emails (default: True). |
PROXY_BASE_URL |
Base URL for invitation links (default: http://0.0.0.0:4000).
|
Outputs
| Output | Type | Description |
|---|---|---|
| Email sent | Side effect | HTML email dispatched via the concrete send_email implementation.
|
| Cache entry | Side effect | Budget alert cache key set to prevent duplicates. |
Usage Examples
from litellm_enterprise.enterprise_callbacks.send_emails.base_email import BaseEmailLogger
class SmtpEmailLogger(BaseEmailLogger):
async def send_email(self, from_email, to_email, subject, html_body):
# Implement SMTP sending logic here
pass
logger = SmtpEmailLogger()
Related Pages
- BerriAI_Litellm_Email_Alert_Endpoints -- REST endpoints for managing email event settings
- BerriAI_Litellm_Email_Alert_Types -- Pydantic types for email events and settings
- BerriAI_Litellm_PagerDuty_Alerting -- PagerDuty-based alerting integration