Anthropic-sdk-python did not return thinking block when calling a reasoning model
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:
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?
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:
- MiniMax M2.1 outputs thinking in
<think>...</think>XML tags (their native format) - vLLM's
--reasoning-parser minimax_m2_append_thinkis supposed to parse these - 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:
- 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)
-
Use OpenAI SDK instead - vLLM's OpenAI-compatible endpoint is more appropriate for non-Anthropic models
-
Check vLLM reasoning parser - The
minimax_m2_append_thinkparser 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.