Backport: fix(anthropic): allow null content in compaction_delta streaming schema#12718
Merged
vercel-ai-sdk[bot] merged 1 commit intorelease-v5.0from Feb 20, 2026
Merged
Conversation
…ma (#12471) ## Background PR #12384 introduced support for Anthropic's compaction feature, but the streaming Zod schema for compaction_delta events requires content to be a non-nullable string. Anthropic's API sends compaction_delta events with content: null (e.g. the initial frame before the compaction summary text), which causes Zod validation to fail at runtime. ## Summary Changed content: z.string() to content: z.string().nullish() in the compaction_delta streaming schema in packages/anthropic/src/anthropic-messages-api.ts. This matches the existing content_block_start schema for compaction, which already uses .nullish(). ## Manual Verification Reproduction requires streaming a conversation that exceeds the compaction trigger threshold (50k+ tokens) with @ai-sdk/anthropic, which triggers a compaction_delta event with content: null. This is not practical to verify without an API key and a large conversation, but the added regression test simulates this exact scenario by streaming a compaction_delta chunk with content: null. ## Checklist - Tests have been added / updated (for bug fixes / features) - Documentation has been added / updated (for bug fixes / features) - A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root) - I have reviewed this pull request (self-review) ## Related Issues Fixes #12470 --------- Co-authored-by: Embedder <215220128+embedder-dev@users.noreply.github.com> Co-authored-by: Aayush Kapoor <83492835+aayush-kapoor@users.noreply.github.com>
aayush-kapoor
approved these changes
Feb 20, 2026
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.
This is an automated backport of #12471 to the release-v5.0 branch. FYI @leog25