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: Add pre and post call for list batches (#15673)

Lucas Sugice9e22688df8
diff --git a/litellm/proxy/batches_endpoints/endpoints.py b/litellm/proxy/batches_endpoints/endpoints.py
index 4f1c4dae085..b491cc61b85 100644
--- a/litellm/proxy/batches_endpoints/endpoints.py
+++ b/litellm/proxy/batches_endpoints/endpoints.py
@@ -369,7 +369,13 @@ async def list_batches(
```
"""
- from litellm.proxy.proxy_server import llm_router, proxy_logging_obj, version
+ from litellm.proxy.proxy_server import (
+ llm_router,
+ proxy_logging_obj,
+ version,
+ general_settings,
+ proxy_config,
+ )
verbose_proxy_logger.debug("GET /v1/batches after={} limit={}".format(after, limit))
try:
@@ -379,8 +385,23 @@ async def list_batches(
detail={"error": CommonProxyErrors.no_llm_router.value},
)
- ## check for target model names
+ # Include original request and headers in the data
data = await _read_request_body(request=request)
+ base_llm_response_processor = ProxyBaseLLMRequestProcessing(data=data)
+ (
+ data,
+ litellm_logging_obj,
+ ) = await base_llm_response_processor.common_processing_pre_call_logic(
+ request=request,
+ general_settings=general_settings,
+ user_api_key_dict=user_api_key_dict,
+ version=version,
+ proxy_logging_obj=proxy_logging_obj,
+ proxy_config=proxy_config,
+ route_type="alist_batches",
+ )
+
+ ## check for target model names
target_model_names = target_model_names or data.get("target_model_names", None)
if target_model_names:
model = target_model_names.split(",")[0]
@@ -388,6 +409,7 @@ async def list_batches(
model=model,
after=after,
limit=limit,
+ **data,
)
else:
custom_llm_provider = (
@@ -399,8 +421,16 @@ async def list_batches(
custom_llm_provider=custom_llm_provider, # type: ignore
after=after,
limit=limit,
+ **data,
)
+ ## POST CALL HOOKS ###
+ _response = await proxy_logging_obj.post_call_success_hook(
+ data=data, user_api_key_dict=user_api_key_dict, response=response
+ )
+ if _response is not None and type(response) == type(_response):
+ response = _response
+
### RESPONSE HEADERS ###
hidden_params = getattr(response, "_hidden_params", {}) or {}
model_id = hidden_params.get("model_id", None) or ""
diff --git a/litellm/proxy/common_request_processing.py b/litellm/proxy/common_request_processing.py
index 4de258483b0..3f50d4fd056 100644
--- a/litellm/proxy/common_request_processing.py
+++ b/litellm/proxy/common_request_processing.py
@@ -295,6 +295,7 @@ class ProxyBaseLLMRequestProcessing:
"acancel_responses",
"acreate_batch",
"aretrieve_batch",
+ "alist_batches",
"afile_content",
"atext_completion",
"acreate_fine_tuning_job",