From 277e398b2ba10332fea3e30d38ab06dbf01c1713 Mon Sep 17 00:00:00 2001 From: yangdx Date: Wed, 1 Apr 2026 15:14:32 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(health=5Fendpoint?= =?UTF-8?q?s):=20eliminate=20proxy=20startup=20import=20cycles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add lazy import wrappers for get_secret, get_secret_bool, and decrypt_value_helper - prevent circular dependencies during proxy initialization by deferring imports - keep existing function signatures and behavior unchanged --- .../health_endpoints/_health_endpoints.py | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/health_endpoints/_health_endpoints.py b/litellm/proxy/health_endpoints/_health_endpoints.py index 3fb04306200..15043827712 100644 --- a/litellm/proxy/health_endpoints/_health_endpoints.py +++ b/litellm/proxy/health_endpoints/_health_endpoints.py @@ -37,12 +37,47 @@ from litellm.proxy.health_check import ( from litellm.proxy.middleware.in_flight_requests_middleware import ( get_in_flight_requests, ) -from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value_helper -from litellm.secret_managers.main import get_secret, get_secret_bool #### Health ENDPOINTS #### +def get_secret( + secret_name: str, default_value: Optional[Union[str, bool]] = None +) -> Optional[Union[str, bool]]: + # Import lazily to avoid proxy startup cycles involving secret manager setup. + from litellm.secret_managers.main import get_secret as _get_secret + + return _get_secret(secret_name=secret_name, default_value=default_value) + + +def get_secret_bool( + secret_name: str, default_value: Optional[bool] = None +) -> Optional[bool]: + # Import lazily to avoid proxy startup cycles involving secret manager setup. + from litellm.secret_managers.main import get_secret_bool as _get_secret_bool + + return _get_secret_bool(secret_name=secret_name, default_value=default_value) + + +def decrypt_value_helper( + value: str, + key: str, + exception_type: Literal["debug", "error"] = "error", + return_original_value: bool = False, +) -> Optional[str]: + # Import lazily so this module does not participate in proxy import cycles. + from litellm.proxy.common_utils.encrypt_decrypt_utils import ( + decrypt_value_helper as _decrypt_value_helper, + ) + + return _decrypt_value_helper( + value=value, + key=key, + exception_type=exception_type, + return_original_value=return_original_value, + ) + + def _resolve_os_environ_variables(params: dict) -> dict: """ Resolve ``os.environ/`` environment variables in ``litellm_params``.