Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion litellm/llms/anthropic/chat/transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ def _build_anthropic_tool_name_maps(
"Sonnet 4.6+, and Mythos Preview."
)

DROP_UNSUPPORTED_SPEED_WARNING = (
"Dropping unsupported `speed` for model=%s "
"(drop_params=True). Fast mode is only supported on select Opus models."
)


class AnthropicConfig(AnthropicModelInfo, BaseConfig):
"""
Expand Down Expand Up @@ -374,6 +379,51 @@ def _model_supports_effort_param(model: str) -> bool:
for level in ("low", "minimal", "medium", "high", "xhigh", "max")
)

@staticmethod
def _model_supports_speed_param(
model: str, custom_llm_provider: Optional[str] = None
) -> bool:
"""Whether the model accepts Anthropic's ``speed`` parameter (fast mode).

Fast mode is direct Anthropic API-only (not Bedrock, Vertex, or Azure).
Those providers strip their prefix before this shared transform runs, so a
bare ``claude-opus-4-8`` would otherwise resolve to the direct-API entry;
the routed provider is checked explicitly to keep them out.
"""
if custom_llm_provider is not None and custom_llm_provider != "anthropic":
return False
return (
AnthropicModelInfo._get_exact_model_capability(model, "supports_speed")
is True
Comment thread
mateo-berri marked this conversation as resolved.
Resolved
)

@staticmethod
def _maybe_drop_speed_param(
model: str,
optional_params: dict,
drop_params: bool,
custom_llm_provider: Optional[str] = None,
) -> None:
if "speed" not in optional_params:
return
if AnthropicConfig._model_supports_speed_param(model, custom_llm_provider):
return
if not (litellm.drop_params or drop_params):
speed_value = optional_params.get("speed")
raise litellm.utils.UnsupportedParamsError(
message=(
f"{model} does not support speed={speed_value!r}. "
"To drop unsupported params, set "
"`litellm.drop_params = True`."
),
status_code=400,
)
litellm.verbose_logger.warning(
DROP_UNSUPPORTED_SPEED_WARNING,
model,
)
optional_params.pop("speed", None)
Comment thread
krrish-berri-2 marked this conversation as resolved.
Resolved

@staticmethod
def _raise_invalid_reasoning_effort(
model: str, value: Any, llm_provider: str
Expand Down Expand Up @@ -1569,8 +1619,13 @@ def map_openai_params(
anthropic_context_management
)
elif param == "speed" and isinstance(value, str):
# Pass through Anthropic-specific speed parameter for fast mode
optional_params["speed"] = value
AnthropicConfig._maybe_drop_speed_param(
model=model,
optional_params=optional_params,
drop_params=drop_params,
custom_llm_provider=self.custom_llm_provider,
)
elif param == "cache_control" and isinstance(value, dict):
# Pass through top-level cache_control for automatic prompt caching
optional_params["cache_control"] = value
Expand Down Expand Up @@ -1875,6 +1930,14 @@ def transform_request(
"has no thinking_blocks. The model won't use extended thinking for this turn."
)

AnthropicConfig._maybe_drop_speed_param(
model=model,
optional_params=optional_params,
drop_params=litellm.drop_params
or litellm_params.get("drop_params") is True,
custom_llm_provider=self.custom_llm_provider,
)

headers = self.update_headers_with_optional_anthropic_beta(
headers=headers, optional_params=optional_params
)
Expand Down
10 changes: 10 additions & 0 deletions litellm/llms/anthropic/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,16 @@ def _get_model_capability(model: str, key: str) -> Optional[bool]:
pass
return None

@staticmethod
def _get_exact_model_capability(model: str, key: str) -> Optional[bool]:
"""Read boolean capability ``key`` from the exact model-map entry only.

