[bug] v0.8.0 Introduced thinking block bug with Claude Sonnet 4: "AI_APICallError: messages.3.content.0.type: Expected thinking or redacted_thinking, but found text." #1718

Closed
opened 2026-02-16 17:32:19 -05:00 by yindo · 7 comments
Owner

Originally created by @grantjayy on GitHub (Sep 14, 2025).

Originally assigned to: @thdxr on GitHub.

When using Claude Sonnet 4 with thinking enabled on Opencode v0.8.0, an Anthropic api error happens after tool invocation. Only happens after tool call (specifically read).

This bug is not present in Opencode v0.7.9.

Here is a share URL of the chat context: https://opencode.ai/s/6z4bcRrU

Here is the full API error (not listed in chat context):

AI_APICallError: messages.3.content.0.type: Expected `thinking` or
`redacted_thinking`, but found `text`. 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`. Please consult our documentation
at https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking

Here is my .opencode.json config:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "anthropic": {
      "options": {
        "headers": {
          "anthropic-beta": "context-1m-2025-08-07"
        }
      },
      "models": {
        "claude-opus-4-1-20250805": {
          "limit": {
            "context": 200000,
            "output": 12288
          },
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 1024
            }
          }
        },
        "claude-sonnet-4-20250514": {
          "limit": {
            "context": 1000000,
            "output": 59904
          },
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 4096
            }
          }
        }
      }
    }
  },
  "agent": {
    "CSS Tailwind (Build)": {
      "mode": "primary",
      "model": "claude-opus-4-1-20250805",
      "description": "Agent for handling HTML with Tailwind CSS",
      "prompt": "{file:<txt-file>}"
    }
  }
}
Originally created by @grantjayy on GitHub (Sep 14, 2025). Originally assigned to: @thdxr on GitHub. When using Claude Sonnet 4 with thinking enabled on Opencode v0.8.0, an Anthropic api error happens after tool invocation. Only happens after tool call (specifically `read`). This bug is not present in Opencode v0.7.9. Here is a share URL of the chat context: https://opencode.ai/s/6z4bcRrU Here is the full API error (not listed in chat context): ``` AI_APICallError: messages.3.content.0.type: Expected `thinking` or `redacted_thinking`, but found `text`. 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`. Please consult our documentation at https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking ``` Here is my .opencode.json config: ``` { "$schema": "https://opencode.ai/config.json", "provider": { "anthropic": { "options": { "headers": { "anthropic-beta": "context-1m-2025-08-07" } }, "models": { "claude-opus-4-1-20250805": { "limit": { "context": 200000, "output": 12288 }, "options": { "thinking": { "type": "enabled", "budgetTokens": 1024 } } }, "claude-sonnet-4-20250514": { "limit": { "context": 1000000, "output": 59904 }, "options": { "thinking": { "type": "enabled", "budgetTokens": 4096 } } } } } }, "agent": { "CSS Tailwind (Build)": { "mode": "primary", "model": "claude-opus-4-1-20250805", "description": "Agent for handling HTML with Tailwind CSS", "prompt": "{file:<txt-file>}" } } } ```
yindo closed this issue 2026-02-16 17:32:19 -05:00
Author
Owner

@rekram1-node commented on GitHub (Sep 14, 2025):

thanks for raising, looks like it was due to these changes: https://github.com/sst/opencode/pull/2577

@rekram1-node commented on GitHub (Sep 14, 2025): thanks for raising, looks like it was due to these changes: https://github.com/sst/opencode/pull/2577
Author
Owner

@rekram1-node commented on GitHub (Sep 14, 2025):

I think the issue is that "providerOptions": {
"anthropic": {
"signature": "...."
}
}

Isn't being saved to the reasoning messages

shouldn't be hard to fix just need to find where

@rekram1-node commented on GitHub (Sep 14, 2025): I think the issue is that "providerOptions": { "anthropic": { "signature": "...." } } Isn't being saved to the reasoning messages shouldn't be hard to fix just need to find where
Author
Owner

@rekram1-node commented on GitHub (Sep 14, 2025):

should be fixed in next release I tested with quite a few models

@rekram1-node commented on GitHub (Sep 14, 2025): should be fixed in next release I tested with quite a few models
Author
Owner

@jessevdp commented on GitHub (Oct 2, 2025):

I'm running into a similar issue with Claude 4.5 Sonnet hosted on Google Vertex (through openai-compatible proxy: LiteLLM...)

messages.3.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`. Please consult our documentation at https://docs.claude.com/en/docs/build-with-claude/extended-thinking
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "messages.3.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`. Please consult our documentation at https://docs.claude.com/en/docs/build-with-claude/extended-thinking"
  },
  "request_id": "..."
}

Should I open a separate issue?

@jessevdp commented on GitHub (Oct 2, 2025): I'm running into a similar issue with Claude 4.5 Sonnet hosted on Google Vertex (through openai-compatible proxy: LiteLLM...) ``` messages.3.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`. Please consult our documentation at https://docs.claude.com/en/docs/build-with-claude/extended-thinking ``` ```json { "type": "error", "error": { "type": "invalid_request_error", "message": "messages.3.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`. Please consult our documentation at https://docs.claude.com/en/docs/build-with-claude/extended-thinking" }, "request_id": "..." } ``` Should I open a separate issue?
Author
Owner

@VisionaryOS commented on GitHub (Dec 27, 2025):

still running into this frequently "messages.101: The final block in an assistant message cannot be thinking" every few tasks with claude opus in opencode

@VisionaryOS commented on GitHub (Dec 27, 2025): still running into this frequently "messages.101: The final block in an assistant message cannot be `thinking`" every few tasks with claude opus in opencode
Author
Owner

@rekram1-node commented on GitHub (Dec 27, 2025):

@VisionaryOS can u share a session?

opencode export > session.json

@rekram1-node commented on GitHub (Dec 27, 2025): @VisionaryOS can u share a session? opencode export > session.json
Author
Owner

@Alumniminium commented on GitHub (Jan 7, 2026):

messages.581.content.0: When thinking is disabled, an assistantmessage in the final position cannot containthinking. To use thinking blocks, enable thinking in your request.

getting this constantly with claude opus with thinking mode on, usually after it calls MCPs, the next message has <thinking> tags visible and then when it stops generating, the error pops

I think this is somehow related to plugins and noReply/ignore messages.

@Alumniminium commented on GitHub (Jan 7, 2026): `messages.581.content.0: When thinking is disabled, an `assistant` message in the final position cannot contain `thinking`. To use thinking blocks, enable `thinking` in your request.` getting this constantly with claude opus with thinking mode on, usually after it calls MCPs, the next message has `<thinking>` tags visible and then when it stops generating, the error pops I think this is somehow related to plugins and noReply/ignore messages.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1718