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]

refactor(anthropic,bedrock,databricks): factor BadRequestError for unknown reasoning_effort

Cursor Agent0f04132cf865
diff --git a/litellm/llms/anthropic/chat/transformation.py b/litellm/llms/anthropic/chat/transformation.py
index 00147b2ec8b..345558a69f7 100644
--- a/litellm/llms/anthropic/chat/transformation.py
+++ b/litellm/llms/anthropic/chat/transformation.py
@@ -6,6 +6,7 @@ from typing import (
Any,
Dict,
List,
+ NoReturn,
Optional,
Tuple,
Union,
@@ -291,8 +292,35 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
@staticmethod
def _model_supports_effort_param(model: str) -> bool:
"""Whether the model accepts ``output_config.effort`` at all."""
- return any(AnthropicConfig._supports_effort_level(model, level)
- for level in ("low", "minimal", "medium", "high", "xhigh", "max"))
+ return any(
+ AnthropicConfig._supports_effort_level(model, level)
+ for level in ("low", "minimal", "medium", "high", "xhigh", "max")
+ )
+
+ @staticmethod
+ def _raise_invalid_reasoning_effort(
+ model: str, value: Any, llm_provider: str
+ ) -> NoReturn:
+ """Raise a ``BadRequestError`` for an unrecognised ``reasoning_effort``.
+
+ Args:
+ model: The model id the request was routed to (surfaced in the error).
+ value: The offending ``reasoning_effort`` value supplied by the caller.
+ llm_provider: Provider tag for the raised exception (``"anthropic"``,
+ ``"bedrock_converse"``, ``"databricks"``, ...).
+
+ Raises:
+ litellm.exceptions.BadRequestError: Always.
+ """
+ raise litellm.exceptions.BadRequestError(
+ message=(
+ f"Invalid reasoning_effort: {value!r}. "
+ f"Must be one of: 'minimal', 'low', 'medium', "
+ f"'high', 'xhigh', 'max', 'none'"
+ ),
+ model=model,
+ llm_provider=llm_provider,
+ )
def get_supported_openai_params(self, model: str):
params = [
@@ -1203,13 +1231,9 @@ class AnthropicConfig(AnthropicModelInfo, BaseConfig):
value
)
if mapped_effort is None:
- raise litellm.exceptions.BadRequestError(
- message=(
- f"Invalid reasoning_effort: {value!r}. "
- f"Must be one of: 'minimal', 'low', "
- f"'medium', 'high', 'xhigh', 'max', 'none'"
- ),
+ AnthropicConfig._raise_invalid_reasoning_effort(
model=model,
+ value=value,
llm_provider=self.custom_llm_provider or "anthropic",
)
optional_params["output_config"] = {"effort": mapped_effort}
diff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.py
index 3b79d5b5db3..efc890d9ee2 100644
--- a/litellm/llms/bedrock/chat/converse_transformation.py
+++ b/litellm/llms/bedrock/chat/converse_transformation.py
@@ -442,13 +442,9 @@ class AmazonConverseConfig(BaseConfig):
reasoning_effort
)
if mapped_effort is None:
- raise litellm.exceptions.BadRequestError(
- message=(
- f"Invalid reasoning_effort: {reasoning_effort!r}. "
- f"Must be one of: 'minimal', 'low', 'medium', "
- f"'high', 'xhigh', 'max', 'none'"
- ),
+ AnthropicConfig._raise_invalid_reasoning_effort(
model=model,
+ value=reasoning_effort,
llm_provider="bedrock_converse",
)
self._validate_anthropic_adaptive_effort(
diff --git a/litellm/llms/databricks/chat/transformation.py b/litellm/llms/databricks/chat/transformation.py
index fedb3d1165b..bd10e929e1e 100644
--- a/litellm/llms/databricks/chat/transformation.py
+++ b/litellm/llms/databricks/chat/transformation.py
@@ -352,13 +352,9 @@ class DatabricksConfig(DatabricksBase, OpenAILikeChatConfig, AnthropicConfig):
reasoning_effort_value
)
if mapped_effort is None:
- raise litellm.exceptions.BadRequestError(
- message=(
- f"Invalid reasoning_effort: {reasoning_effort_value!r}. "
- f"Must be one of: 'minimal', 'low', "
- f"'medium', 'high', 'xhigh', 'max', 'none'"
- ),
+ AnthropicConfig._raise_invalid_reasoning_effort(
model=model,
+ value=reasoning_effort_value,
llm_provider="databricks",
)
optional_params["output_config"] = {"effort": mapped_effort}