## TL;DR

For "ts [1] Error creating stream APICallError [AI_APICallError]: messages.29.content.0.type: Expected": 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.

```text
ts [1] Error creating stream APICallError [AI_APICallError]: messages.29.content.0.type: Expected
```

## Steps

1. 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`.

2. 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.

## When to use

You are seeing this: We recommend you include thinking blocks from previous turns. Use this skill when you run into "claude-sonnet-4-20250514 with thinking error: Expected thinking or redacted_thinking, but found tool_use".

## When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

## Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

## Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

## Sources

- https://github.com/mastra-ai/mastra/issues/7799
