Skip to content

Commit 069aee9

Browse files
fix(transformation.py): correctly translate 'thinking' param for lite… (#9904)
* fix(transformation.py): correctly translate 'thinking' param for litellm_proxy/ route Fixes #9892 * test: update test
1 parent b9f01c9 commit 069aee9

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

litellm/llms/litellm_proxy/chat/transformation.py

+15
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ def get_supported_openai_params(self, model: str) -> List:
1515
list.append("thinking")
1616
return list
1717

18+
def _map_openai_params(
19+
self,
20+
non_default_params: dict,
21+
optional_params: dict,
22+
model: str,
23+
drop_params: bool,
24+
) -> dict:
25+
supported_openai_params = self.get_supported_openai_params(model)
26+
for param, value in non_default_params.items():
27+
if param == "thinking":
28+
optional_params.setdefault("extra_body", {})["thinking"] = value
29+
elif param in supported_openai_params:
30+
optional_params[param] = value
31+
return optional_params
32+
1833
def _get_openai_compatible_provider_info(
1934
self, api_base: Optional[str], api_key: Optional[str]
2035
) -> Tuple[Optional[str], Optional[str]]:

tests/llm_translation/test_litellm_proxy_provider.py

+16
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,19 @@ def test_litellm_gateway_from_sdk_with_response_cost_in_additional_headers():
449449
)
450450

451451
assert response._hidden_params["response_cost"] == 120
452+
453+
454+
def test_litellm_gateway_from_sdk_with_thinking_param():
455+
try:
456+
response = litellm.completion(
457+
model="litellm_proxy/anthropic.claude-3-7-sonnet-20250219-v1:0",
458+
messages=[{"role": "user", "content": "Hello world"}],
459+
api_base="http://0.0.0.0:4000",
460+
api_key="sk-PIp1h0RekR",
461+
# client=openai_client,
462+
thinking={"type": "enabled", "max_budget": 100},
463+
)
464+
pytest.fail("Expected an error to be raised")
465+
except Exception as e:
466+
assert "Connection error." in str(e)
467+

tests/llm_translation/test_optional_params.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ def test_litellm_proxy_thinking_param():
14101410
custom_llm_provider="litellm_proxy",
14111411
thinking={"type": "enabled", "budget_tokens": 1024},
14121412
)
1413-
assert optional_params["thinking"] == {"type": "enabled", "budget_tokens": 1024}
1413+
assert optional_params["extra_body"]["thinking"] == {"type": "enabled", "budget_tokens": 1024}
14141414

14151415
def test_gemini_modalities_param():
14161416
optional_params = get_optional_params(

0 commit comments

Comments
 (0)