Unlike ``_get_model_capability``, does not walk stripped provider aliases.
Use when a feature is tied to a specific host (e.g. Anthropic API fast mode).
"""
value = litellm.model_cost.get(model, {}).get(key)
return value if isinstance(value, bool) else None

@staticmethod
def _supports_model_capability(model: str, key: str) -> bool:
"""Check a boolean capability ``key`` in the model map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,10 @@ def anthropic_messages_handler(
local_vars.update(kwargs)
anthropic_messages_optional_request_params = (
AnthropicMessagesRequestUtils.get_requested_anthropic_messages_optional_param(
params=local_vars
params=local_vars,
model=model,
drop_params=litellm_params.get("drop_params") is True,
custom_llm_provider=custom_llm_provider,
)
)
if is_reasoning_auto_summary_enabled():
Expand Down
16 changes: 16 additions & 0 deletions litellm/llms/anthropic/experimental_pass_through/messages/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@ class AnthropicMessagesRequestUtils:
@staticmethod
def get_requested_anthropic_messages_optional_param(
params: Dict[str, Any],
*,
model: str | None = None,
drop_params: bool = False,
custom_llm_provider: str | None = None,
) -> AnthropicMessagesRequestOptionalParams:
"""
Filter parameters to only include those defined in AnthropicMessagesRequestOptionalParams.

Args:
params: Dictionary of parameters to filter
model: Resolved model id; when set, unsupported params may be dropped
drop_params: Per-request drop_params flag (also respects litellm.drop_params)
custom_llm_provider: Routed provider; fast mode is gated to direct Anthropic

Returns:
AnthropicMessagesRequestOptionalParams instance with only the valid parameters
Expand All @@ -37,6 +44,15 @@ def get_requested_anthropic_messages_optional_param(
filtered_params = {
k: v for k, v in params.items() if k in valid_keys and v is not None
}
if model is not None:
from litellm.llms.anthropic.chat.transformation import AnthropicConfig

AnthropicConfig._maybe_drop_speed_param(
model=model,
optional_params=filtered_params,
drop_params=drop_params,
custom_llm_provider=custom_llm_provider,
)
return cast(AnthropicMessagesRequestOptionalParams, filtered_params)


Comment thread
krrish-berri-2 marked this conversation as resolved.
Resolved
Expand Down
15 changes: 10 additions & 5 deletions litellm/model_prices_and_context_window_backup.json
Original file line number Diff line number Diff line change
Expand Up @@ -10443,7 +10443,8 @@
"fast": 6.0
},
"supports_output_config": true,
"supports_max_reasoning_effort": true
"supports_max_reasoning_effort": true,
"supports_speed": true
},
"claude-opus-4-6-20260205": {
"cache_creation_input_token_cost": 6.25e-06,
Expand Down Expand Up @@ -10476,7 +10477,8 @@
"fast": 6.0
},
"supports_max_reasoning_effort": true,
"supports_output_config": true
"supports_output_config": true,
"supports_speed": true
},
"claude-opus-4-7": {
"cache_creation_input_token_cost": 6.25e-06,
Expand Down Expand Up @@ -10511,7 +10513,8 @@
"us": 1.1,
"fast": 6.0
},
"supports_output_config": true
"supports_output_config": true,
"supports_speed": true
},
"claude-opus-4-7-20260416": {
"cache_creation_input_token_cost": 6.25e-06,
Expand Down Expand Up @@ -10546,7 +10549,8 @@
"us": 1.1,
"fast": 6.0
},
"supports_output_config": true
"supports_output_config": true,
"supports_speed": true
},
"claude-fable-5": {
"cache_creation_input_token_cost": 1.25e-05,
Expand Down Expand Up @@ -10615,7 +10619,8 @@
"us": 1.1,
"fast": 2.0
},
"supports_output_config": true
"supports_output_config": true,
"supports_speed": true
},
"claude-sonnet-4-20250514": {
"deprecation_date": "2026-05-14",
Expand Down
15 changes: 10 additions & 5 deletions model_prices_and_context_window.json
Original file line number Diff line number Diff line change
Expand Up @@ -10443,7 +10443,8 @@
"fast": 6.0
},
"supports_output_config": true,
"supports_max_reasoning_effort": true
"supports_max_reasoning_effort": true,
"supports_speed": true
},
"claude-opus-4-6-20260205": {
"cache_creation_input_token_cost": 6.25e-06,
Expand Down Expand Up @@ -10476,7 +10477,8 @@
"fast": 6.0
},
"supports_max_reasoning_effort": true,
"supports_output_config": true
"supports_output_config": true,
"supports_speed": true
},
"claude-opus-4-7": {
"cache_creation_input_token_cost": 6.25e-06,
Expand Down Expand Up @@ -10511,7 +10513,8 @@
"us": 1.1,
"fast": 6.0
},
"supports_output_config": true
"supports_output_config": true,
"supports_speed": true
},
"claude-opus-4-7-20260416": {
"cache_creation_input_token_cost": 6.25e-06,
Expand Down Expand Up @@ -10546,7 +10549,8 @@
"us": 1.1,
"fast": 6.0
},
"supports_output_config": true
"supports_output_config": true,
"supports_speed": true
},
"claude-fable-5": {
"cache_creation_input_token_cost": 1.25e-05,
Expand Down Expand Up @@ -10615,7 +10619,8 @@
"us": 1.1,
"fast": 2.0
},
"supports_output_config": true
"supports_output_config": true,
"supports_speed": true
},
"claude-sonnet-4-20250514": {
"deprecation_date": "2026-05-14",
Expand Down
Loading
Loading