[BUG] API 400 error: assistant message thinking blocks serialized with `text` before `thinking` in conversation replay
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When using Claude Code with claude-opus-4-5-20251101 in auto thinking mode, every tool-use turn triggers an API 400 error on the subsequent API round-trip. The error states that an assistant message has a text block before a thinking block, violating the API's ordering constraint.
The error is 100% reproducible — in a single session, it triggered on every single tool call (8 out of 8), across 4 different tool types (AskUserQuestion, Chrome MCP computer, Read, Edit, Bash). Claude Code retries and recovers, so the session continues, but every tool-use turn costs an extra failed API call.
The 8th occurrence returned a more detailed error message revealing the likely root cause:
"Whenthinkingis enabled, a finalassistantmessage must start with a thinking block (preceding the lastmost set oftool_useandtool_resultblocks). We recommend you include thinking blocks from previous turns. To avoid this requirement, disablethinking."
This suggests Claude Code may be stripping or not preserving thinking blocks from previous assistant turns when replaying conversation history, causing the API to reject the request.
What Should Happen?
All assistant messages with thinking blocks should have thinking or redacted_thinking as the first content block when replayed in conversation history. Tool-use turns should not trigger API validation errors.
Error Messages/Logs
Primary error (occurred 7 times):**
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.N.content.0: If an assistant message contains any thinking blocks, the first block must be `thinking` or `redacted_thinking`. Found `text`."}}
**Expanded error (occurred on 8th trigger, more detailed):**
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.37.content.0.type: Expected `thinking` or `redacted_thinking`, but found `text`. When `thinking` is enabled, a final `assistant` message must start with a thinking block (preceeding the lastmost set of `tool_use` and `tool_result` blocks). We recommend you include thinking blocks from previous turns. To avoid this requirement, disable `thinking`. Please consult our documentation at https://docs.claude.com/en/docs/build-with-claude/extended-thinking"}}
**All 8 occurrences from a single session:**
| # | Error location | Tool that preceded it | Request ID |
|---|---------------|----------------------|------------|
| 1 | `messages.3.content.0` | Unknown (previous session) | `req_011CXTEZ3PEWeQsDVw8pGWb9` |
| 2 | `messages.9.content.0` | `AskUserQuestion` | `req_011CXTExGAZz1e5brbP1Ec6q` |
| 3 | `messages.13.content.0` | `AskUserQuestion` | `req_011CXTF5YW2gANXrUcNdFzxE` |
| 4 | `messages.21.content.0` | Chrome MCP `computer` | `req_011CXTFG74PKdAVcqdmZ28C3` |
| 5 | `messages.25.content.0` | Chrome MCP `computer` + `Read` | `req_011CXTFJyv75yutKTwuRwDT9` |
| 6 | `messages.29.content.0` | `Edit` | `req_011CXTFP6733tYW8VSkU5Lbr` |
| 7 | `messages.33.content.0` | `Edit` | `req_011CXTFVdKuyKn84ZSTjYNXo` |
| 8 | `messages.37.content.0` | `Edit` + `Bash` (parallel) | `req_011CXTFYcxRNr1X8VMT4CMc3` |
Message index progression: 3 → 9 → 13 → 21 → 25 → 29 → 33 → 37 (always `.content.0`)
Steps to Reproduce
Start a Claude Code session with claude-opus-4-5-20251101 (thinking mode: auto)
- Send a message that triggers thinking (e.g., a question that requires reasoning)
- Send a follow-up message that triggers a tool call (e.g., "read file X", or use any tool)
- After the tool result is returned, the next API call to replay conversation history fails with the 400 error
- Claude Code retries and succeeds, but the error occurs every time
The key conditions appear to be:
- Auto thinking mode (some turns have thinking blocks, some don't)
- Multi-turn conversation with tool use
- Conversation history replay after tool results
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.19 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
The error is non-fatal — Claude Code retries and the session continues. But it adds latency and wastes an API call on every tool-use turn.
- The 8th error's expanded message ("We recommend you include thinking blocks from previous turns") strongly suggests the client is not preserving thinking blocks when serializing conversation history.
- The error was observed across multiple tool types: built-in (
AskUserQuestion,Read,Edit,Bash) and MCP-based (Chrome browser automationcomputertool). This rules out any tool-specific cause. - The message index always points to
.content.0, meaning the first content block in the flagged assistant message istextwhen it should bethinking. - Multiple MCP servers were connected during the session (Asana, Gmail, Google Drive, Claude in Chrome), but the error is tool-type-agnostic.
7 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
I think this is the same issue maybe.
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.51.content.0: If an assistant message contains any thinking blocks, the first block must be thinking or redacted_thinking. Found text."},"request_id":"req_011CXTHRxPW6zbgycJ474tm2"}
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.47.content.0.type: Expected thinking or redacted_thinking, but found text. When thinking is enabled, a final assistant message must start with a thinking block (preceeding the lastmost set of tool_use and tool_result blocks). We recommend you include thinking blocks from previous turns. To avoid this requirement, disable thinking. Please consult our documentation at https://docs.claude.com/en/docs/build-with-claude/extended-thinking"},"request_id":"req_011CXTHNbJuY7KQvsk2PCCUj"}
I'm getting the same thing, repeatedly:
same; API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.27.content.0.type: Expected
thinkingorredacted_thinking, but foundtext. Whenthinkingis enabled, a finalassistantmessage must startwith a thinking block (preceeding the lastmost set of
tool_useandtool_resultblocks). We recommend you includethinking blocks from previous turns. To avoid this requirement, disable
thinking. Please consult our documentation athttps://docs.claude.com/en/docs/build-with-claude/extended-thinking"},"request_id":"req_011CXTJvtH8Y2KxGmq3DttvF"}
Same issue for me, I had upgraded to 2.1.19 yesterday and just reverted to 2.1.17 and am having the same issue.
Resolved. Thank you, all!
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.