diff --git a/enterprise/litellm_enterprise/proxy/hooks/managed_files.py b/enterprise/litellm_enterprise/proxy/hooks/managed_files.py index 37d267fcd6e..ebc45b05bd4 100644 --- a/enterprise/litellm_enterprise/proxy/hooks/managed_files.py +++ b/enterprise/litellm_enterprise/proxy/hooks/managed_files.py @@ -420,13 +420,19 @@ class _PROXY_LiteLLMManagedFiles(CustomLogger, BaseFileEndpoints): # This is because the encoded object ids stored in the managed objects table do not contain the provider information # To support provider filtering, we would need to store the provider information in the encoded object ids if provider: - raise Exception("Filtering by 'provider' is not supported when using managed batches.") + raise HTTPException( + status_code=400, + detail="Filtering by 'provider' is not supported when using managed batches.", + ) # Model name filtering is not supported for managed batches # This is because the encoded object ids stored in the managed objects table do not contain the model name # A hash of the model name + litellm_params for the model name is encoded as the model id. This is not sufficient to reliably map the target model names to the model ids. if target_model_names: - raise Exception("Filtering by 'target_model_names' is not supported when using managed batches.") + raise HTTPException( + status_code=400, + detail="Filtering by 'target_model_names' is not supported when using managed batches.", + ) owner_filter = build_owner_filter(user_api_key_dict) if owner_filter is None: diff --git a/litellm/proxy/batches_endpoints/endpoints.py b/litellm/proxy/batches_endpoints/endpoints.py index aef1c5ac17e..1258162edbd 100644 --- a/litellm/proxy/batches_endpoints/endpoints.py +++ b/litellm/proxy/batches_endpoints/endpoints.py @@ -695,7 +695,12 @@ async def list_batches( # Try to use managed objects table for listing batches (returns encoded IDs). managed_files_obj: Final = proxy_logging_obj.get_proxy_hook("managed_files") - if managed_files_obj is not None and hasattr(managed_files_obj, "list_user_batches"): + if ( + managed_files_obj is not None + and hasattr(managed_files_obj, "list_user_batches") + and not provider + and not target_model_names + ): verbose_proxy_logger.debug("Using managed objects table for batch listing") response = await cast(Any, managed_files_obj).list_user_batches( user_api_key_dict=user_api_key_dict, diff --git a/tests/enterprise/litellm_enterprise/proxy/hooks/test_managed_files.py b/tests/enterprise/litellm_enterprise/proxy/hooks/test_managed_files.py index fde1feb80e2..14876299ddc 100644 --- a/tests/enterprise/litellm_enterprise/proxy/hooks/test_managed_files.py +++ b/tests/enterprise/litellm_enterprise/proxy/hooks/test_managed_files.py @@ -2007,15 +2007,16 @@ async def test_list_batches_from_managed_objects_table_provider_filter_raises_ex DualCache(), prisma_client=prisma_client ) - # Filtering by provider should raise Exception - with pytest.raises(Exception) as exc_info: + # Filtering by provider should raise HTTPException with 400 + with pytest.raises(HTTPException) as exc_info: await proxy_managed_files.list_user_batches( user_api_key_dict=UserAPIKeyAuth(user_id="test-user"), limit=10, provider="openai", ) - assert str(exc_info.value) == ( + assert exc_info.value.status_code == 400 + assert str(exc_info.value.detail) == ( "Filtering by 'provider' is not supported when using managed batches." ) @@ -2033,15 +2034,16 @@ async def test_list_batches_from_managed_objects_table_target_model_name_filter_ DualCache(), prisma_client=prisma_client ) - # Filtering by provider should raise Exception - with pytest.raises(Exception) as exc_info: + # Filtering by target_model_names should raise HTTPException with 400 + with pytest.raises(HTTPException) as exc_info: await proxy_managed_files.list_user_batches( user_api_key_dict=UserAPIKeyAuth(user_id="test-user"), limit=10, target_model_names="gpt-5.5,gpt-3.5", ) - assert str(exc_info.value) == ( + assert exc_info.value.status_code == 400 + assert str(exc_info.value.detail) == ( "Filtering by 'target_model_names' is not supported when using managed batches." )