diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py index fce4e7a83fd..79c311cf739 100644 --- a/litellm/proxy/management_endpoints/key_management_endpoints.py +++ b/litellm/proxy/management_endpoints/key_management_endpoints.py @@ -72,10 +72,7 @@ from litellm.proxy.common_utils.auth_cache_invalidation_pubsub import ( publish_auth_cache_invalidation, ) from litellm.proxy.common_utils.callback_config_validation import logging_metadata_config_error -from litellm.proxy.common_utils.callback_utils import ( - decrypt_callback_vars, - encrypt_callback_vars, -) +from litellm.proxy.common_utils.callback_utils import encrypt_callback_vars from litellm.proxy.common_utils.config_sync_pubsub import ( coordination_redis_cache, publish_config_change, @@ -7032,14 +7029,12 @@ async def key_health( from litellm.proxy.proxy_server import proxy_config try: - key_metadata: Final = user_api_key_dict.metadata - if key_metadata and "logging" in key_metadata: - _raise_if_key_logging_missing_callback_name(decrypt_callback_vars(key_metadata)["logging"]) + key_logging_entries: Final = KeyAndTeamLoggingSettings.get_key_dynamic_logging_settings(user_api_key_dict) + if key_logging_entries is not None: + _raise_if_key_logging_missing_callback_name(key_logging_entries) configured_entries: Final = ( - KeyAndTeamLoggingSettings.get_key_dynamic_logging_settings(user_api_key_dict) - or KeyAndTeamLoggingSettings.get_team_dynamic_logging_settings(user_api_key_dict) - or () + key_logging_entries or KeyAndTeamLoggingSettings.get_team_dynamic_logging_settings(user_api_key_dict) or () ) invalid_entries: Final = _describe_invalid_callback_entries(configured_entries) if invalid_entries is not None: diff --git a/tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.py index 4c5a5072e9f..2f0501fe886 100644 --- a/tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.py +++ b/tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.py @@ -18309,11 +18309,14 @@ def _default_team_gcs_proxy_config(team_id: str): return pc +@pytest.mark.parametrize("key_logging", [[], None], ids=["empty list", "null"]) @pytest.mark.asyncio -async def test_key_health_tests_the_team_callbacks_an_empty_key_logging_list_falls_back_to(): +async def test_key_health_tests_the_team_callbacks_an_unset_key_logging_falls_back_to(key_logging: list | None): from litellm.proxy.management_endpoints.key_management_endpoints import key_health - caller: Final = UserAPIKeyAuth(api_key="sk-1", team_id="team-gcs", metadata={"logging": []}, team_metadata={}) + caller: Final = UserAPIKeyAuth( + api_key="sk-1", team_id="team-gcs", metadata={"logging": key_logging}, team_metadata={} + ) logging_status: Final = LoggingCallbackStatus(callbacks=("gcs_bucket",), status="unhealthy", details="404") with ( patch("litellm.proxy.proxy_server.proxy_config", _default_team_gcs_proxy_config("team-gcs")), # test-quality-ok: key_health reads the module-level proxy config