From 63d3612fbe05c8a05d42d42814921279603adbb5 Mon Sep 17 00:00:00 2001 From: songjianglin <270247441+2017955725@users.noreply.github.com> Date: Thu, 8 Oct 2026 19:10:54 +0800 Subject: [PATCH] fix(anthropic): remove unchecked cast from thinking promotion --- litellm/llms/anthropic/chat/transformation.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/litellm/llms/anthropic/chat/transformation.py b/litellm/llms/anthropic/chat/transformation.py index ffa90ab3e16..90d82d4200b 100644 --- a/litellm/llms/anthropic/chat/transformation.py +++ b/litellm/llms/anthropic/chat/transformation.py @@ -1925,11 +1925,9 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig): request_optional_params: Final = optional_params.copy() if self.custom_llm_provider == "anthropic": extra_body: Final = request_optional_params.get("extra_body") - if isinstance(extra_body, dict): - thinking: Final = cast(object, extra_body.get("thinking")) - if thinking is not None: - request_optional_params["thinking"] = thinking - request_optional_params.pop("extra_body", None) + if isinstance(extra_body, dict) and "thinking" in extra_body and extra_body["thinking"] is not None: + request_optional_params["thinking"] = extra_body["thinking"] + request_optional_params.pop("extra_body", None) if "tools" not in request_optional_params and messages is not None and has_tool_call_blocks(messages): request_optional_params["tools"], _ = self._map_tools(add_dummy_tool(custom_llm_provider="anthropic"))