From 20adad495c1564ac896dd1a5a45b3966da68c383 Mon Sep 17 00:00:00 2001 From: JerryLee <223425819+Jerry2003826@users.noreply.github.com> Date: Mon, 11 May 2026 16:50:23 +1000 Subject: [PATCH] fix(proxy): type anthropic pre-call hook inputs --- .../messages/handler.py | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/messages/handler.py b/litellm/llms/anthropic/experimental_pass_through/messages/handler.py index 8eebef2a0bb..519152787f1 100644 --- a/litellm/llms/anthropic/experimental_pass_through/messages/handler.py +++ b/litellm/llms/anthropic/experimental_pass_through/messages/handler.py @@ -8,7 +8,17 @@ import asyncio import contextvars from functools import partial -from typing import Any, AsyncIterator, Coroutine, Dict, List, Optional, Union, cast +from typing import ( + TYPE_CHECKING, + Any, + AsyncIterator, + Coroutine, + Dict, + List, + Optional, + Union, + cast, +) import litellm from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj @@ -31,6 +41,10 @@ from ..responses_adapters.handler import LiteLLMMessagesToResponsesAPIHandler from .interceptors import get_messages_interceptors from .utils import AnthropicMessagesRequestUtils, mock_response +if TYPE_CHECKING: + from litellm.caching.caching import DualCache + from litellm.proxy._types import UserAPIKeyAuth + # Providers that are routed directly to the OpenAI Responses API instead of # going through chat/completions. _RESPONSES_API_PROVIDERS = frozenset({"openai"}) @@ -134,8 +148,10 @@ async def _execute_pre_request_hooks( # Keep the experimental Messages path in parity with the proxy # pre-call hook contract used by the standard /v1/messages path. modified_kwargs = await callback.async_pre_call_hook( - user_api_key_dict=request_kwargs.get("user_api_key_dict"), - cache=request_kwargs.get("cache"), + user_api_key_dict=cast( + "UserAPIKeyAuth", request_kwargs.get("user_api_key_dict") + ), + cache=cast("DualCache", request_kwargs.get("cache")), data=request_kwargs, call_type="anthropic_messages", )