Skip to content

Anthropic → OpenAI conversion drops reasoning_content, breaks multi-turn with reasoning models #27946

Description

@Biogod2020

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

  1. LiteLLM proxy with Anthropic /v1/messages + LITELLM_USE_CHAT_COMPLETIONS_URL_FOR_ANTHROPIC_MESSAGES=true
  2. Model: deepseek/* pointing to a reasoning endpoint via api_base
  3. Client sends a multi-turn conversation
  4. First turn succeeds, second turn fails

Environment

  • LiteLLM: main (commit 867470f)
  • Model: DeepSeek reasoning model via OpenAI-compatible proxy

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions