Skip to content

Thinking blocks compatibility for non-Claude providers #1988

@lmsanch

Description

@lmsanch

Problem

When switching from Claude (with extended thinking) to non-Claude providers (Fireworks, Together) mid-task, the message history contains thinking_blocks that these providers reject.

Error

litellm.BadRequestError: Fireworks_aiException - {
  "error": {
    "type": "invalid_request_error",
    "message": "Extra inputs are not permitted, field: 'messages[2].thinking_blocks'"
  }
}

Scenario

  1. User starts task with Claude → Claude generates thinking_blocks in responses
  2. User hits rate limit / runs out of credits
  3. User switches to Fireworks/Together provider
  4. Message history still contains thinking_blocks from Claude turns
  5. Fireworks/Together API rejects the request

Root Cause

  • Claude's extended thinking feature adds thinking_blocks to assistant messages
  • These blocks are preserved in conversation history
  • Non-Claude providers don't support this field and reject it
  • LiteLLM's drop_params only drops request parameters, not message fields

Proposed Solution

Add a LiteLLM pre-request callback that:

  1. Checks provider capabilities (from model-capabilities/*.yaml)
  2. If provider doesn't support thinking, converts thinking_blocks to text content
  3. Preserves reasoning information in compatible format

Conversion

# Before (Claude format):
{
  "role": "assistant", 
  "thinking_blocks": [{"type": "thinking", "thinking": "Let me analyze..."}]
}

# After (Compatible format):
{
  "role": "assistant",
  "content": [{"type": "text", "text": "[Reasoning] Let me analyze..."}]
}

Files to Create

  • litellm_callbacks/thinking_compat.py - Pre-request callback
  • Update start scripts to register callback in LiteLLM config

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions