From 8da3efdfbe3251dbaf4ba4f9441122e0f6af6c21 Mon Sep 17 00:00:00 2001 From: Sameer Kankute Date: Fri, 20 Mar 2026 18:21:01 +0530 Subject: [PATCH] Fix code qa and mypy lint issues --- litellm/integrations/websearch_interception/handler.py | 3 ++- .../experimental_pass_through/messages/handler.py | 7 ++++--- litellm/llms/openai/chat/gpt_transformation.py | 3 ++- litellm/proxy/auth/auth_utils.py | 3 ++- litellm/proxy/hooks/parallel_request_limiter.py | 9 +++++++++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/litellm/integrations/websearch_interception/handler.py b/litellm/integrations/websearch_interception/handler.py index 34396849e24..2e5a8734085 100644 --- a/litellm/integrations/websearch_interception/handler.py +++ b/litellm/integrations/websearch_interception/handler.py @@ -28,6 +28,7 @@ from litellm.integrations.websearch_interception.transformation import ( from litellm.types.integrations.websearch_interception import ( WebSearchInterceptionConfig, ) +from litellm.types.llms.openai import AllMessageValues from litellm.types.utils import LlmProviders from litellm.utils import ProviderConfigManager @@ -138,7 +139,7 @@ class WebSearchInterceptionLogger(CustomLogger): get_last_user_message, ) - query = get_last_user_message(messages) + query = get_last_user_message(cast(List[AllMessageValues], messages)) if not query: return None diff --git a/litellm/llms/anthropic/experimental_pass_through/messages/handler.py b/litellm/llms/anthropic/experimental_pass_through/messages/handler.py index dae2b5da1f8..d117d74e4f7 100644 --- a/litellm/llms/anthropic/experimental_pass_through/messages/handler.py +++ b/litellm/llms/anthropic/experimental_pass_through/messages/handler.py @@ -8,7 +8,7 @@ import asyncio import contextvars from functools import partial -from typing import Any, AsyncIterator, Coroutine, Dict, List, Optional, Union +from typing import Any, AsyncIterator, Coroutine, Dict, List, Optional, Union, cast import litellm from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj @@ -151,13 +151,14 @@ async def _try_websearch_short_circuit( custom_llm_provider=custom_llm_provider, ) if response is not None: + anthropic_response = cast(AnthropicMessagesResponse, response) if stream: from litellm.llms.anthropic.experimental_pass_through.messages.fake_stream_iterator import ( FakeAnthropicMessagesStreamIterator, ) - return FakeAnthropicMessagesStreamIterator(response) - return response + return FakeAnthropicMessagesStreamIterator(anthropic_response) + return anthropic_response return None diff --git a/litellm/llms/openai/chat/gpt_transformation.py b/litellm/llms/openai/chat/gpt_transformation.py index 34a23222c2a..c12c6e6ba09 100644 --- a/litellm/llms/openai/chat/gpt_transformation.py +++ b/litellm/llms/openai/chat/gpt_transformation.py @@ -7,6 +7,7 @@ from typing import ( Any, AsyncIterator, Coroutine, + Dict, Iterator, List, Literal, @@ -805,7 +806,7 @@ class OpenAIChatCompletionStreamingHandler(BaseModelResponseIterator): choices = chunk.get("choices", []) choices = self._map_reasoning_to_reasoning_content(choices) - kwargs = { + kwargs: Dict[str, Any] = { "id": chunk.get("id"), "object": "chat.completion.chunk", "created": chunk.get("created"), diff --git a/litellm/proxy/auth/auth_utils.py b/litellm/proxy/auth/auth_utils.py index 7d3427ed4c1..d2f8320668e 100644 --- a/litellm/proxy/auth/auth_utils.py +++ b/litellm/proxy/auth/auth_utils.py @@ -560,7 +560,8 @@ def _get_deployment_default_limit(model_name: str, field: str) -> Optional[int]: raw = deployment.get("litellm_params", {}).get(field) if raw is not None: try: - limits.append(int(raw)) + if isinstance(raw, (int, float, str, bytes, bytearray)): + limits.append(int(raw)) except (ValueError, TypeError): pass return min(limits) if limits else None diff --git a/litellm/proxy/hooks/parallel_request_limiter.py b/litellm/proxy/hooks/parallel_request_limiter.py index 55e89e02d67..fefc6c8af9c 100644 --- a/litellm/proxy/hooks/parallel_request_limiter.py +++ b/litellm/proxy/hooks/parallel_request_limiter.py @@ -478,6 +478,15 @@ class _PROXY_MaxParallelRequestsHandler(CustomLogger): kwargs["litellm_params"]["metadata"].get("user_api_key_metadata", {}) or {} ) + user_api_key_team_metadata = kwargs["litellm_params"]["metadata"].get( + "user_api_key_team_metadata", None + ) + user_api_key_dict = UserAPIKeyAuth( + api_key=user_api_key, + metadata=user_api_key_metadata, + model_max_budget=user_api_key_model_max_budget, + team_metadata=user_api_key_team_metadata, + ) # ------------ # Setup values