From 0f7ae365217d098186faf40f9da2844f9c9e6125 Mon Sep 17 00:00:00 2001 From: songkuan-zheng <252822057+songkuan-zheng@users.noreply.github.com> Date: Fri, 11 Sep 2026 12:25:28 +0000 Subject: [PATCH] fix(dashscope): drop thinking_budget when thinking is disabled A thinking block of type disabled that still carries budget_tokens now maps to enable_thinking false alone, instead of a request that both disables thinking and sets a thinking budget Co-authored-by: songkuan-zheng <252822057+songkuan-zheng@users.noreply.github.com> Co-authored-by: songkuan-zheng --- litellm/llms/dashscope/chat/transformation.py | 2 +- .../llms/dashscope/test_dashscope_chat_transformation.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/litellm/llms/dashscope/chat/transformation.py b/litellm/llms/dashscope/chat/transformation.py index 304be9435da..459369d4c60 100644 --- a/litellm/llms/dashscope/chat/transformation.py +++ b/litellm/llms/dashscope/chat/transformation.py @@ -27,7 +27,7 @@ def _dashscope_thinking_body(thinking: object, reasoning_effort: object) -> Dash if isinstance(thinking, dict): enabled: Final = thinking.get("type") != "disabled" budget: Final = thinking.get("budget_tokens") - if isinstance(budget, int) and not isinstance(budget, bool): + if enabled and isinstance(budget, int) and not isinstance(budget, bool): with_budget: Final[DashScopeThinkingBody] = {"enable_thinking": enabled, "thinking_budget": budget} return with_budget toggled: Final[DashScopeThinkingBody] = {"enable_thinking": enabled} diff --git a/tests/test_litellm/llms/dashscope/test_dashscope_chat_transformation.py b/tests/test_litellm/llms/dashscope/test_dashscope_chat_transformation.py index 395bfe61cbf..fbc2b0b47a7 100644 --- a/tests/test_litellm/llms/dashscope/test_dashscope_chat_transformation.py +++ b/tests/test_litellm/llms/dashscope/test_dashscope_chat_transformation.py @@ -207,6 +207,7 @@ class TestDashScopeThinkingParams: ({"type": "enabled", "budget_tokens": 4096}, {"enable_thinking": True, "thinking_budget": 4096}), ({"type": "enabled"}, {"enable_thinking": True}), ({"type": "disabled"}, {"enable_thinking": False}), + ({"type": "disabled", "budget_tokens": 4096}, {"enable_thinking": False}), ], ) def test_thinking_maps_to_enable_thinking_and_budget(self, thinking, expected):