-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Add support for extended thinking in Anthropic's models via Bedrock's Converse API #15220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for extended thinking in Anthropic's models via Bedrock's Converse API #15220
Conversation
This fixes Claude's models via the Converse API, which should also fix Claude Code.
@lcfyi is attempting to deploy a commit to the CLERKIEAI Team on Vercel. A member of the Team first needs to authorize it. |
5999918
to
c7a5984
Compare
c7a5984
to
310e3b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your code modifies the anthropic v1 messages api.
The error - is on the bedrock/converse_transformation for /v1/chat/completions
AFAIK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that was the API I was looking to fix initially (such that litellm works for Claude Code), so it's not fully related to the linked issue.
This change should fix models that are explicitly routing to converse
though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @krrishdholakia , This PR partially fixes #14194. This only takes care of streaming cases. The one problem people in that issue are facing is when they use Claude code with http://localhost:4004/v1/messages
they don't get back the thinking blocks in the streaming response. Which in turn makes Claude send a request without thinking block and it hence throws an error. So this is taking care of this case.
I am raising a PR which will take care of the other issues. But this LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Title
Add support for extended thinking in Anthropic's models via Bedrock's Converse API
Relevant issues
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