Skip to content

fix(anthropic): handle vertex_event SSE events from Vertex AI Anthropic provider - #13576

Open
BillionClaw wants to merge 1 commit into
vercel:mainfrom
BillionClaw:clawoss/fix/vertex-anthropic-streaming
Open

fix(anthropic): handle vertex_event SSE events from Vertex AI Anthropic provider#13576
BillionClaw wants to merge 1 commit into
vercel:mainfrom
BillionClaw:clawoss/fix/vertex-anthropic-streaming

Conversation

@BillionClaw

Copy link
Copy Markdown

Problem

When using streamText with the Vertex AI Anthropic provider, streaming fails immediately because Vertex sends additional vertex_event SSE events that aren't recognized by the SDK.

These events contain usage information that cause type validation errors, resulting in the stream finishing immediately instead of properly streaming.

Solution

  1. Added vertex_event to the anthropicMessagesChunkSchema with the usage field structure
  2. Handle vertex_event in the transform stream (ignored like ping events)

This follows the same pattern used by other providers that handle provider-specific SSE events.

Changes

  • packages/anthropic/src/anthropic-messages-api.ts: Added vertex_event schema definition
  • packages/anthropic/src/anthropic-messages-language-model.ts: Added handler for vertex_event type

Fixes #13350

@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 provider/google-vertex Issues related to the @ai-sdk/google-vertex provider labels Mar 18, 2026
Comment on lines +1324 to +1331
z.object({
type: z.literal('vertex_event'),
usage: z.looseObject({
input_tokens: z.number(),
output_tokens: z.number(),
cache_creation_input_tokens: z.number().nullish(),
cache_read_input_tokens: z.number().nullish(),
}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
z.object({
type: z.literal('vertex_event'),
usage: z.looseObject({
input_tokens: z.number(),
output_tokens: z.number(),
cache_creation_input_tokens: z.number().nullish(),
cache_read_input_tokens: z.number().nullish(),
}),
z.looseObject({
type: z.literal('vertex_event'),

The vertex_event schema requires usage with mandatory input_tokens and output_tokens fields, but the event data is never used — causing unnecessary validation failures if Vertex AI sends vertex_event events with a different shape.

Fix on Vercel

@Mati0kez

Copy link
Copy Markdown

Friendly bump -- this PR has been open for a while. Happy to make any changes if needed, or close it if no longer relevant.

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 provider/google-vertex Issues related to the @ai-sdk/google-vertex provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants