mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
fix(bedrock): forward the interleaved-thinking beta on Bedrock Invoke and Converse
Bedrock Invoke and Converse both accept interleaved-thinking-2025-05-14, but the beta headers config mapped it to null for bedrock and bedrock_converse, so a client's header was dropped and requests with thinking.budget_tokens above max_tokens failed with a 400. Map it through like bedrock_mantle does, and keep the clear_thinking auto-injection off adaptive-thinking models, which don't need it
This commit is contained in:
parent
f2118fc767
commit
8a4eb7b0f9
4 changed files with 61 additions and 3 deletions
|
|
@ -89,7 +89,7 @@
|
|||
"fast-mode-2026-02-01": null,
|
||||
"files-api-2025-04-14": null,
|
||||
"fine-grained-tool-streaming-2025-05-14": "fine-grained-tool-streaming-2025-05-14",
|
||||
"interleaved-thinking-2025-05-14": null,
|
||||
"interleaved-thinking-2025-05-14": "interleaved-thinking-2025-05-14",
|
||||
"mcp-client-2025-11-20": null,
|
||||
"mcp-client-2025-04-04": null,
|
||||
"mcp-servers-2025-12-04": null,
|
||||
|
|
@ -124,7 +124,7 @@
|
|||
"fast-mode-2026-02-01": null,
|
||||
"files-api-2025-04-14": null,
|
||||
"fine-grained-tool-streaming-2025-05-14": "fine-grained-tool-streaming-2025-05-14",
|
||||
"interleaved-thinking-2025-05-14": null,
|
||||
"interleaved-thinking-2025-05-14": "interleaved-thinking-2025-05-14",
|
||||
"mcp-client-2025-11-20": null,
|
||||
"mcp-client-2025-04-04": null,
|
||||
"mcp-servers-2025-12-04": null,
|
||||
|
|
|
|||
|
|
@ -583,7 +583,7 @@ class AmazonAnthropicClaudeMessagesConfig(
|
|||
)
|
||||
beta_set.update(auto_betas)
|
||||
|
||||
if injected_thinking_for_clear_thinking:
|
||||
if injected_thinking_for_clear_thinking and not AnthropicModelInfo.is_adaptive_thinking_model(model, "bedrock"):
|
||||
beta_set.add("interleaved-thinking-2025-05-14")
|
||||
|
||||
if anthropic_model_info.is_eager_input_streaming_used(tools):
|
||||
|
|
|
|||
|
|
@ -2170,6 +2170,51 @@ def test_bedrock_clear_thinking_keeps_enabled_for_non_adaptive_models():
|
|||
assert "output_config" not in request
|
||||
|
||||
|
||||
def test_bedrock_invoke_transform_forwards_client_interleaved_thinking_beta(local_beta_headers_config):
|
||||
from litellm.types.router import GenericLiteLLMParams
|
||||
|
||||
cfg = AmazonAnthropicClaudeMessagesConfig()
|
||||
optional_params = {
|
||||
"max_tokens": 2000,
|
||||
"stream": False,
|
||||
"thinking": {"type": "enabled", "budget_tokens": 3000},
|
||||
}
|
||||
|
||||
result = cfg.transform_anthropic_messages_request(
|
||||
model="us.anthropic.claude-haiku-4-5-20251001-v1:0",
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
anthropic_messages_optional_request_params=copy.deepcopy(optional_params),
|
||||
litellm_params=GenericLiteLLMParams(),
|
||||
headers={"anthropic-beta": "interleaved-thinking-2025-05-14"},
|
||||
)
|
||||
|
||||
assert "interleaved-thinking-2025-05-14" in result["anthropic_beta"]
|
||||
|
||||
|
||||
def test_bedrock_invoke_transform_adds_interleaved_beta_for_clear_thinking_on_non_adaptive_model(
|
||||
local_beta_headers_config,
|
||||
):
|
||||
from litellm.types.router import GenericLiteLLMParams
|
||||
|
||||
cfg = AmazonAnthropicClaudeMessagesConfig()
|
||||
optional_params = {
|
||||
"max_tokens": 32000,
|
||||
"stream": False,
|
||||
"context_management": {"edits": [{"type": "clear_thinking_20251015", "keep": "all"}]},
|
||||
}
|
||||
|
||||
result = cfg.transform_anthropic_messages_request(
|
||||
model="anthropic.claude-opus-4-5-v1:0",
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
anthropic_messages_optional_request_params=copy.deepcopy(optional_params),
|
||||
litellm_params=GenericLiteLLMParams(),
|
||||
headers={},
|
||||
)
|
||||
|
||||
assert result["thinking"]["type"] == "enabled"
|
||||
assert "interleaved-thinking-2025-05-14" in result["anthropic_beta"]
|
||||
|
||||
|
||||
def test_bedrock_invoke_transform_emits_adaptive_thinking_for_opus_4_8():
|
||||
"""End-to-end: a Claude Code clear_thinking payload (no ``thinking`` field) on
|
||||
Opus 4.8 must produce a Bedrock Invoke body with adaptive thinking and an
|
||||
|
|
|
|||
|
|
@ -458,6 +458,19 @@ class TestAnthropicBetaHeadersFiltering:
|
|||
|
||||
assert filtered == ["dangerous-tool-use-2026-09-03"]
|
||||
|
||||
@pytest.mark.parametrize("provider", ["bedrock", "bedrock_converse"])
|
||||
def test_interleaved_thinking_forwarded_for_bedrock(self, provider: str) -> None:
|
||||
"""Bedrock InvokeModel (body `anthropic_beta`) and Converse (`additionalModelRequestFields.anthropic_beta`)
|
||||
both accepted interleaved-thinking-2025-05-14 on us.anthropic.claude-haiku-4-5 when probed live on
|
||||
2026-10-20. Dropping it made every request with `thinking.budget_tokens` above `max_tokens` fail with
|
||||
"`max_tokens` must be greater than `thinking.budget_tokens`" on /v1/messages and /chat/completions"""
|
||||
filtered: Final = filter_and_transform_beta_headers(
|
||||
beta_headers=["interleaved-thinking-2025-05-14"],
|
||||
provider=provider,
|
||||
)
|
||||
|
||||
assert filtered == ["interleaved-thinking-2025-05-14"]
|
||||
|
||||
@pytest.mark.parametrize("provider", ["anthropic", "vertex_ai"])
|
||||
def test_inline_tools_forwarded(self, provider: str) -> None:
|
||||
"""inline-tools-2026-09-15 lets a `tool_addition` system message carry a new tool mid-conversation.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue