Skip to content

Backport: fix(anthropic): allow null content in compaction_delta streaming schema#12718

Merged
vercel-ai-sdk[bot] merged 1 commit intorelease-v5.0from
backport-pr-12471-to-release-v5.0
Feb 20, 2026
Merged

Backport: fix(anthropic): allow null content in compaction_delta streaming schema#12718
vercel-ai-sdk[bot] merged 1 commit intorelease-v5.0from
backport-pr-12471-to-release-v5.0

Conversation

@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

@vercel-ai-sdk vercel-ai-sdk bot commented Feb 20, 2026

This is an automated backport of #12471 to the release-v5.0 branch. FYI @leog25

…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>
@vercel-ai-sdk vercel-ai-sdk bot enabled auto-merge (squash) February 20, 2026 00:45
@tigent tigent bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/anthropic Issues related to the @ai-sdk/anthropic provider labels Feb 20, 2026
@vercel-ai-sdk vercel-ai-sdk bot merged commit b153525 into release-v5.0 Feb 20, 2026
24 checks passed
@vercel-ai-sdk vercel-ai-sdk bot deleted the backport-pr-12471-to-release-v5.0 branch February 20, 2026 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/anthropic Issues related to the @ai-sdk/anthropic provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants