Skip to content

Fix: add OpenAI-compatible API for Anthropic with modify_params=True - #17106

Merged
3 commits merged into
BerriAI:mainfrom
Chesars:docs/anthropic-thinking-openai-compatibility
Dec 15, 2025
Merged

Fix: add OpenAI-compatible API for Anthropic with modify_params=True#17106
3 commits merged into
BerriAI:mainfrom
Chesars:docs/anthropic-thinking-openai-compatibility

Conversation

@Chesars

@Chesars Chesars commented Nov 25, 2025

Copy link
Copy Markdown
Contributor

Relevant issues

Related to #14194 and #9020

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard
    requirement
    - see details - N/A (documentation only)
  • I have added a screenshot of my new test passing locally - N/A (documentation only)
  • My PR passes all unit tests on make test-unit - N/A (documentation only)
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

Documentation
Bug Fix

Changes

Summary

  • Adds handling for OpenAI-Anthropic API incompatibility when using extended thinking with tool calling
  • When modify_params=True, LiteLLM drops the thinking param if assistant messages with tool_calls are missing thinking_blocks
  • Updates documentation explaining the architectural differences between OpenAI (stateful) and Anthropic (stateless) APIs

Details

OpenAI-compatible clients (LibreChat, Open WebUI, Vercel AI SDK, etc.) don't preserve thinking_blocks because it's not in the OpenAI spec. This causes Anthropic to reject requests with:
Expected thinking or redacted_thinking, but found tool_use

Solution

When modify_params=True:

  1. Detect if thinking is enabled but thinking_blocks are missing from the last assistant message with tool_calls
  2. Drop the thinking param for that turn
  3. Log a warning so users are aware

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
@vercel

vercel Bot commented Nov 25, 2025

Copy link
Copy Markdown

@Chesars is attempting to deploy a commit to the CLERKIEAI Team on Vercel.

A member of the Team first needs to authorize it.

@ghost

ghost commented Nov 25, 2025

Copy link
Copy Markdown

@Chesars for clients with litellm.modify_params enabled - can we not just drop the thinking flag, if the thinking_blocks are missing?

this would prevent a 400 right?

@Chesars

Chesars commented Nov 25, 2025

Copy link
Copy Markdown
Contributor Author

Yes, that would prevent the 400, but the model would stop using extended thinking on that turn.

@ghost

ghost commented Nov 25, 2025

Copy link
Copy Markdown

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?

@Chesars

Chesars commented Nov 26, 2025

Copy link
Copy Markdown
Contributor Author

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.

Chesars and others added 2 commits November 28, 2025 17:21
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.
@Chesars Chesars changed the title docs: add OpenAI-compatible API limitations for Anthropic thinking Fix: add OpenAI-compatible API for Anthropic with modify_params=True Nov 28, 2025
@ghost
ghost merged commit 6ddc787 into BerriAI:main Dec 15, 2025
3 of 6 checks passed
@Chesars
Chesars deleted the docs/anthropic-thinking-openai-compatibility branch December 15, 2025 09:37
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…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.
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant