fix(proxy): register managed files hooks from the litellm_enterprise package

A pip-installed litellm[proxy] could not import the repo-only enterprise
folder, so the managed_files and managed_vector_stores hooks never
registered and POST /v1/files with target_model_names answered 500.
Register both straight from litellm_enterprise, which the proxy extra
installs, and log a warning naming both features when that import fails
This commit is contained in:
mateo-berri 2026-10-20 19:25:25 -07:00
parent c912562672
commit 35d30d6428
2 changed files with 20 additions and 15 deletions

View file

@ -1,6 +1,9 @@
import os
from typing import Final, Literal
from litellm._logging import verbose_proxy_logger
from litellm.integrations.custom_logger import CustomLogger
from . import *
from .autorouter_baseline_cache import AutoRouterBaselineCache
from .cache_control_check import ( # noqa: F401 # backwards-compatible package export
@ -32,10 +35,10 @@ from .sensitive_data_routing import ( # noqa: F401 # backwards-compatible pack
)
# List of all available hooks that can be enabled.
# Defined before the enterprise import below so that any module re-imported
# transitively through `enterprise.enterprise_hooks` can resolve `PROXY_HOOKS`
# Defined before the litellm_enterprise hook imports below so that any module re-imported
# transitively through them can resolve `PROXY_HOOKS`
# and `get_proxy_hook` from this partially-initialized module without circling.
PROXY_HOOKS: Final = {
PROXY_HOOKS: Final[dict[str, type[CustomLogger]]] = { # mutable-ok: shared with cycle importers, extended below
"parallel_request_limiter": PROXY_MaxParallelRequestsHandler_v3,
"cache_control_check": PROXY_CacheControlCheck,
"responses_id_security": ResponsesIDSecurity,
@ -63,14 +66,14 @@ def get_proxy_hook(
return PROXY_HOOKS[hook_name]
### CHECK IF ENTERPRISE HOOKS ARE AVAILABLE ####
try:
from enterprise.enterprise_hooks import ENTERPRISE_PROXY_HOOKS
except ImportError:
ENTERPRISE_PROXY_HOOKS = {}
### update PROXY_HOOKS with ENTERPRISE_PROXY_HOOKS ###
PROXY_HOOKS.update(ENTERPRISE_PROXY_HOOKS)
from litellm_enterprise.proxy.hooks.managed_files import PROXY_LiteLLMManagedFiles
from litellm_enterprise.proxy.hooks.managed_vector_stores import PROXY_LiteLLMManagedVectorStores
except ImportError as litellm_enterprise_import_error:
verbose_proxy_logger.warning(
"Managed files and managed vector stores are disabled because litellm_enterprise failed to import: %s",
litellm_enterprise_import_error,
)
else:
PROXY_HOOKS["managed_files"] = PROXY_LiteLLMManagedFiles
PROXY_HOOKS["managed_vector_stores"] = PROXY_LiteLLMManagedVectorStores

View file

@ -137,7 +137,9 @@ class AutoRouterBaselineCache(CustomLogger):
return
try:
raw_metadata: Final = kwargs.get(get_metadata_variable_name_from_kwargs(kwargs))
metadata: Final = _METADATA.validate_python(raw_metadata) if isinstance(raw_metadata, Mapping) else {}
metadata: Final[Mapping[str, object]] = (
_METADATA.validate_python(raw_metadata) if isinstance(raw_metadata, Mapping) else {}
)
if metadata.get(INTERNAL_CALL_ORIGIN_METADATA_KEY):
return
if logging_obj.baseline_cache_context is not None:
@ -157,7 +159,7 @@ class AutoRouterBaselineCache(CustomLogger):
prices: Final = _PRICES.validate_python(
_effective_model_info(router, request.route.baseline_deployment_id, request.route.baseline_model)
)
params: Final = (
params: Final[Mapping[str, object]] = (
_METADATA.validate_python(deployment.litellm_params.model_dump(mode="json")) if deployment else {}
)
projected: Final = (