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): fix remaining type errors after first pass

Cursor Agentbd9df9a78ce4
diff --git a/litellm/llms/perplexity/responses/transformation.py b/litellm/llms/perplexity/responses/transformation.py
index 31bed1dee3b..c7ec1313566 100644
--- a/litellm/llms/perplexity/responses/transformation.py
+++ b/litellm/llms/perplexity/responses/transformation.py
@@ -71,8 +71,11 @@ class PerplexityResponsesConfig(OpenAIResponsesAPIConfig):
result: List[Any] = []
for item in input:
if isinstance(item, dict) and "type" not in item:
- item = {**item, "type": "message"}
- result.append(item)
+ new_item = dict(item) # convert to plain dict to avoid TypedDict checking
+ new_item["type"] = "message"
+ result.append(new_item)
+ else:
+ result.append(item)
return result
return input
diff --git a/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py b/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py
index f003ba3fed7..2371bc4865a 100644
--- a/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py
+++ b/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py
@@ -201,7 +201,7 @@ class GoogleBatchEmbeddings(VertexLLM):
)
### TRANSFORMATION (sync path) ###
- request_data: Dict[str, Any]
+ request_data: Any
if use_embed_content:
resolved_files = {}
if api_key:
diff --git a/litellm/proxy/guardrails/guardrail_hooks/presidio.py b/litellm/proxy/guardrails/guardrail_hooks/presidio.py
index 337f3bfd0fb..ce2419e97ca 100644
--- a/litellm/proxy/guardrails/guardrail_hooks/presidio.py
+++ b/litellm/proxy/guardrails/guardrail_hooks/presidio.py
@@ -1242,7 +1242,7 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail):
async for chunk in self._stream_apply_output_masking(
response, request_data
):
- yield chunk
+ yield cast(ModelResponseStream, chunk)
return
metadata = (request_data.get("metadata") or {}) if request_data else {}
@@ -1257,7 +1257,7 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail):
return
async for chunk in self._stream_pii_unmasking(response, request_data):
- yield chunk
+ yield cast(ModelResponseStream, chunk)
@staticmethod
def _preserve_usage_from_last_chunk(
diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py
index 8a7478bb5bc..77424c090dd 100644
--- a/litellm/proxy/management_endpoints/key_management_endpoints.py
+++ b/litellm/proxy/management_endpoints/key_management_endpoints.py
@@ -1776,11 +1776,13 @@ async def _validate_mcp_servers_for_key_update(
user_api_key_cache=user_api_key_cache,
check_db_only=True,
)
- object_permission_dict = (
- data.object_permission.model_dump()
- if data.object_permission is not None and hasattr(data.object_permission, "model_dump")
- else data.object_permission
- )
+ object_permission_dict: Optional[dict] = None
+ if data.object_permission is not None:
+ object_permission_dict = (
+ data.object_permission.model_dump()
+ if hasattr(data.object_permission, "model_dump")
+ else dict(data.object_permission) # type: ignore[arg-type]
+ )
await validate_key_mcp_servers_against_team(
object_permission=object_permission_dict,
team_obj=effective_team_obj,
diff --git a/litellm/proxy/route_llm_request.py b/litellm/proxy/route_llm_request.py
index 9fb5fe9fee4..6e02d28b383 100644
--- a/litellm/proxy/route_llm_request.py
+++ b/litellm/proxy/route_llm_request.py
@@ -173,8 +173,21 @@ async def route_request( # noqa: PLR0915 - Complex routing function, refactorin
"agenerate_content",
"agenerate_content_stream",
"allm_passthrough_route",
+ "acreate_batch",
+ "aretrieve_batch",
+ "alist_batches",
+ "afile_content",
+ "afile_retrieve",
+ "acreate_fine_tuning_job",
+ "acancel_fine_tuning_job",
+ "alist_fine_tuning_jobs",
+ "aretrieve_fine_tuning_job",
"avector_store_search",
"avector_store_create",
+ "avector_store_retrieve",
+ "avector_store_list",
+ "avector_store_update",
+ "avector_store_delete",
"avector_store_file_create",
"avector_store_file_list",
"avector_store_file_retrieve",
@@ -207,6 +220,8 @@ async def route_request( # noqa: PLR0915 - Complex routing function, refactorin
"aget_interaction",
"adelete_interaction",
"acancel_interaction",
+ "asend_message",
+ "call_mcp_tool",
"acancel_batch",
"afile_delete",
"acreate_eval",
diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.py
index df24d51bf57..e9333c7dfab 100644
--- a/litellm/responses/litellm_completion_transformation/transformation.py
+++ b/litellm/responses/litellm_completion_transformation/transformation.py
@@ -410,11 +410,12 @@ class LiteLLMCompletionResponsesConfig:
else getattr(new_msg, "role", None)
)
if new_role == "assistant":
- new_tcs: list = (
+ _raw_tcs = (
new_msg.get("tool_calls")
if isinstance(new_msg, dict)
else getattr(new_msg, "tool_calls", None)
- ) or []
+ )
+ new_tcs: list = _raw_tcs if isinstance(_raw_tcs, list) else []
for tc in new_tcs:
LiteLLMCompletionResponsesConfig._add_tool_call_to_assistant(
last_msg, tc