Add support for extended thinking in Anthropic's models via Bedrock's Converse API #15220
+505
−30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title
Add support for extended thinking in Anthropic's models via Bedrock's Converse API
Relevant issues
Related to #14194
I'm hesitant to say this PR fixes that issue, because the original reporter is using a
bedrock/
model which should route to the Invoke API which handles the thinking blocks properly. Specifically, I wasn't able to reproduce the issue they were seeing when usingbedrock/us.anthropic.claude-sonnet-4-20250514-v1:0
andbedrock/us.anthropic.claude-sonnet-4-5-20250929-v1:0
as the model.However, I was able to reproduce their issue with
bedrock/converse/us.anthropic.claude-sonnet-4-20250514-v1:0
andbedrock/converse/us.anthropic.claude-sonnet-4-5-20250929-v1:0
, where fixing that was the main motivation for this PR. When running the litellm proxy on b348a26, I get the error that reporter saw:Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/
directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit
This is not passing. However, the change is unrelated to my code:
Type
🐛 Bug Fix
✅ Test
Changes
This PR adds support for extended thinking in Anthropic's models, building upon the
thinking_blocks
that's already parsed out from the Converse response here:litellm/litellm/llms/bedrock/chat/converse_transformation.py
Lines 1321 to 1330 in b348a26
This is mostly a mechanical parsing change, and is intended for downstream providers that faithfully return
thinking_blocks
that Anthropic clients expect. As such, it ignoresreasoning_content
because it doesn't return a signature (which many Anthropic clients, such as Claude Code, validate and require).Extended test plan
Validation with the reproduction script in #14194
I also confirmed that I can no longer reproduce the issue with the repro script in the linked issue:
Validation with a tool (Claude Code)
With this litellm config:
Before
The tool call succeeds, but the follow-up fails because we aren't passing in thinking blocks that would've been generated with the tool call.
After