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: mypy errors

Sameer Kankuted3b2afbbe423
diff --git a/litellm/batches/main.py b/litellm/batches/main.py
index 3367f567a7f..795ae493f68 100644
--- a/litellm/batches/main.py
+++ b/litellm/batches/main.py
@@ -868,7 +868,7 @@ async def acancel_batch(
extra_headers: Optional[Dict[str, str]] = None,
extra_body: Optional[Dict[str, str]] = None,
**kwargs,
-) -> Batch:
+) -> LiteLLMBatch:
"""
Async: Cancels a batch.
@@ -912,7 +912,7 @@ def cancel_batch(
extra_headers: Optional[Dict[str, str]] = None,
extra_body: Optional[Dict[str, str]] = None,
**kwargs,
-) -> Union[Batch, Coroutine[Any, Any, Batch]]:
+) -> Union[LiteLLMBatch, Coroutine[Any, Any, LiteLLMBatch]]:
"""
Cancels a batch.
diff --git a/litellm/llms/azure/batches/handler.py b/litellm/llms/azure/batches/handler.py
index 7c4e1d901bd..aaefe801687 100644
--- a/litellm/llms/azure/batches/handler.py
+++ b/litellm/llms/azure/batches/handler.py
@@ -9,7 +9,6 @@ from openai import AsyncOpenAI, OpenAI
from litellm.llms.azure.azure import AsyncAzureOpenAI, AzureOpenAI
from litellm.types.llms.openai import (
- Batch,
CancelBatchRequest,
CreateBatchRequest,
RetrieveBatchRequest,
@@ -159,6 +158,21 @@ class AzureBatchesAPI(BaseAzureLLM):
raise ValueError(
"OpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment."
)
+
+ if _is_async is True:
+ if not isinstance(azure_client, (AsyncAzureOpenAI, AsyncOpenAI)):
+ raise ValueError(
+ "Azure client is not an instance of AsyncAzureOpenAI or AsyncOpenAI. Make sure you passed an async client."
+ )
+ return self.acancel_batch( # type: ignore
+ cancel_batch_data=cancel_batch_data, client=azure_client
+ )
+
+ # At this point, azure_client is guaranteed to be a sync client
+ if not isinstance(azure_client, (AzureOpenAI, OpenAI)):
+ raise ValueError(
+ "Azure client is not an instance of AzureOpenAI or OpenAI. Make sure you passed a sync client."
+ )
response = azure_client.batches.cancel(**cancel_batch_data)
return LiteLLMBatch(**response.model_dump())
diff --git a/litellm/llms/openai/openai.py b/litellm/llms/openai/openai.py
index dd0263cc151..8a8070240da 100644
--- a/litellm/llms/openai/openai.py
+++ b/litellm/llms/openai/openai.py
@@ -1962,6 +1962,11 @@ class OpenAIBatchesAPI(BaseLLM):
cancel_batch_data=cancel_batch_data, openai_client=openai_client
)
+ # At this point, openai_client is guaranteed to be a sync OpenAI client
+ if not isinstance(openai_client, OpenAI):
+ raise ValueError(
+ "OpenAI client is not an instance of OpenAI. Make sure you passed a sync OpenAI client."
+ )
response = openai_client.batches.cancel(**cancel_batch_data)
return LiteLLMBatch(**response.model_dump())
diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.py
index 32ac0f0fb62..774867591bd 100644
--- a/litellm/proxy/auth/user_api_key_auth.py
+++ b/litellm/proxy/auth/user_api_key_auth.py
@@ -1239,9 +1239,6 @@ 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(
diff --git a/litellm/proxy/batches_endpoints/endpoints.py b/litellm/proxy/batches_endpoints/endpoints.py
index 3aa587c0407..220ecc5453c 100644
--- a/litellm/proxy/batches_endpoints/endpoints.py
+++ b/litellm/proxy/batches_endpoints/endpoints.py
@@ -24,9 +24,7 @@ from litellm.proxy.openai_files_endpoints.common_utils import (
_is_base64_encoded_unified_file_id,
decode_model_from_file_id,
encode_file_id_with_model,
- get_batch_id_from_unified_batch_id,
get_credentials_for_model,
- get_model_id_from_unified_batch_id,
get_models_from_unified_file_id,
get_original_file_id,
prepare_data_with_credentials,
diff --git a/litellm/proxy/common_request_processing.py b/litellm/proxy/common_request_processing.py
index 0d3e61b75c7..79392cb5fac 100644
--- a/litellm/proxy/common_request_processing.py
+++ b/litellm/proxy/common_request_processing.py
@@ -392,8 +392,10 @@ class ProxyBaseLLMRequestProcessing:
"acreate_batch",
"aretrieve_batch",
"alist_batches",
+ "acancel_batch",
"afile_content",
"afile_retrieve",
+ "afile_delete",
"atext_completion",
"acreate_fine_tuning_job",
"acancel_fine_tuning_job",
@@ -606,6 +608,8 @@ class ProxyBaseLLMRequestProcessing:
"aget_interaction",
"adelete_interaction",
"acancel_interaction",
+ "acancel_batch",
+ "afile_delete",
],
proxy_logging_obj: ProxyLogging,
general_settings: dict,
diff --git a/litellm/types/llms/anthropic.py b/litellm/types/llms/anthropic.py
index 8d18322d374..9239287dcb7 100644
--- a/litellm/types/llms/anthropic.py
+++ b/litellm/types/llms/anthropic.py
@@ -296,9 +296,9 @@ class AnthropicMessagesDocumentParam(TypedDict, total=False):
citations: Optional[CitationsObject]
-class AnthropicMessagesToolResultContent(TypedDict):
- type: Literal["text"]
- text: str
+class AnthropicMessagesToolResultContent(TypedDict, total=False):
+ type: Required[Literal["text"]]
+ text: Required[str]
cache_control: Optional[Union[dict, ChatCompletionCachedContent]]