Skip to content

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]

[Fix] Proxy: Address Greptile feedback on hook-cycle PR

Yuneng Jiang8cac6c5bff92
diff --git a/litellm/llms/base_llm/managed_resources/isolation.py b/litellm/llms/base_llm/managed_resources/isolation.py
index 340fd822422..62027f4272c 100644
--- a/litellm/llms/base_llm/managed_resources/isolation.py
+++ b/litellm/llms/base_llm/managed_resources/isolation.py
@@ -11,14 +11,10 @@ unscoped query.
from typing import Any, Dict, List, Optional
-from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth
-
-
-def _user_has_admin_view(user_api_key_dict: UserAPIKeyAuth) -> bool:
- return user_api_key_dict.user_role in (
- LitellmUserRoles.PROXY_ADMIN,
- LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY,
- )
+from litellm.proxy._types import (
+ UserAPIKeyAuth,
+ user_api_key_has_admin_view as _user_has_admin_view,
+)
def build_list_page(items: List[Any], has_more: bool = False) -> Dict[str, Any]:
diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py
index db7c487cdd9..c6653a722d6 100644
--- a/litellm/proxy/_types.py
+++ b/litellm/proxy/_types.py
@@ -2735,6 +2735,19 @@ class UserAPIKeyAuth(
)
+def user_api_key_has_admin_view(user_api_key_dict: UserAPIKeyAuth) -> bool:
+ """Return True if the caller's role grants unscoped read access to all
+ tenant resources (managed files, batches, vector stores, spend rows, etc).
+
+ Lives on _types.py so leaf modules (e.g. litellm.llms.base_llm.managed_resources)
+ can use it without pulling in litellm.proxy.utils via management_endpoints.
+ """
+ return user_api_key_dict.user_role in (
+ LitellmUserRoles.PROXY_ADMIN,
+ LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY,
+ )
+
+
class UserInfoResponse(LiteLLMPydanticObjectBase):
user_id: Optional[str]
user_info: Optional[Union[dict, BaseModel]]
diff --git a/litellm/proxy/management_endpoints/common_utils.py b/litellm/proxy/management_endpoints/common_utils.py
index 8ad44b53007..a54c10bddc5 100644
--- a/litellm/proxy/management_endpoints/common_utils.py
+++ b/litellm/proxy/management_endpoints/common_utils.py
@@ -16,6 +16,7 @@ from litellm.proxy._types import (
NewProjectRequest,
UpdateProjectRequest,
UserAPIKeyAuth,
+ user_api_key_has_admin_view as _user_has_admin_view,
)
from litellm.proxy.utils import _premium_user_check
@@ -24,13 +25,6 @@ if TYPE_CHECKING:
from litellm.proxy.utils import PrismaClient, ProxyLogging
-def _user_has_admin_view(user_api_key_dict: UserAPIKeyAuth) -> bool:
- return (
- user_api_key_dict.user_role == LitellmUserRoles.PROXY_ADMIN
- or user_api_key_dict.user_role == LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY
- )
-
-
def require_caller_user_id_for_non_admin(
user_api_key_dict: UserAPIKeyAuth,
) -> str:
diff --git a/tests/test_litellm/proxy/hooks/test_proxy_hooks_init.py b/tests/test_litellm/proxy/hooks/test_proxy_hooks_init.py
index 23d8887a722..a6edd3db944 100644
--- a/tests/test_litellm/proxy/hooks/test_proxy_hooks_init.py
+++ b/tests/test_litellm/proxy/hooks/test_proxy_hooks_init.py
@@ -14,16 +14,20 @@ silently swallowed the ImportError in `hooks/__init__.py`, leaving
``managed_files`` unregistered and the /files endpoint returning 500.
"""
+import pytest
+
from litellm.proxy.hooks import PROXY_HOOKS, get_proxy_hook
def test_managed_files_hook_registered():
+ pytest.importorskip("litellm_enterprise")
assert "managed_files" in PROXY_HOOKS
hook_cls = get_proxy_hook("managed_files")
assert hook_cls.__name__ == "_PROXY_LiteLLMManagedFiles"
def test_managed_vector_stores_hook_registered():
+ pytest.importorskip("litellm_enterprise")
assert "managed_vector_stores" in PROXY_HOOKS
hook_cls = get_proxy_hook("managed_vector_stores")
assert hook_cls.__name__ == "_PROXY_LiteLLMManagedVectorStores"