Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

feat(anthropic/chat/transformation.py): add minimal reasoning effort thinking support

Krrish Dholakia48579f7539fc
diff --git a/litellm/llms/anthropic/chat/transformation.py b/litellm/llms/anthropic/chat/transformation.py
index ced5a089fcc..6aeb4f5bb9a 100644
--- a/litellm/llms/anthropic/chat/transformation.py
+++ b/litellm/llms/anthropic/chat/transformation.py
@@ -12,6 +12,7 @@ from litellm.constants import (
DEFAULT_REASONING_EFFORT_HIGH_THINKING_BUDGET,
DEFAULT_REASONING_EFFORT_LOW_THINKING_BUDGET,
DEFAULT_REASONING_EFFORT_MEDIUM_THINKING_BUDGET,
+ DEFAULT_REASONING_EFFORT_MINIMAL_THINKING_BUDGET,
RESPONSE_FORMAT_TOOL_NAME,
)
from litellm.litellm_core_utils.core_helpers import map_finish_reason
@@ -52,10 +53,7 @@ from litellm.types.utils import (
CompletionTokensDetailsWrapper,
)
from litellm.types.utils import Message as LitellmMessage
-from litellm.types.utils import (
- PromptTokensDetailsWrapper,
- ServerToolUse,
-)
+from litellm.types.utils import PromptTokensDetailsWrapper, ServerToolUse
from litellm.utils import (
ModelResponse,
Usage,
@@ -82,9 +80,9 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
to pass metadata to anthropic, it's {"user_id": "any-relevant-information"}
"""
- max_tokens: Optional[
- int
- ] = DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS # anthropic requires a default value (Opus, Sonnet, and Haiku have the same default)
+ max_tokens: Optional[int] = (
+ DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS # anthropic requires a default value (Opus, Sonnet, and Haiku have the same default)
+ )
stop_sequences: Optional[list] = None
temperature: Optional[int] = None
top_p: Optional[int] = None
@@ -378,6 +376,11 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
type="enabled",
budget_tokens=DEFAULT_REASONING_EFFORT_HIGH_THINKING_BUDGET,
)
+ elif reasoning_effort == "minimal":
+ return AnthropicThinkingParam(
+ type="enabled",
+ budget_tokens=DEFAULT_REASONING_EFFORT_MINIMAL_THINKING_BUDGET,
+ )
else:
raise ValueError(f"Unmapped reasoning effort: {reasoning_effort}")
@@ -464,11 +467,11 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
if mcp_servers:
optional_params["mcp_servers"] = mcp_servers
if param == "tool_choice" or param == "parallel_tool_calls":
- _tool_choice: Optional[
- AnthropicMessagesToolChoice
- ] = self._map_tool_choice(
- tool_choice=non_default_params.get("tool_choice"),
- parallel_tool_use=non_default_params.get("parallel_tool_calls"),
+ _tool_choice: Optional[AnthropicMessagesToolChoice] = (
+ self._map_tool_choice(
+ tool_choice=non_default_params.get("tool_choice"),
+ parallel_tool_use=non_default_params.get("parallel_tool_calls"),
+ )
)
if _tool_choice is not None:
@@ -576,9 +579,9 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
text=system_message_block["content"],
)
if "cache_control" in system_message_block:
- anthropic_system_message_content[
- "cache_control"
- ] = system_message_block["cache_control"]
+ anthropic_system_message_content["cache_control"] = (
+ system_message_block["cache_control"]
+ )
anthropic_system_message_list.append(
anthropic_system_message_content
)
@@ -592,9 +595,9 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
)
)
if "cache_control" in _content:
- anthropic_system_message_content[
- "cache_control"
- ] = _content["cache_control"]
+ anthropic_system_message_content["cache_control"] = (
+ _content["cache_control"]
+ )
anthropic_system_message_list.append(
anthropic_system_message_content
@@ -652,15 +655,15 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
if tool.get("type", None) and tool.get("type").startswith(
ANTHROPIC_HOSTED_TOOLS.WEB_FETCH.value
):
- headers[
- "anthropic-beta"
- ] = ANTHROPIC_BETA_HEADER_VALUES.WEB_FETCH_2025_09_10.value
+ headers["anthropic-beta"] = (
+ ANTHROPIC_BETA_HEADER_VALUES.WEB_FETCH_2025_09_10.value
+ )
elif tool.get("type", None) and tool.get("type").startswith(
ANTHROPIC_HOSTED_TOOLS.MEMORY.value
):
- headers[
- "anthropic-beta"
- ] = ANTHROPIC_BETA_HEADER_VALUES.CONTEXT_MANAGEMENT_2025_06_27.value
+ headers["anthropic-beta"] = (
+ ANTHROPIC_BETA_HEADER_VALUES.CONTEXT_MANAGEMENT_2025_06_27.value
+ )
return headers
def transform_request(
@@ -779,9 +782,7 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
)
return _message
- def extract_response_content(
- self, completion_response: dict
- ) -> Tuple[
+ def extract_response_content(self, completion_response: dict) -> Tuple[
str,
Optional[List[Any]],
Optional[