From 7f5d5c5c6ea356bc0b79d91f2432c4e7de95ed8f Mon Sep 17 00:00:00 2001 From: Yangqian Yan <5144644+yangqian@users.noreply.github.com> Date: Sat, 7 Mar 2026 10:16:27 +0800 Subject: [PATCH] fix: use DeepSeekChatConfig instead of OpenAIConfig for deepseek provider (#22971) * fix: use DeepSeekChatConfig instead of OpenAIConfig for deepseek provider The deepseek provider was incorrectly using OpenAIConfig().map_openai_params() instead of DeepSeekChatConfig().map_openai_params(), which meant DeepSeek-specific parameter mappings were not being applied. * test: add unit tests for deepseek DeepSeekChatConfig param mapping Verify that get_optional_params uses DeepSeekChatConfig (not OpenAIConfig) for the deepseek provider by testing thinking, reasoning_effort, and budget_tokens stripping behavior. --- litellm/utils.py | 2 +- tests/test_litellm/test_utils.py | 47 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/litellm/utils.py b/litellm/utils.py index 72423f8483..dfacefe697 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -4491,7 +4491,7 @@ def get_optional_params( # noqa: PLR0915 ), ) elif custom_llm_provider == "deepseek": - optional_params = litellm.OpenAIConfig().map_openai_params( + optional_params = litellm.DeepSeekChatConfig().map_openai_params( non_default_params=non_default_params, optional_params=optional_params, model=model, diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.py index 70818af547..27e6363e53 100644 --- a/tests/test_litellm/test_utils.py +++ b/tests/test_litellm/test_utils.py @@ -3473,6 +3473,53 @@ class TestDropParamsWithPromptCacheKey: assert result.get("temperature") == 0.7 +class TestGetOptionalParamsDeepSeek: + """Tests that deepseek provider uses DeepSeekChatConfig for parameter mapping.""" + + def test_deepseek_supports_thinking_param(self): + """ + Verify that get_optional_params for deepseek accepts the 'thinking' param, + which is only supported by DeepSeekChatConfig, not OpenAIConfig. + """ + from litellm.utils import get_optional_params + + result = get_optional_params( + model="deepseek-reasoner", + custom_llm_provider="deepseek", + thinking={"type": "enabled"}, + ) + assert result.get("thinking") == {"type": "enabled"} + + def test_deepseek_supports_reasoning_effort_param(self): + """ + Verify that get_optional_params for deepseek accepts 'reasoning_effort', + which is only supported by DeepSeekChatConfig, not OpenAIConfig. + """ + from litellm.utils import get_optional_params + + result = get_optional_params( + model="deepseek-reasoner", + custom_llm_provider="deepseek", + reasoning_effort="high", + ) + assert result.get("thinking") == {"type": "enabled"} + + def test_deepseek_thinking_strips_budget_tokens(self): + """ + DeepSeekChatConfig strips budget_tokens from thinking param. + This would not happen with OpenAIConfig. + """ + from litellm.utils import get_optional_params + + result = get_optional_params( + model="deepseek-reasoner", + custom_llm_provider="deepseek", + thinking={"type": "enabled", "budget_tokens": 5000}, + ) + assert "budget_tokens" not in result.get("thinking", {}) + assert result.get("thinking") == {"type": "enabled"} + + class TestIsStreamingRequest: def test_stream_true_in_kwargs(self): assert _is_streaming_request(kwargs={"stream": True}, call_type="acompletion") is True