Description
Bug Report
Description
When using Claude Opus 4.7 via Amazon Bedrock, OpenCode can replay assistant reasoning/thinking blocks through the interleaved reasoning transform in packages/opencode/src/provider/transform.ts.
That transform is intended for OpenAI-compatible providers (reasoning_content / reasoning_details style fields), but it can also run for Bedrock models if the model catalog marks them as interleaved.
For Bedrock Claude models, this is invalid: native Anthropic/Bedrock thinking blocks must be replayed as content blocks with their original metadata/signature preserved. Rewriting them into providerOptions.openaiCompatible[...] strips the native structure and can cause Bedrock validation failures.
Error
Example failure:
undefined: The model returned the following errors:
{"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.0.thinking.signature: Field required"}}
``` txt
Root cause
In packages/opencode/src/provider/transform.ts, normalizeMessages() has this path:
```txt
if (typeof model.capabilities.interleaved === "object" && model.capabilities.interleaved.field) {
// collect reasoning text
// remove reasoning blocks from content
// move text to providerOptions.openaiCompatible[field]
}
This path is too broad. It is not restricted to @ai-sdk/openai-compatible, so Bedrock models can be routed through logic that is only valid for OpenAI-compatible providers.
For Anthropic models on Bedrock, reasoning blocks should remain native reasoning/thinking content with provider metadata preserved, not be rewritten into openaiCompatible.reasoning_content.
Why this matters for Opus 4.7
Opus 4.7 uses adaptive thinking and Bedrock expects prior thinking blocks to be replayed unchanged. If OpenCode rewrites them into an OpenAI-compatible shape, the request no longer matches the Bedrock/Anthropic format and signatures can no longer validate correctly.
Proposed fix
Restrict the interleaved rewrite to OpenAI-compatible providers only:
if (
model.api.npm === "@ai-sdk/openai-compatible" &&
typeof model.capabilities.interleaved === "object" &&
model.capabilities.interleaved.field
) {
...
}
This keeps the interleaved behavior for providers that actually use reasoning_content / reasoning_details, while preserving native reasoning blocks for Bedrock Claude models.
Related issues / PRs
This appears related in symptom space, but not identical in root cause:
Plugins
oh-my-openagent
OpenCode version
1.14.20
Steps to reproduce
-
Configure OpenCode to use Amazon Bedrock.
-
Select Claude Opus 4.7 as the model.
-
Use a reasoning-heavy variant such as xhigh or max so adaptive thinking is likely to be emitted.
-
Start a fresh session.
-
Send a prompt that reliably triggers extended thinking, for example:
Compare three approaches for migrating a large TypeScript monorepo from one provider SDK to another, including risks, rollout strategy, and rollback plan.
-
After the assistant responds, send a follow-up in the same session that depends on the previous turn, for example:
Now turn that into a concrete phased migration plan with checkpoints and failure criteria.
-
If it does not fail on the first follow-up, continue with 1–2 more follow-ups in the same session so OpenCode replays prior assistant thinking blocks.
-
Observe the next Bedrock request fail with an error like:
undefined: The model returned the following errors:
{"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.0.thinking.signature: Field required"}}
Screenshot and/or share link
Operating System
Ubuntu 22.04 on WSL
Terminal
bash
Description
Bug Report
Description
When using
Claude Opus 4.7viaAmazon Bedrock, OpenCode can replay assistant reasoning/thinking blocks through theinterleavedreasoning transform inpackages/opencode/src/provider/transform.ts.That transform is intended for OpenAI-compatible providers (
reasoning_content/reasoning_detailsstyle fields), but it can also run for Bedrock models if the model catalog marks them asinterleaved.For Bedrock Claude models, this is invalid: native Anthropic/Bedrock thinking blocks must be replayed as content blocks with their original metadata/signature preserved. Rewriting them into
providerOptions.openaiCompatible[...]strips the native structure and can cause Bedrock validation failures.Error
Example failure:
undefined: The model returned the following errors: {"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.0.thinking.signature: Field required"}} ``` txt Root cause In packages/opencode/src/provider/transform.ts, normalizeMessages() has this path: ```txt if (typeof model.capabilities.interleaved === "object" && model.capabilities.interleaved.field) { // collect reasoning text // remove reasoning blocks from content // move text to providerOptions.openaiCompatible[field] }This path is too broad. It is not restricted to @ai-sdk/openai-compatible, so Bedrock models can be routed through logic that is only valid for OpenAI-compatible providers.
For Anthropic models on Bedrock, reasoning blocks should remain native reasoning/thinking content with provider metadata preserved, not be rewritten into openaiCompatible.reasoning_content.
Why this matters for Opus 4.7
Opus 4.7 uses adaptive thinking and Bedrock expects prior thinking blocks to be replayed unchanged. If OpenCode rewrites them into an OpenAI-compatible shape, the request no longer matches the Bedrock/Anthropic format and signatures can no longer validate correctly.
Proposed fix
Restrict the interleaved rewrite to OpenAI-compatible providers only:
if ( model.api.npm === "@ai-sdk/openai-compatible" && typeof model.capabilities.interleaved === "object" && model.capabilities.interleaved.field ) { ... }This keeps the interleaved behavior for providers that actually use reasoning_content / reasoning_details, while preserving native reasoning blocks for Bedrock Claude models.
Related issues / PRs
This appears related in symptom space, but not identical in root cause:
Those focus on signature preservation, empty text blocks, trimming, or compaction. This issue is specifically about the wrong provider transform being applied to Bedrock Claude replay.
Environment
Plugins
oh-my-openagent
OpenCode version
1.14.20
Steps to reproduce
Configure OpenCode to use Amazon Bedrock.
Select Claude Opus 4.7 as the model.
Use a reasoning-heavy variant such as xhigh or max so adaptive thinking is likely to be emitted.
Start a fresh session.
Send a prompt that reliably triggers extended thinking, for example:
Compare three approaches for migrating a large TypeScript monorepo from one provider SDK to another, including risks, rollout strategy, and rollback plan.
After the assistant responds, send a follow-up in the same session that depends on the previous turn, for example:
Now turn that into a concrete phased migration plan with checkpoints and failure criteria.
If it does not fail on the first follow-up, continue with 1–2 more follow-ups in the same session so OpenCode replays prior assistant thinking blocks.
Observe the next Bedrock request fail with an error like:
undefined: The model returned the following errors:
{"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.0.thinking.signature: Field required"}}
Screenshot and/or share link
Operating System
Ubuntu 22.04 on WSL
Terminal
bash