-
Notifications
You must be signed in to change notification settings - Fork 139
Streaming Responses API fails Zod validation - usage field is null instead of object/undefined #452
Copy link
Copy link
Open
Description
Moved from OpenRouterTeam/typescript-sdk#146
Description
When using the Responses API with streaming, the response.created event fails Zod validation because the usage field is null, but the SDK schema only allows object | undefined, not null.
SDK Version
@openrouter/sdk@0.3.12
Steps to Reproduce
- Make a streaming request to the Responses API
- The first event (
response.created) triggers a ZodError
import { OpenRouter } from "@openrouter/sdk";
const client = new OpenRouter();
const response = client.callModel({
model: 'anthropic/claude-sonnet-4.5',
input: 'Hello',
});
for await (const event of response.getTextStream()) {
// Throws ZodError on first event
console.log(event);
}Error
ZodError invalid_union
ZodError: [
{
"code": "invalid_union",
"errors": [
[
{
"expected": "object",
"code": "invalid_type",
"path": [
"response",
"usage"
],
"message": "Invalid input: expected object, received null"
}
],
...
]
}
]
Expected Behavior
The SDK should handle null values for usage in streaming events, since initial events like response.created don't have usage data yet.
Workaround
None currently — the error prevents consuming the stream entirely.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels