Description
When LiteLLM converts Anthropic /v1/messages assistant responses (with thinking blocks) to OpenAI Chat Completions format, the thinking blocks are stored in a custom thinking_blocks field. The standard reasoning_content field is not set.
This causes multi-turn requests to reasoning models to fail with:
The `reasoning_content` in the thinking mode must be passed back to the API.
Root cause
In litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py:
if len(thinking_blocks) > 0:
assistant_message["thinking_blocks"] = thinking_blocks
The upstream API (DeepSeek, OpenAI o-series) expects reasoning_content at the top level of the assistant message dict in multi-turn conversations.
Fix
if len(thinking_blocks) > 0:
assistant_message["thinking_blocks"] = thinking_blocks
first_thinking = thinking_blocks[0]
assistant_message["reasoning_content"] = first_thinking.get("thinking", "")
Steps to reproduce
- LiteLLM proxy with Anthropic
/v1/messages + LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES=true
- Model:
deepseek/* pointing to a reasoning endpoint via api_base
- Client sends a multi-turn conversation
- First turn succeeds, second turn fails
Environment
- LiteLLM: main (commit 867470f)
- Model: DeepSeek reasoning model via OpenAI-compatible proxy
Description
When LiteLLM converts Anthropic
/v1/messagesassistant responses (withthinkingblocks) to OpenAI Chat Completions format, the thinking blocks are stored in a customthinking_blocksfield. The standardreasoning_contentfield is not set.This causes multi-turn requests to reasoning models to fail with:
Root cause
In
litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py:The upstream API (DeepSeek, OpenAI o-series) expects
reasoning_contentat the top level of the assistant message dict in multi-turn conversations.Fix
Steps to reproduce
/v1/messages+LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES=truedeepseek/*pointing to a reasoning endpoint viaapi_baseEnvironment