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
fix(email): apply EMAIL_SIGNATURE to budget alert emails (#31712)
michelligabriele88c34a5bad73
diff --git a/enterprise/litellm_enterprise/enterprise_callbacks/send_emails/base_email.py b/enterprise/litellm_enterprise/enterprise_callbacks/send_emails/base_email.pyindex 89c3b854686..9d15f45079f 100644--- a/enterprise/litellm_enterprise/enterprise_callbacks/send_emails/base_email.py+++ b/enterprise/litellm_enterprise/enterprise_callbacks/send_emails/base_email.py@@ -239,6 +239,7 @@ class BaseEmailLogger(CustomLogger):max_budget_info=max_budget_info,base_url=email_params.base_url,email_support_contact=email_params.support_contact,+ email_footer=email_params.signature,)await self.send_email(from_email=self.DEFAULT_LITELLM_EMAIL,@@ -311,6 +312,7 @@ class BaseEmailLogger(CustomLogger):max_budget_info=max_budget_info,base_url=email_params.base_url,email_support_contact=email_params.support_contact,+ email_footer=email_params.signature,)# Send email to all recipients@@ -379,6 +381,7 @@ class BaseEmailLogger(CustomLogger):alert_threshold=alert_threshold_str,base_url=email_params.base_url,email_support_contact=email_params.support_contact,+ email_footer=email_params.signature,)await self.send_email(from_email=self.DEFAULT_LITELLM_EMAIL,@@ -403,6 +406,7 @@ class BaseEmailLogger(CustomLogger):alert_threshold=alert_threshold_str,base_url=email_params.base_url,email_support_contact=email_params.support_contact,+ email_footer=email_params.signature,)await self.send_email(from_email=self.DEFAULT_LITELLM_EMAIL,diff --git a/litellm/integrations/email_templates/templates.py b/litellm/integrations/email_templates/templates.pyindex 8df816dfecd..b4f39074a94 100644--- a/litellm/integrations/email_templates/templates.py+++ b/litellm/integrations/email_templates/templates.py@@ -81,8 +81,7 @@ SOFT_BUDGET_ALERT_EMAIL_TEMPLATE = """If you have any questions, please send an email to {email_support_contact} <br /> <br />- Best, <br />- The LiteLLM team <br />+ {email_footer}"""TEAM_SOFT_BUDGET_ALERT_EMAIL_TEMPLATE = """@@ -105,8 +104,7 @@ TEAM_SOFT_BUDGET_ALERT_EMAIL_TEMPLATE = """If you have any questions, please send an email to {email_support_contact} <br /> <br />- Best, <br />- The LiteLLM team <br />+ {email_footer}"""MAX_BUDGET_ALERT_EMAIL_TEMPLATE = """@@ -129,6 +127,5 @@ MAX_BUDGET_ALERT_EMAIL_TEMPLATE = """If you have any questions, please send an email to {email_support_contact} <br /> <br />- Best, <br />- The LiteLLM team <br />+ {email_footer}"""diff --git a/tests/test_litellm/enterprise/enterprise_callbacks/send_emails/test_base_email.py b/tests/test_litellm/enterprise/enterprise_callbacks/send_emails/test_base_email.pyindex 5cabfe5fb7f..db23b712125 100644--- a/tests/test_litellm/enterprise/enterprise_callbacks/send_emails/test_base_email.py+++ b/tests/test_litellm/enterprise/enterprise_callbacks/send_emails/test_base_email.py@@ -1112,3 +1112,133 @@ async def test_no_map_preserves_old_single_threshold(# Old path cache key has no threshold percentagecache_key = mock_cache.async_set_cache.call_args[1]["key"]assert cache_key == "email_budget_alerts:max_budget_alert:test_user"+++CUSTOM_SIGNATURE = "<div>Best,<br/>The Acme Platform Team</div>"+++async def test_send_soft_budget_alert_email_uses_custom_signature(+ base_email_logger, mock_send_email, mock_lookup_user_email+):+ """Soft budget alert honors EMAIL_SIGNATURE for premium users."""+ event = WebhookEvent(+ user_id="test_user",+ user_email="[email protected]",+ event_group=Litellm_EntityType.USER,+ event="soft_budget_crossed",+ event_message="Soft Budget Crossed",+ spend=105.0,+ max_budget=200.0,+ soft_budget=100.0,+ )+ with mock.patch.dict(+ os.environ,+ {"PROXY_BASE_URL": "http://test.com", "EMAIL_SIGNATURE": CUSTOM_SIGNATURE},+ ), patch("litellm.proxy.proxy_server.premium_user", True):+ await base_email_logger.send_soft_budget_alert_email(event)++ html_body = mock_send_email.call_args[1]["html_body"]+ assert CUSTOM_SIGNATURE in html_body+ assert "The LiteLLM team" not in html_body+++async def test_send_team_soft_budget_alert_email_uses_custom_signature(+ base_email_logger, mock_send_email, mock_lookup_user_email+):+ """Team soft budget alert honors EMAIL_SIGNATURE for premium users."""+ event = WebhookEvent(+ user_id="test_user",+ event_group=Litellm_EntityType.TEAM,+ event="soft_budget_crossed",+ event_message="Team Soft Budget Crossed",+ spend=105.0,+ max_budget=200.0,+ soft_budget=100.0,+ team_alias="Acme",+ alert_emails=["[email protected]"],+ )+ with mock.patch.dict(+ os.environ,+ {"PROXY_BASE_URL": "http://test.com", "EMAIL_SIGNATURE": CUSTOM_SIGNATURE},+ ), patch("litellm.proxy.proxy_server.premium_user", True):+ await base_email_logger.send_team_soft_budget_alert_email(event)++ html_body = mock_send_email.call_args[1]["html_body"]+ assert CUSTOM_SIGNATURE in html_body+ assert "The LiteLLM team" not in html_body+++async def test_send_max_budget_alert_email_single_recipient_uses_custom_signature(+ base_email_logger, mock_send_email, mock_lookup_user_email+):+ """Max budget alert (single-recipient path) honors EMAIL_SIGNATURE."""+ event = WebhookEvent(+ user_id="test_user",+ user_email="[email protected]",+ event_group=Litellm_EntityType.USER,+ event="max_budget_alert",+ event_message="Max Budget Alert",+ spend=165.0,+ max_budget=200.0,+ )+ with mock.patch.dict(+ os.environ,+ {"PROXY_BASE_URL": "http://test.com", "EMAIL_SIGNATURE": CUSTOM_SIGNATURE},+ ), patch("litellm.proxy.proxy_server.premium_user", True):+ await base_email_logger.send_max_budget_alert_email(event)++ html_body = mock_send_email.call_args[1]["html_body"]+ assert CUSTOM_SIGNATURE in html_body+ assert "The LiteLLM team" not in html_body+++async def test_send_max_budget_alert_email_multi_recipient_uses_custom_signature(+ base_email_logger, mock_send_email, mock_lookup_user_email+):+ """Max budget alert (multi-threshold/recipient path) honors EMAIL_SIGNATURE."""+ event = WebhookEvent(+ user_id="test_user",+ user_email="[email protected]",+ event_group=Litellm_EntityType.USER,+ event="max_budget_alert",+ event_message="Max Budget Alert",+ spend=165.0,+ max_budget=200.0,+ )+ with mock.patch.dict(+ os.environ,+ {"PROXY_BASE_URL": "http://test.com", "EMAIL_SIGNATURE": CUSTOM_SIGNATURE},+ ), patch("litellm.proxy.proxy_server.premium_user", True):+ await base_email_logger.send_max_budget_alert_email(+ event, threshold_pct=75, recipient_emails=["[email protected]", "[email protected]"]+ )++ html_body = mock_send_email.call_args[1]["html_body"]+ assert CUSTOM_SIGNATURE in html_body+ assert "The LiteLLM team" not in html_body+++async def test_send_soft_budget_alert_email_default_footer_when_no_signature(+ base_email_logger, mock_send_email, mock_lookup_user_email+):+ """Without EMAIL_SIGNATURE, budget alert falls back to the default EMAIL_FOOTER."""+ event = WebhookEvent(+ user_id="test_user",+ user_email="[email protected]",+ event_group=Litellm_EntityType.USER,+ event="soft_budget_crossed",+ event_message="Soft Budget Crossed",+ spend=105.0,+ max_budget=200.0,+ soft_budget=100.0,+ )+ with mock.patch.dict(os.environ, {"PROXY_BASE_URL": "http://test.com"}):+ await base_email_logger.send_soft_budget_alert_email(event)++ html_body = mock_send_email.call_args[1]["html_body"]+ assert EMAIL_FOOTER in html_body