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
Merge with main
yuneng-jiangcff8a3115a95
diff --cc litellm/proxy/common_utils/callback_utils.pyindex eb312612779,4373f84292c..2fb4dfc60cc--- a/litellm/proxy/common_utils/callback_utils.py+++ b/litellm/proxy/common_utils/callback_utils.py@@@ -387,24 -383,7 +387,28 @@@ def get_metadata_variable_name_from_kwa"""return "litellm_metadata" if "litellm_metadata" in kwargs else "metadata"+def process_callback(_callback: str, callback_type: str, environment_variables: dict) -> dict:+ """Process a single callback and return its data with environment variables"""+ env_vars = CustomLogger.get_callback_env_vars(_callback)++ env_vars_dict: dict[str, str | None] = {}+ for _var in env_vars:+ env_variable = environment_variables.get(_var, None)+ if env_variable is None:+ env_vars_dict[_var] = None+ else:+ # decode + decrypt the value+ decrypted_value = decrypt_value_helper(+ value=env_variable, key=_var+ )+ env_vars_dict[_var] = decrypted_value++ return {+ "name": _callback,+ "variables": env_vars_dict,+ "type": callback_type- }++ }+ def normalize_callback_names(callbacks: Iterable[Any]) -> List[Any]:+ if callbacks is None:+ return []+ return [c.lower() if isinstance(c, str) else c for c in callbacks]diff --cc litellm/proxy/proxy_server.pyindex 205609a645c,f81bcd14d59..de228e7c582--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@@ -47,8 -47,9 +47,10 @@@ from litellm.types.utils importTokenCountResponse,)from litellm.utils import load_credentials_from_list+from litellm.proxy.common_utils.callback_utils import process_callback+ from litellm.proxy.common_utils.callback_utils import normalize_callback_names+if TYPE_CHECKING:from aiohttp import ClientSessionfrom opentelemetry.trace import Span as _Spandiff --cc tests/proxy_unit_tests/test_proxy_server.pyindex 17a6f8eb9ae,9ae916db0a7..15376ef0e32--- a/tests/proxy_unit_tests/test_proxy_server.py+++ b/tests/proxy_unit_tests/test_proxy_server.py@@@ -2403,164 -2418,59 +2418,222 @@@ def test_non_root_ui_path_logic(monkeypassert mock_logger.info.call_count == 0+async def test_get_config_callbacks_with_all_types(client_no_auth):+ """+ Test that /get/config/callbacks returns all three callback types:+ - success_callback with type="success"+ - failure_callback with type="failure"+ - callbacks (success_and_failure) with type="success_and_failure"+ """+ from litellm.proxy.proxy_server import ProxyConfig++ # Create a mock config with all three callback types+ mock_config_data = {+ "litellm_settings": {+ "success_callback": ["langfuse", "braintrust"],+ "failure_callback": ["sentry"],+ "callbacks": ["otel", "langsmith"]+ },+ "environment_variables": {+ "LANGFUSE_PUBLIC_KEY": "test-public-key",+ "LANGFUSE_SECRET_KEY": "test-secret-key",+ "LANGFUSE_HOST": "https://test.langfuse.com",+ "BRAINTRUST_API_KEY": "test-braintrust-key",+ "OTEL_EXPORTER": "otlp",+ "OTEL_ENDPOINT": "http://localhost:4317",+ "LANGSMITH_API_KEY": "test-langsmith-key",+ },+ "general_settings": {}+ }++ proxy_config = getattr(litellm.proxy.proxy_server, "proxy_config")++ with patch.object(+ proxy_config, "get_config", new=AsyncMock(return_value=mock_config_data)+ ), patch(+ "litellm.proxy.common_utils.callback_utils.decrypt_value_helper",+ side_effect=lambda value, key=None: value+ ):+ response = client_no_auth.get("/get/config/callbacks")++ assert response.status_code == 200+ result = response.json()++ # Verify response structure+ assert "status" in result+ assert result["status"] == "success"+ assert "callbacks" in result++ callbacks = result["callbacks"]++ # Verify we have all 5 callbacks (2 success + 1 failure + 2 success_and_failure)+ assert len(callbacks) == 5++ # Group callbacks by type+ success_callbacks = [cb for cb in callbacks if cb.get("type") == "success"]+ failure_callbacks = [cb for cb in callbacks if cb.get("type") == "failure"]+ success_and_failure_callbacks = [cb for cb in callbacks if cb.get("type") == "success_and_failure"]++ # Verify all callbacks have required fields+ for callback in callbacks:+ assert "name" in callback+ assert "variables" in callback+ assert "type" in callback+ assert callback["type"] in ["success", "failure", "success_and_failure"]++ # Verify success callbacks+ assert len(success_callbacks) == 2+ success_names = [cb["name"] for cb in success_callbacks]+ assert "langfuse" in success_names+ assert "braintrust" in success_names++ # Verify failure callbacks+ assert len(failure_callbacks) == 1+ assert failure_callbacks[0]["name"] == "sentry"++ # Verify success_and_failure callbacks+ assert len(success_and_failure_callbacks) == 2+ success_and_failure_names = [cb["name"] for cb in success_and_failure_callbacks]+ assert "otel" in success_and_failure_names+ assert "langsmith" in success_and_failure_names+++async def test_get_config_callbacks_environment_variables(client_no_auth):+ """+ Test that /get/config/callbacks correctly includes environment variables+ for each callback type with proper decryption.+ """+ from litellm.proxy.proxy_server import ProxyConfig++ # Create a mock config with callbacks and their env vars+ mock_config_data = {+ "litellm_settings": {+ "success_callback": ["langfuse"],+ "failure_callback": [],+ "callbacks": ["otel"]+ },+ "environment_variables": {+ "LANGFUSE_PUBLIC_KEY": "encrypted-public-key",+ "LANGFUSE_SECRET_KEY": "encrypted-secret-key",+ "LANGFUSE_HOST": "https://cloud.langfuse.com",+ "OTEL_EXPORTER": "otlp",+ "OTEL_ENDPOINT": "http://localhost:4317",+ "OTEL_HEADERS": "key=value",+ },+ "general_settings": {}+ }++ # Mock decrypt to prepend "decrypted-" to values+ def mock_decrypt(value, key=None):+ if value and isinstance(value, str) and "encrypted" in value:+ return f"decrypted-{value}"+ return value++ proxy_config = getattr(litellm.proxy.proxy_server, "proxy_config")++ with patch.object(+ proxy_config, "get_config", new=AsyncMock(return_value=mock_config_data)+ ), patch(+ "litellm.proxy.common_utils.callback_utils.decrypt_value_helper",+ side_effect=mock_decrypt+ ):+ response = client_no_auth.get("/get/config/callbacks")++ assert response.status_code == 200+ result = response.json()++ callbacks = result["callbacks"]++ # Find langfuse callback (success type)+ langfuse_callback = next(+ (cb for cb in callbacks if cb["name"] == "langfuse"), None+ )+ assert langfuse_callback is not None+ assert langfuse_callback["type"] == "success"+ assert "variables" in langfuse_callback++ # Verify langfuse env vars are present and decrypted+ langfuse_vars = langfuse_callback["variables"]+ assert "LANGFUSE_PUBLIC_KEY" in langfuse_vars+ assert langfuse_vars["LANGFUSE_PUBLIC_KEY"] == "decrypted-encrypted-public-key"+ assert "LANGFUSE_SECRET_KEY" in langfuse_vars+ assert langfuse_vars["LANGFUSE_SECRET_KEY"] == "decrypted-encrypted-secret-key"+ assert "LANGFUSE_HOST" in langfuse_vars+ assert langfuse_vars["LANGFUSE_HOST"] == "https://cloud.langfuse.com"++ # Find otel callback (success_and_failure type)+ otel_callback = next(+ (cb for cb in callbacks if cb["name"] == "otel"), None+ )+ assert otel_callback is not None+ assert otel_callback["type"] == "success_and_failure"+ assert "variables" in otel_callback++ # Verify otel env vars are present+ otel_vars = otel_callback["variables"]+ assert "OTEL_EXPORTER" in otel_vars+ assert otel_vars["OTEL_EXPORTER"] == "otlp"+ assert "OTEL_ENDPOINT" in otel_vars+ assert otel_vars["OTEL_ENDPOINT"] == "http://localhost:4317"+ assert "OTEL_HEADERS" in otel_vars+ assert otel_vars["OTEL_HEADERS"] == "key=value"+++++ @pytest.mark.asyncio+ async def test_update_config_success_callback_normalization():+ """+ Ensure success_callback values are normalized to lowercase when updating config.+ This prevents delete_callback (which searches lowercase) from failing on mixed case inputs like 'SQS'.+ """+ import litellm.proxy.proxy_server as proxy_server+ from litellm.proxy._types import ConfigYAML++ # Ensure feature is enabled and prisma_client is set+ setattr(proxy_server, "store_model_in_db", True)+ setattr(proxy_server, "proxy_logging_obj", MagicMock())++ class MockPrisma:+ def __init__(self):+ self.db = MagicMock()+ self.db.litellm_config = MagicMock()+ self.db.litellm_config.upsert = AsyncMock()++ # proxy_server.update_config expects this to be sync returning a dict+ def jsonify_object(self, obj):+ return obj++ setattr(proxy_server, "prisma_client", MockPrisma())++ class MockProxyConfig:+ def __init__(self):+ self.saved_config = None++ async def get_config(self):+ # Existing config has one lowercase callback already+ return {"litellm_settings": {"success_callback": ["langfuse"]}}++ async def save_config(self, new_config: dict):+ self.saved_config = new_config++ async def add_deployment(self, prisma_client=None, proxy_logging_obj=None):+ return None++ mock_proxy_config = MockProxyConfig()+ setattr(proxy_server, "proxy_config", mock_proxy_config)++ # Update config with mixed-case callbacks - expect normalization to lowercase+ config_update = ConfigYAML(litellm_settings={"success_callback": ["SQS", "sQs"]})+ await proxy_server.update_config(config_update)++ saved = mock_proxy_config.saved_config+ assert saved is not None, "save_config was not called"+ callbacks = saved["litellm_settings"]["success_callback"]++ # Deduped and normalized+ assert "sqs" in callbacks+ assert "SQS" not in callbacks+ assert "sQs" not in callbacks+ # Existing callback should still be present+ assert "langfuse" in callbacksdiff --cc tests/test_litellm/proxy/common_utils/test_callback_utils.pyindex 877f0092182,42290a024b3..d51437fc844--- a/tests/test_litellm/proxy/common_utils/test_callback_utils.py+++ b/tests/test_litellm/proxy/common_utils/test_callback_utils.py@@@ -7,11 -7,9 +7,12 @@@ sys.path.insertfrom litellm.proxy.common_utils.callback_utils import (get_remaining_tokens_and_requests_from_request_data,+ normalize_callback_names,)+from unittest.mock import patch+from litellm.proxy.common_utils.callback_utils import process_callback+def test_get_remaining_tokens_and_requests_from_request_data():model_group = "openrouter/google/gemini-2.0-flash-001"@@@ -32,45 -30,11 +33,55 @@@}+@patch(+ "litellm.proxy.common_utils.callback_utils.CustomLogger.get_callback_env_vars",+ return_value=["API_KEY", "MISSING_VAR"],+)+@patch(+ "litellm.proxy.common_utils.callback_utils.decrypt_value_helper",+ side_effect=lambda value, key: f"decrypted-{key}",+)+def test_process_callback_with_env_vars(mock_decrypt, mock_get_env_vars):+ environment_variables = {+ "API_KEY": "ENC_VALUE",+ "UNUSED": "SHOULD_BE_IGNORED",+ }++ result = process_callback(+ _callback="my_callback",+ callback_type="input",+ environment_variables=environment_variables,+ )++ assert result["name"] == "my_callback"+ assert result["type"] == "input"+ assert result["variables"] == {+ "API_KEY": "decrypted-API_KEY",+ "MISSING_VAR": None,+ }+++@patch(+ "litellm.proxy.common_utils.callback_utils.CustomLogger.get_callback_env_vars",+ return_value=[],+)+def test_process_callback_with_no_required_env_vars(mock_get_env_vars):+ result = process_callback(+ _callback="another_callback",+ callback_type="output",+ environment_variables={"SHOULD_NOT_BE_USED": "VALUE"},+ )++ assert result["name"] == "another_callback"+ assert result["type"] == "output"+ assert result["variables"] == {}+++++ def test_normalize_callback_names_none_returns_empty_list():+ assert normalize_callback_names(None) == []+ assert normalize_callback_names([]) == []+++ def test_normalize_callback_names_lowercases_strings():+ assert normalize_callback_names(["SQS", "S3", "CUSTOM_CALLBACK"]) == ["sqs", "s3", "custom_callback"]+