Fix: add OpenAI-compatible API for Anthropic with modify_params=True - #17106
Conversation
Document the fundamental incompatibility between Anthropic extended thinking and OpenAI-compatible API clients. Explains: - Why thinking_blocks must be resent (stateless vs stateful APIs) - OpenAI vs Anthropic architecture differences - Solutions for client developers
|
@Chesars is attempting to deploy a commit to the CLERKIEAI Team on Vercel. A member of the Team first needs to authorize it. |
|
@Chesars for clients with this would prevent a 400 right? |
|
Yes, that would prevent the 400, but the model would stop using extended thinking on that turn. |
|
if litellm.modify_params is True, and the alternative is that it would fail the request - then it seems correct to handle the scenario to avoid failing the call if the flag is not enabled, then we should just bubble up the error, and let them know this can be avoided with the flag. this allows the anthropic model to work via the proxy when being called via openai clients - thoughts? |
|
Makes sense. For the proxy when modify_params=True, the fix would detect if the last assistant message has tool_calls but no thinking_blocks, drop the thinking param from the request. Typically on the tool result turn. |
When modify_params=True, LiteLLM now automatically drops the 'thinking' param if the last assistant message with tool_calls is missing thinking_blocks. This prevents the Anthropic error: "Expected thinking or redacted_thinking, but found tool_use" This workaround addresses the OpenAI-Anthropic API incompatibility where OpenAI-compatible clients don't preserve thinking_blocks.
…erriAI#17106) * docs: add OpenAI-compatible API limitations for Anthropic thinking Document the fundamental incompatibility between Anthropic extended thinking and OpenAI-compatible API clients. Explains: - Why thinking_blocks must be resent (stateless vs stateful APIs) - OpenAI vs Anthropic architecture differences - Solutions for client developers * Update docs * fix: auto-drop thinking param when thinking_blocks missing When modify_params=True, LiteLLM now automatically drops the 'thinking' param if the last assistant message with tool_calls is missing thinking_blocks. This prevents the Anthropic error: "Expected thinking or redacted_thinking, but found tool_use" This workaround addresses the OpenAI-Anthropic API incompatibility where OpenAI-compatible clients don't preserve thinking_blocks.
Relevant issues
Related to #14194 and #9020
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 hardrequirement - see details - N/A (documentation only)
make test-unit- N/A (documentation only)Type
Documentation
Bug Fix
Changes
Summary
modify_params=True, LiteLLM drops thethinkingparam if assistant messages withtool_callsare missingthinking_blocksDetails
OpenAI-compatible clients (LibreChat, Open WebUI, Vercel AI SDK, etc.) don't preserve
thinking_blocksbecause it's not in the OpenAI spec. This causes Anthropic to reject requests with:Expected thinking or redacted_thinking, but found tool_useSolution
When
modify_params=True:thinkingis enabled butthinking_blocksare missing from the last assistant message withtool_callsthinkingparam for that turn