From 4aa6f02beba78299245b4ccade08f1166e102e14 Mon Sep 17 00:00:00 2001 From: Gennaro Malafronte <8798987+malafronte@users.noreply.github.com> Date: Mon, 27 Apr 2026 19:18:53 +0200 Subject: [PATCH] fix(anthropic): resolve mypy lint errors in pass-through handler and adapter --- .../adapters/transformation.py | 2 +- .../experimental_pass_through/messages/handler.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py index 8e0f15e54ea..818627918ce 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py @@ -1331,7 +1331,7 @@ class LiteLLMAnthropicMessagesAdapter: openai_finish_reason=response.choices[0].finish_reason # type: ignore ) # extract usage - usage: Usage = response.usage + usage: Usage = response.usage # type: ignore[attr-defined] uncached_input_tokens = usage.prompt_tokens or 0 cached_tokens = 0 if hasattr(usage, "prompt_tokens_details") and usage.prompt_tokens_details: diff --git a/litellm/llms/anthropic/experimental_pass_through/messages/handler.py b/litellm/llms/anthropic/experimental_pass_through/messages/handler.py index 6c255a69690..74223048a33 100644 --- a/litellm/llms/anthropic/experimental_pass_through/messages/handler.py +++ b/litellm/llms/anthropic/experimental_pass_through/messages/handler.py @@ -48,8 +48,10 @@ def _should_route_to_responses_api(custom_llm_provider: Optional[str]) -> bool: def _sanitize_think_tag_text_blocks( - response: Union[AnthropicMessagesResponse, AsyncIterator] -) -> Union[AnthropicMessagesResponse, AsyncIterator]: + response: Union[ + AnthropicMessagesResponse, AsyncIterator[Any], Coroutine[Any, Any, Any] + ], +) -> Union[AnthropicMessagesResponse, AsyncIterator[Any], Coroutine[Any, Any, Any]]: if not isinstance(response, dict): return response @@ -57,7 +59,7 @@ def _sanitize_think_tag_text_blocks( if not isinstance(content, list): return response - sanitized_content: List[Dict[str, Any]] = [] + sanitized_content: List[Any] = [] for block in content: if not isinstance(block, dict): sanitized_content.append(block) @@ -221,7 +223,7 @@ async def anthropic_messages( client: Optional[AsyncHTTPHandler] = None, custom_llm_provider: Optional[str] = None, **kwargs, -) -> Union[AnthropicMessagesResponse, AsyncIterator]: +) -> Union[AnthropicMessagesResponse, AsyncIterator[Any], Coroutine[Any, Any, Any]]: """ Async: Make llm api request in Anthropic /messages API spec """