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: Batch cancellation ownership bug

Sameer Kankute833cf6a2cfae
diff --git a/enterprise/litellm_enterprise/proxy/hooks/managed_files.py b/enterprise/litellm_enterprise/proxy/hooks/managed_files.py
index dd0613f87ff..62d4abee23b 100644
--- a/enterprise/litellm_enterprise/proxy/hooks/managed_files.py
+++ b/enterprise/litellm_enterprise/proxy/hooks/managed_files.py
@@ -433,12 +433,16 @@ class _PROXY_LiteLLMManagedFiles(CustomLogger, BaseFileEndpoints):
data["model_file_id_mapping"] = model_file_id_mapping
elif (
call_type == CallTypes.aretrieve_batch.value
+ or call_type == CallTypes.acancel_batch.value
or call_type == CallTypes.acancel_fine_tuning_job.value
or call_type == CallTypes.aretrieve_fine_tuning_job.value
):
accessor_key: Optional[str] = None
retrieve_object_id: Optional[str] = None
- if call_type == CallTypes.aretrieve_batch.value:
+ if (
+ call_type == CallTypes.aretrieve_batch.value
+ or call_type == CallTypes.acancel_batch.value
+ ):
accessor_key = "batch_id"
elif (
call_type == CallTypes.acancel_fine_tuning_job.value
@@ -454,6 +458,8 @@ class _PROXY_LiteLLMManagedFiles(CustomLogger, BaseFileEndpoints):
if retrieve_object_id
else False
)
+ print(f"🔥potential_llm_object_id: {potential_llm_object_id}")
+ print(f"🔥retrieve_object_id: {retrieve_object_id}")
if potential_llm_object_id and retrieve_object_id:
## VALIDATE USER HAS ACCESS TO THE OBJECT ##
if not await self.can_user_call_unified_object_id(
diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.py
index 7e7c7c8c90c..32ac0f0fb62 100644
--- a/litellm/proxy/auth/user_api_key_auth.py
+++ b/litellm/proxy/auth/user_api_key_auth.py
@@ -1239,7 +1239,9 @@ async def user_api_key_auth(
request_data=request_data, request=request
)
route: str = get_request_route(request=request)
-
+ print(f"🔥route: {route}")
+ print(f"🔥request_data: {request_data}")
+ print(f"🔥api_key: {api_key}")
## CHECK IF ROUTE IS ALLOWED
user_api_key_auth_obj = await _user_api_key_auth_builder(
@@ -1263,7 +1265,7 @@ async def user_api_key_auth(
user_api_key_auth_obj.end_user_id = end_user_id
user_api_key_auth_obj.request_route = normalize_request_route(route)
-
+ print(f"🔥user_api_key_auth_obj: {user_api_key_auth_obj}")
return user_api_key_auth_obj
diff --git a/litellm/proxy/batches_endpoints/endpoints.py b/litellm/proxy/batches_endpoints/endpoints.py
index 078e21f9bb4..c9118a82db3 100644
--- a/litellm/proxy/batches_endpoints/endpoints.py
+++ b/litellm/proxy/batches_endpoints/endpoints.py
@@ -695,15 +695,31 @@ async def cancel_batch(
data: Dict = {}
try:
- data = await _read_request_body(request=request)
- verbose_proxy_logger.debug(
- "Request received by LiteLLM:\n{}".format(json.dumps(data, indent=4)),
- )
-
# Check for encoded batch ID with model info
model_from_id = decode_model_from_file_id(batch_id)
+
+ # Create CancelBatchRequest with batch_id to enable ownership checking
+ _cancel_batch_request = CancelBatchRequest(
+ batch_id=batch_id,
+ )
+ data = cast(dict, _cancel_batch_request)
+
unified_batch_id = _is_base64_encoded_unified_file_id(batch_id)
+ 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="acancel_batch",
+ )
+
# Include original request and headers in the data
data = await add_litellm_data_to_request(
data=data,
@@ -751,17 +767,8 @@ async def cancel_batch(
},
)
- model = (
- get_model_id_from_unified_batch_id(unified_batch_id)
- if unified_batch_id
- else None
- )
-
- model_batch_id = get_batch_id_from_unified_batch_id(unified_batch_id)
-
- data["batch_id"] = model_batch_id
-
- response = await llm_router.acancel_batch(model=model, **data) # type: ignore
+ # Hook has already extracted model and unwrapped batch_id into data dict
+ response = await llm_router.acancel_batch(**data) # type: ignore
# SCENARIO 3: Fallback to custom_llm_provider (uses env variables)
else:
diff --git a/litellm/types/utils.py b/litellm/types/utils.py
index 49c903502d1..f063418f92e 100644
--- a/litellm/types/utils.py
+++ b/litellm/types/utils.py
@@ -276,6 +276,8 @@ class CallTypes(str, Enum):
acreate_batch = "acreate_batch"
aretrieve_batch = "aretrieve_batch"
retrieve_batch = "retrieve_batch"
+ acancel_batch = "acancel_batch"
+ cancel_batch = "cancel_batch"
pass_through = "pass_through_endpoint"
anthropic_messages = "anthropic_messages"
get_assistants = "get_assistants"