From 161f5e3f2f2db8a2f947d74de08a0139b363ac6b Mon Sep 17 00:00:00 2001 From: Harshit28j Date: Fri, 6 Mar 2026 20:47:27 +0530 Subject: [PATCH] fix(mypy): resolve 11 type errors across 8 files - llms/openai/openai.py + llms/azure/batches/handler.py: add type: ignore[arg-type] for FileExpiresAfter vs OutputExpiresAfter SDK mismatch - batches/main.py: add type: ignore for dict[str, Any] -> FileExpiresAfter assignment - llms/openrouter/image_edit/transformation.py: cast value to str before passing to typed methods - proxy/db/db_transaction_queue/spend_log_cleanup.py: add type: ignore[assignment] for bool | None -> bool - proxy/management_endpoints/cost_tracking_settings.py: cast base_model to str to match return type - proxy/guardrails/guardrail_hooks/azure/{text_moderation,prompt_shield}.py: add type: ignore[misc] for TypedDict ** expansion Co-Authored-By: Claude Sonnet 4.6 --- litellm/batches/main.py | 2 +- litellm/llms/azure/batches/handler.py | 4 ++-- litellm/llms/openai/openai.py | 4 ++-- litellm/llms/openrouter/image_edit/transformation.py | 4 ++-- litellm/proxy/db/db_transaction_queue/spend_log_cleanup.py | 2 +- .../proxy/guardrails/guardrail_hooks/azure/prompt_shield.py | 2 +- .../proxy/guardrails/guardrail_hooks/azure/text_moderation.py | 2 +- litellm/proxy/management_endpoints/cost_tracking_settings.py | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/litellm/batches/main.py b/litellm/batches/main.py index e69c5a5c377..7000fd7c551 100644 --- a/litellm/batches/main.py +++ b/litellm/batches/main.py @@ -219,7 +219,7 @@ def create_batch( # noqa: PLR0915 extra_body=extra_body, ) if output_expires_after is not None: - _create_batch_request["output_expires_after"] = output_expires_after + _create_batch_request["output_expires_after"] = output_expires_after # type: ignore[typeddict-item] if model is not None: provider_config = ProviderConfigManager.get_provider_batches_config( model=model, diff --git a/litellm/llms/azure/batches/handler.py b/litellm/llms/azure/batches/handler.py index aaefe801687..110a4e6e575 100644 --- a/litellm/llms/azure/batches/handler.py +++ b/litellm/llms/azure/batches/handler.py @@ -35,7 +35,7 @@ class AzureBatchesAPI(BaseAzureLLM): create_batch_data: CreateBatchRequest, azure_client: Union[AsyncAzureOpenAI, AsyncOpenAI], ) -> LiteLLMBatch: - response = await azure_client.batches.create(**create_batch_data) + response = await azure_client.batches.create(**create_batch_data) # type: ignore[arg-type] return LiteLLMBatch(**response.model_dump()) def create_batch( @@ -73,7 +73,7 @@ class AzureBatchesAPI(BaseAzureLLM): return self.acreate_batch( # type: ignore create_batch_data=create_batch_data, azure_client=azure_client ) - response = cast(Union[AzureOpenAI, OpenAI], azure_client).batches.create(**create_batch_data) + response = cast(Union[AzureOpenAI, OpenAI], azure_client).batches.create(**create_batch_data) # type: ignore[arg-type] return LiteLLMBatch(**response.model_dump()) async def aretrieve_batch( diff --git a/litellm/llms/openai/openai.py b/litellm/llms/openai/openai.py index 7020f796bb7..4f222c2c61b 100644 --- a/litellm/llms/openai/openai.py +++ b/litellm/llms/openai/openai.py @@ -1938,7 +1938,7 @@ class OpenAIBatchesAPI(BaseLLM): create_batch_data: CreateBatchRequest, openai_client: AsyncOpenAI, ) -> LiteLLMBatch: - response = await openai_client.batches.create(**create_batch_data) + response = await openai_client.batches.create(**create_batch_data) # type: ignore[arg-type] return LiteLLMBatch(**response.model_dump()) def create_batch( @@ -1974,7 +1974,7 @@ class OpenAIBatchesAPI(BaseLLM): return self.acreate_batch( # type: ignore create_batch_data=create_batch_data, openai_client=openai_client ) - response = cast(OpenAI, openai_client).batches.create(**create_batch_data) + response = cast(OpenAI, openai_client).batches.create(**create_batch_data) # type: ignore[arg-type] return LiteLLMBatch(**response.model_dump()) diff --git a/litellm/llms/openrouter/image_edit/transformation.py b/litellm/llms/openrouter/image_edit/transformation.py index ed5e6ae67d5..7ee3ab3d1cd 100644 --- a/litellm/llms/openrouter/image_edit/transformation.py +++ b/litellm/llms/openrouter/image_edit/transformation.py @@ -91,9 +91,9 @@ class OpenRouterImageEditConfig(BaseImageEditConfig): if key == "size": if "image_config" not in mapped_params: mapped_params["image_config"] = {} - mapped_params["image_config"]["aspect_ratio"] = self._map_size_to_aspect_ratio(value) + mapped_params["image_config"]["aspect_ratio"] = self._map_size_to_aspect_ratio(str(value)) elif key == "quality": - image_size = self._map_quality_to_image_size(value) + image_size = self._map_quality_to_image_size(str(value)) if image_size: if "image_config" not in mapped_params: mapped_params["image_config"] = {} diff --git a/litellm/proxy/db/db_transaction_queue/spend_log_cleanup.py b/litellm/proxy/db/db_transaction_queue/spend_log_cleanup.py index a538e411b68..75a7a65445a 100644 --- a/litellm/proxy/db/db_transaction_queue/spend_log_cleanup.py +++ b/litellm/proxy/db/db_transaction_queue/spend_log_cleanup.py @@ -131,7 +131,7 @@ class SpendLogCleanup: # If we have a pod lock manager, try to acquire the lock if self.pod_lock_manager and self.pod_lock_manager.redis_cache: - lock_acquired = await self.pod_lock_manager.acquire_lock( + lock_acquired = await self.pod_lock_manager.acquire_lock( # type: ignore[assignment] cronjob_id=SPEND_LOG_CLEANUP_JOB_NAME, ) verbose_proxy_logger.info( diff --git a/litellm/proxy/guardrails/guardrail_hooks/azure/prompt_shield.py b/litellm/proxy/guardrails/guardrail_hooks/azure/prompt_shield.py index 5a8ea04e8ca..a3883899904 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/azure/prompt_shield.py +++ b/litellm/proxy/guardrails/guardrail_hooks/azure/prompt_shield.py @@ -98,7 +98,7 @@ class AzureContentSafetyPromptShieldGuardrail(AzureGuardrailBase, CustomGuardrai "text:shieldPrompt", cast(dict, request_body) ) - last_response = AzurePromptShieldGuardrailResponse(**response_json) + last_response = AzurePromptShieldGuardrailResponse(**response_json) # type: ignore[misc] if last_response["userPromptAnalysis"].get("attackDetected"): verbose_proxy_logger.warning( diff --git a/litellm/proxy/guardrails/guardrail_hooks/azure/text_moderation.py b/litellm/proxy/guardrails/guardrail_hooks/azure/text_moderation.py index 5c004d1965a..f0a397becc9 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/azure/text_moderation.py +++ b/litellm/proxy/guardrails/guardrail_hooks/azure/text_moderation.py @@ -131,7 +131,7 @@ class AzureContentSafetyTextModerationGuardrail(AzureGuardrailBase, CustomGuardr "text:analyze", cast(dict, request_body) ) - chunk_response = AzureTextModerationGuardrailResponse(**response_json) + chunk_response = AzureTextModerationGuardrailResponse(**response_json) # type: ignore[misc] # For multi-chunk texts the callers only see the final response, # so we must check every intermediate chunk here to avoid silently diff --git a/litellm/proxy/management_endpoints/cost_tracking_settings.py b/litellm/proxy/management_endpoints/cost_tracking_settings.py index 38dd4578c05..8113e7d8e16 100644 --- a/litellm/proxy/management_endpoints/cost_tracking_settings.py +++ b/litellm/proxy/management_endpoints/cost_tracking_settings.py @@ -67,7 +67,7 @@ def _resolve_model_for_cost_lookup(model: str) -> Tuple[str, Optional[str]]: f"Resolved model '{model}' to base_model '{base_model}' from router" ) custom_llm_provider = litellm_params.get("custom_llm_provider") - return base_model, custom_llm_provider + return str(base_model), custom_llm_provider resolved_model = litellm_params.get("model")