fix(anthropic): handle vertex_event SSE events from Vertex AI Anthropic provider - #13576
Open
BillionClaw wants to merge 1 commit into
Open
fix(anthropic): handle vertex_event SSE events from Vertex AI Anthropic provider#13576BillionClaw wants to merge 1 commit into
BillionClaw wants to merge 1 commit into
Conversation
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(), | ||
| }), |
Contributor
There was a problem hiding this comment.
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.
|
Friendly bump -- this PR has been open for a while. Happy to make any changes if needed, or close it if no longer relevant. |
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
When using streamText with the Vertex AI Anthropic provider, streaming fails immediately because Vertex sends additional
vertex_eventSSE 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
vertex_eventto theanthropicMessagesChunkSchemawith the usage field structurevertex_eventin the transform stream (ignored like ping events)This follows the same pattern used by other providers that handle provider-specific SSE events.
Changes
Fixes #13350