Repository navigation
Claude Extended Thinking: assistant message content order causes API error #9364
Description
Activity
github-actions commented
on Jan 19, 2026 on Jan 19, 2026 – with GitHub ActionsContributorMore actionsThis issue might be a duplicate of existing issues. Please check:
- Claude extended thinking + tool use: signature not preserved in message history #6176: Claude extended thinking + tool use: signature not preserved in message history
- Expected
thinkingorredacted_thinking, but foundtool_use#3077: Expectedthinkingorredacted_thinking, but foundtool_use(same error) - [bug] v0.8.0 Introduced thinking block bug with Claude Sonnet 4: "AI_APICallError: messages.3.content.0.type: Expected
thinkingorredacted_thinking, but foundtext." #2599: v0.8.0 Introduced thinking block bug with Claude Sonnet 4 (same root cause) - Expected
thinkingorredacted_thinkingbut foundtool_use#8010: Expectedthinkingorredacted_thinkingbut foundtool_use(AWS Bedrock variant) - Most sessions eventually gets an
tool_useerror #8377: Most sessions eventually gets atool_useerror (related message ordering) - Devstral via LiteLLM OpenAI-compatible fails with invalid_request_message_order on first file edit #6346: Devstral via LiteLLM OpenAI-compatible fails with invalid_request_message_order (systemic issue)
- using Claude with Antigravity always show messages.1.content.1.tool_use.id: Field required #8675: Claude with Antigravity shows message structure validation failure (proxy variant)
The most relevant duplicate appears to be #6176, which was closed on Dec 26, 2025 but the issue persists. The underlying cause seems to be message content ordering not being enforced properly across different providers and model configurations.
Feel free to ignore if your specific case differs from these.
Update: Related to #6176
After reviewing #6176, it appears this may be the same root cause - the Antigravity adapter not correctly converting
thoughtSignatureto theproviderMetadata.anthropic.signatureformat that AI SDK expects.My Setup
- Plugin:
opencode-antigravity-auth@1.3.0 - Proxy: CLIProxyAPI (custom proxy)
- Provider configured as
@ai-sdk/anthropiccompatible
Possible Causes
- Signature format mismatch (per Claude extended thinking + tool use: signature not preserved in message history #6176): The adapter may not wrap signatures in the correct format
- Message ordering (my original analysis):
transform.tsdoesn't reorder reasoning parts to be first
Questions
- Is
opencode-antigravity-authbased on oh-my-opencode's Antigravity adapter? - If so, does it include the fixes from oh-my-opencode PR Install on Apple M3 Max #256?
If this is confirmed as a plugin issue rather than OpenCode core, please feel free to close as duplicate of #6176.
- Plugin:
Oh if you are using a plugin and getting an issue I highly recommend opening issue w/ them
Bug Description
When using Claude models with Extended Thinking enabled through a proxy (e.g., via
@ai-sdk/anthropic), multi-turn conversations with tool use fail with the following error:Root Cause
Claude Extended Thinking requires that assistant messages must start with a
thinkingorredacted_thinkingblock when thinking is enabled. However, OpenCode's message reconstruction does not guarantee this ordering.Code Analysis
In
packages/opencode/src/session/message-v2.ts, thetoModelMessagefunction builds message parts in iteration order:The
partsare sorted by their generated ID:In
packages/opencode/src/provider/transform.ts, thenormalizeMessagesfunction for Anthropic only filters empty content but does not reorder parts to ensurereasoningblocks come first:Reproduction Steps
claude-sonnet-4-5withthinking.budgetTokens > 0)tool_useat position 0Proposed Fix
Add reordering logic in
normalizeMessagesfor Anthropic models to ensurereasoningparts always come before other content types:Environment
Related