Immutable solution version
claude-sonnet-4-20250514 with thinking error: Expected thinking or redacted_thinking, but found tool_use
Complete solution
A practical guide for Mastra. The 'Expected thinking or redacted_thinking, but found tool_use' error with claude-sonnet-4 was fixed on Mastra's side: providerMetadata was not being passed through in reasoning parts. Update to the latest Mastra version.
The problem
Issue mastra-ai/mastra#7799 (closed, 21 comments): ### Describe the Bug A user is encountering the error below when using claude-sonnet-4-20250514 with thinking enabled: ``ts [1] Error creating stream APICallError [AI_APICallError]: messages.29.content.0.type: Expected thinking or redactedthinking, but found tooluse. When thinking is enabled, a final assistant message must start with a thinking block (preceeding the lastmost set of tooluse and toolresult blocks). We recommend you include thinking blocks from previous turns. To avoid this requirement, disable thinking`.
The fix
The 'Expected thinking or redactedthinking, but found tooluse' error with claude-sonnet-4 was fixed on Mastra's side: providerMetadata was not being passed through in reasoning parts. Update to the latest Mastra version. PR #10650 also added helpers to process messages going to the LLM at every step, which helps future debugging.
Notes
Thread: https://github.com/mastra-ai/mastra/issues/7799. Verified against the closed issue and the maintainer/accepted answer there.
Evidence
In https://github.com/mastra-ai/mastra/issues/7799, the reporter asked: Issue mastra-ai/mastra#7799 (closed, 21 comments): ### Describe the Bug A user is encountering the error below when using claude-sonnet-4-20250514 with thinking enabled: ``ts [1] Error creating stream APICallError [AI_APICallError]: messages.29.content.0.type: Expected thinking or redactedthinking, but found tooluse. When thinking is enabled, a final assistant message must start with a thinking block (preceeding the lastmost set of tooluse and toolresult blocks). We recommend you include thinking blocks from previous turns. To avoid this requirement, disable thinking`. The verified answer: The 'Expected thinking or redactedthinking, but found tooluse' error with claude-sonnet-4 was fixed on Mastra's side: providerMetadata was not being passed through in reasoning parts. Update to the latest Mastra version. PR #10650 also added helpers to process messages going to the LLM at every step, which helps future debugging. Source thread: https://github.com/mastra-ai/mastra/issues/7799
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_zJN2UO64KB2V2-kmxR0foA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">claude-sonnet-4-20250514 with thinking error: Expected thinking or redacted_thinking, but found tool_use <span>— Vectle</span></a>