Skip to content

[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." #2599

Closed

Description

@grantjayy

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>}"
    }
  }
}

Activity

  1. rekram1-node commented on Sep 14, 2025

    @rekram1-node
    Contributor

    thanks for raising, looks like it was due to these changes: #2577

  2. rekram1-node commented on Sep 14, 2025

    @rekram1-node
    Contributor

    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

  3. rekram1-node commented on Sep 14, 2025

    @rekram1-node
    Contributor

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

  4. jessevdp commented on Oct 2, 2025

    @jessevdp
    Contributor

    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?

  5. VisionaryOS commented on Dec 27, 2025

    @VisionaryOS

    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

  6. rekram1-node commented on Dec 27, 2025

    @rekram1-node
    Contributor

    @VisionaryOS can u share a session?

    opencode export > session.json

  7. Alumniminium commented on Jan 7, 2026

    @Alumniminium

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions