anthropic-sdk-python icon indicating copy to clipboard operation
anthropic-sdk-python copied to clipboard

Anthropic-sdk-python did not return thinking block when calling a reasoning model

Open pandaominggz opened this issue 11 months ago • 1 comments

System: ubuntu 22.04

Python: 3.10.19

Anthropic-sdk-python version: 0.75.0

LLM: MiniMax AI m2.1

vLLM version: 0.13.0

LLM Deployment Command: SAFETENSORS_FAST_GPU=1 vllm serve MiniMaxAI/MiniMax-M2.1 --trust-remote-code --enable_expert_parallel --tensor-parallel-size 8 --enable-auto-tool-choice --tool-call-parser minimax_m2 --reasoning-parser minimax_m2_append_think --served-model-name MiniMax --port 8080 --host 0.0.0.0

Python Code: ` import anthropic

client = anthropic.Anthropic(base_url="my_base_url", api_key="empty")

message = client.messages.create( model="MiniMax", max_tokens=1000, system="You are a helpful assistant.", messages=[ { "role": "user", "content": [ { "type": "text", "text": "Hi, how are you?" } ] } ] )

for block in message.content: if block.type == "thinking": print(f"Thinking:\n{block.thinking}\n") elif block.type == "text": print(f"Text:\n{block.text}\n") ` Output: Text: The user is just greeting me and asking how I am. This is a simple conversational exchange, not a request for me to perform any coding tasks or work. I should respond in a friendly, conversational way.

Hi there! I'm doing well, thank you for asking. I'm ready to help you with whatever you need—whether that's coding, debugging, explaining concepts, or anything else. How can I assist you today?

pandaominggz avatar Dec 30 '25 09:12 pandaominggz

This is expected behavior - the issue is that you're using the Anthropic SDK to talk to a non-Anthropic model (MiniMax) via vLLM.

What's happening:

  1. MiniMax M2.1 outputs thinking in <think>...</think> XML tags (their native format)
  2. vLLM's --reasoning-parser minimax_m2_append_think is supposed to parse these
  3. But the Anthropic SDK expects Anthropic's native thinking block format, not XML tags

The mismatch:

Provider Thinking Format
Anthropic (Claude) {"type": "thinking", "thinking": "..."} content block
MiniMax via vLLM <think>...</think> in text content

Solutions:

  1. Post-process the response to extract thinking from XML:
import re

def extract_thinking(text):
    match = re.search(r'<think>(.*?)</think>', text, re.DOTALL)
    if match:
        return match.group(1).strip(), re.sub(r'<think>.*?</think>', '', text, flags=re.DOTALL).strip()
    return None, text

thinking, clean_text = extract_thinking(message.content[0].text)
  1. Use OpenAI SDK instead - vLLM's OpenAI-compatible endpoint is more appropriate for non-Anthropic models

  2. Check vLLM reasoning parser - The minimax_m2_append_think parser should be converting to proper content blocks. If it's not, that's a vLLM issue, not anthropic-sdk.

The Anthropic SDK is designed for Anthropic models. For other providers, consider using their native SDKs or the OpenAI-compatible interface.

prandata avatar Jan 05 '26 02:01 prandata