feat(ai): round-trip Anthropic redacted thinking blocks - #38614
Merged
Conversation
rekram1-node
force-pushed
the
redacted-thinking
branch
from
July 24, 2026 04:37
28b20ce to
5ab8aa8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Anthropic Messages protocol silently dropped
redacted_thinkingcontent blocks: they fell through every branch of the stream parser, and there was no assistant-lowering path to send them back. Anthropic requires redacted thinking blocks to round-trip verbatim, so multi-turn thinking + tool-use conversations that hit safety filtering would lose reasoning continuity (or get rejected on the follow-up request).Solution
Model redacted thinking the same way Vercel's
@ai-sdk/anthropicdoes:redacted_thinkingcontent_block_startemitsreasoning-startwithproviderMetadata: { anthropic: { redactedData } }and empty text; the existingcontent_block_stophandling closes the part, and response assembly carries the metadata into the finalReasoningPart.part.encryptedoranthropic.signaturemetadata) still lower tothinking; signature-less parts carryinganthropic.redactedDatalower to{ type: "redacted_thinking", data }verbatim. Same precedence order as the AI SDK.AnthropicRedactedThinkingBlockin the assistant block union;datafield on the stream block schema.Tests
round-trips redacted thinking as redacted_thinking blocks— mixed redacted + signed reasoning parts lower to the correct block types in order.parses redacted thinking into empty reasoning with redactedData metadata— stream fixture assertsreasoning-startmetadata and the assembled empty-text reasoning part.bun test(330 pass) andbun typecheckclean frompackages/ai.