Anthropic's 'thinking' content blocks and deltas are missing from streaming responses when using Claude Opus 4. Additionally, when explicitly enabling thinking with thinking(AnthropicApi.ThinkingType.ENABLED, 2048), a 400 BAD REQUEST error occurs with the message "Expected thinking or redacted_thinking but found tool_use. When thinking is enabled a final assistant message must start with thinking block."
Environment
Spring AI version: 1.0.2 Model: claude-opus-4-0 and claude-3-7-sonnet-latest Additional context: Tool use is enabled
Steps to reproduce
Following examples from (https://docs.spring.io/spring-ai/reference/api/chat/anthropic-chat.html#_streaming_example)
Scenario 1: Missing thinking content with Claude Opus 4
javaFlux
Scenario 2: 400 BAD REQUEST with explicit thinking enabled
javaFlux
Throws: "Expected thinking or redacted_thinking but found tool_use. When thinking is enabled a final assistant message must start with thinking block."
Expected behavior
Scenario 1: Thinking content blocks and deltas should be included in the streaming response metadata when using Claude Opus 4 Scenario 2: When explicitly enabling thinking, the request should succeed and return thinking content without throwing a 400 BAD REQUEST error
Actual behavior
Scenario 1: Thinking events in metadata are never emitted despite tool use being enabled Scenario 2: Request fails with "400 BAD REQUEST, Expected thinking or redacted_thinking but found tool_use. When thinking is enabled a final assistant message must start with thinking block"
Comment From: dolukhanov
Getting the same issue also in 1.1.0-M3