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
feat: add global fallback config, fix no-owner crash, improve email greeting
Ryan Crabbe41a719a53782
diff --git a/litellm/__init__.py b/litellm/__init__.pyindex 3b67d9e0021..0c3d8f9926a 100644--- a/litellm/__init__.py+++ b/litellm/__init__.py@@ -376,6 +376,7 @@ datadog_params: Optional[Union[DatadogInitParams, Dict]] = Noneaws_sqs_callback_params: Optional[Dict] = Nonegeneric_logger_headers: Optional[Dict] = Nonedefault_key_generate_params: Optional[Dict] = None+default_key_max_budget_alert_emails: Optional[Dict[str, list]] = Noneupperbound_key_generate_params: Optional[LiteLLM_UpperboundKeyGenerateParams] = Nonekey_generation_settings: Optional["StandardKeyGenerationConfig"] = Nonedefault_internal_user_params: Optional[Dict] = Nonediff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.pyindex fbc24ab17cd..19751f6edc6 100644--- a/litellm/proxy/auth/auth_checks.py+++ b/litellm/proxy/auth/auth_checks.py@@ -2966,7 +2966,7 @@ async def _virtual_key_max_budget_alert_check(owner_email = user_obj.user_email if user_obj else Nonealert_email_config = (valid_token.metadata or {}).get("max_budget_alert_emails"- )+ ) or litellm.default_key_max_budget_alert_emailsif isinstance(alert_email_config, dict) and alert_email_config:# New path: pass the map through, let the email handler decide what to firediff --git a/tests/test_litellm/proxy/auth/test_auth_checks.py b/tests/test_litellm/proxy/auth/test_auth_checks.pyindex d9ab8e06d04..0f7ffa541af 100644--- a/tests/test_litellm/proxy/auth/test_auth_checks.py+++ b/tests/test_litellm/proxy/auth/test_auth_checks.py@@ -1652,6 +1652,86 @@ async def test_virtual_key_max_budget_alert_check_old_path_below_threshold_no_alassert alert_triggered is False+async def test_virtual_key_max_budget_alert_check_global_fallback():+ """Test that litellm.default_key_max_budget_alert_emails is used when key metadata has no map"""+ alert_triggered = False+ captured_call_info = None++ class MockProxyLogging:+ async def budget_alerts(self, type, user_info):+ nonlocal alert_triggered, captured_call_info+ alert_triggered = True+ captured_call_info = user_info++ global_config = {+ "50": ["[email protected]"],+ "75": ["[email protected]", "[email protected]"],+ }+ valid_token = UserAPIKeyAuth(+ token="test-token",+ spend=30.0,+ max_budget=100.0,+ user_id="test-user",+ key_alias="test-key",+ metadata={}, # no per-key config+ )++ import litellm+ original = litellm.default_key_max_budget_alert_emails+ try:+ litellm.default_key_max_budget_alert_emails = global_config+ await _virtual_key_max_budget_alert_check(+ valid_token=valid_token,+ proxy_logging_obj=MockProxyLogging(),+ user_obj=None,+ )+ await asyncio.sleep(0.1)++ assert alert_triggered is True+ assert captured_call_info.max_budget_alert_emails == global_config+ finally:+ litellm.default_key_max_budget_alert_emails = original+++async def test_virtual_key_max_budget_alert_check_per_key_overrides_global():+ """Test that per-key metadata takes priority over global fallback"""+ captured_call_info = None++ class MockProxyLogging:+ async def budget_alerts(self, type, user_info):+ nonlocal captured_call_info+ captured_call_info = user_info++ per_key_config = {"50": ["[email protected]"]}+ global_config = {"75": ["[email protected]"]}++ valid_token = UserAPIKeyAuth(+ token="test-token",+ spend=30.0,+ max_budget=100.0,+ user_id="test-user",+ key_alias="test-key",+ metadata={"max_budget_alert_emails": per_key_config},+ )++ import litellm+ original = litellm.default_key_max_budget_alert_emails+ try:+ litellm.default_key_max_budget_alert_emails = global_config+ await _virtual_key_max_budget_alert_check(+ valid_token=valid_token,+ proxy_logging_obj=MockProxyLogging(),+ user_obj=None,+ )+ await asyncio.sleep(0.1)++ assert captured_call_info.max_budget_alert_emails == per_key_config+ finally:+ litellm.default_key_max_budget_alert_emails = original++@pytest.mark.asyncioasync def test_get_fuzzy_user_object_case_insensitive_email():"""Test that _get_fuzzy_user_object uses case-insensitive email lookup"""