## 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 `redacted_thinking`, but found `tool_use`. 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`.
## The fix
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. 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.