Repository navigation
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Description
When a vertex proxy sends back a vertex_event SSE event, an uncaught exception makes its way up to OpenCode.
The true cause is with ai-sdk and the bug is filed.
The fix upstream on ai-sdk is to ignore the event so I'm assuming the exception can also be safely ignored.
The bug report's likely to go stale so logging this here in case we're able to add exception handling.
For streaming proxies that present the Anthropic API to clients, but use Vertex Anthropic upstream -- Vertex returns an additional SSE event called vertex_event that breaks @ai-sdk/anthropic with the following error:
AI_APICallError: Type validation failed: Value: {"type":"vertex_event","usage":{"input_tokens":9,"output_tokens":1,"cache_
creation_input_tokens":null,"cache_read_input_tokens":null,"web_search_requests":null,"cache_creation":{"ephemeral_5m_inpu
t_tokens":0,"ephemeral_1h_input_tokens":0},"tiers":{"0-to-200000":{"input_tokens":9,"output_tokens":1,"cache_creation_inpu
t_tokens":null,"cache_read_input_tokens":null,"web_search_requests":null,"cache_creation":{"ephemeral_5m_input_tokens":0,"
ephemeral_1h_input_tokens":0}}}}}.
Error message: [
{
"code": "invalid_union",
"errors": [],
"note": "No matching discriminator",
"discriminator": "type",
"path": [
"type"
],
"message": "Invalid input"
}
]
at AnthropicMessagesLanguageModel.doStream (file:///Users/xxxxxx/.cache/deno/npm/registry.npmjs.org/@ai-sdk/anthropic
/2.0.56/src/anthropic-messages-language-model.ts:1433:15)
Clients that use the official Anthropic SDK don't suffer from this. I found that Block's Goose handles this as well.
Plugins
None
OpenCode version
1.2.6
Steps to reproduce
import { createAnthropic } from "@ai-sdk/anthropic";
import { generateText, streamText } from "ai";
const apiKey: string | undefined = Deno.env.get("ANTHROPIC_API_KEY");
const baseURL: string = `${Deno.env.get("ANTHROPIC_BASE_URL")}/v1`;
const anthropic = createAnthropic({
apiKey: apiKey,
baseURL: baseURL,
headers: { "anthropic_version": "vertex-2023-10-16" },
});
const { textStream } = streamText({
model: anthropic("claude-sonnet-4-5"),
prompt: "ping.",
});
for await (const part of textStream) {
console.log(part);
}
// non-stream works just fine
const { text } = await generateText({
model: anthropic("claude-sonnet-4-5"),
prompt: "ping.",
});
console.log(text);
console.log(baseURL);Screenshot and/or share link
No response
Operating System
macOS
Terminal
Ghostty
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
github-actions commentedon Feb 17, 2026
This issue might be a duplicate of existing issues. Please check:
Highly likely duplicates:
invalid_union— Same type validation error pattern with streamingRelated issues:
Please check if this is indeed a duplicate before proceeding. Note that you mentioned filing this upstream in @ai-sdk/anthropic (#11309), so this may need exception handling in OpenCode for the extra
vertex_eventSSE event that Vertex returns.fix: filter unknown SSE events from Anthropic-family streaming responses
nehaaprasad commentedon Feb 17, 2026
hello @audibleblink
please check out the PR!
github-actions commentedon Apr 19, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.