-
Notifications
You must be signed in to change notification settings - Fork 660
Closed
Labels
Milestone
Description
Currently, in the raw_model_stream_event type, when the data.type field is "model", we expose an event field whose type is declared as any (courtesy of StreamEventGenericItem). This means consumers lose all type-safety and autocompletion on the shape of the event payload.
Steps to Reproduce:
- In the OpenAI client, import or interact with the streaming API.
- Inspect the TypeScript definition of
raw_model_stream_event. - Note that
data.eventis typed asanyunder the hood.
export declare const StreamEventGenericItem: z.ZodObject<{
/**
* Additional optional provider specific data. Used for custom functionality or model provider
* specific fields.
*/
providerData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
} & {
type: z.ZodLiteral<"model">;
event: z.ZodAny;
}, "strip", z.ZodTypeAny, {
type: "model";
providerData?: Record<string, any> | undefined;
event?: any;
}, {
type: "model";
providerData?: Record<string, any> | undefined;
event?: any;
}>;
Expected Behavior:
- The
eventproperty should be strongly typed to match what the API actually returns for model-stream events. - We should leverage the existing
ResponseStreamEventtype defined inopenai/resources/responses/responses.mjsrather than falling back toany.
Suggested Solution:
- Update the definition of
StreamEventGenericItem<T>(or whereverStreamEventGenericItemis used) so that whendata.type === 'model', theeventfield is typed asResponseStreamEvent. - Ensure that
ResponseStreamEventis properly imported fromopenai/resources/responses/responses.mjs. - Add any needed unit tests or type assertions to verify that the change provides correct type-checking and does not break existing uses.
Additional Context:
The change will improve DX by restoring full type-safety and IntelliSense when handling streaming responses from model endpoints. This aligns with the rest of the client library’s emphasis on precise typings.
Reactions are currently unavailable