You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See #8: A crucial piece of functionality still missing in our SDK is response streaming - a quite complex piece of functionality to get right, especially with the incomplete documentation of how different providers implement it. But we need it, that's for sure.
What we'll need to do is:
Implement the primitives needed for streaming (likely some kind of stream response class, potentially a new stream method on HttpTransporter).
Implement actual streaming for the three providers (which can fortunately be centralized in the OpenAI API compatible implementation for now).
Putting here some references for inspiration in how I implemented streaming (still with some limitations) in the AI Services plugin for WordPress:
There's definitely things to improve there which we should do here, but it's a decent starting point to review this and come up with effectively a v2 of that implementation.
I'm picking this up. Before implementing this, here's what I'm planning:
Extend the HTTP DTOs
Add a stream option to RequestOptions to request a streamed response.
Extend the Response DTO to expose the body as a stream.
Extend the HttpTransporter to support streaming when sending the request and building the Response.
Add an SSE-spec-compliant parser behind an EventStreamParserInterface, so providers can plug in their own parser or fall back to the default.
Add a GenerativeAiResultChunk DTO and a StreamingTextGenerationModelInterface so models can expose streaming text generation and yield result chunks (which can be aggregated back into a final GenerativeAiResult).
Extend the PromptBuilder (and the AiClient facade) with streaming entry points.
Dispatch before/after events for streaming, mirroring the current before/after response events where the "after" firing happens once the stream completes, with the aggregated result.
I think this is sufficient within the scope of this SDK; individual providers can extend it based on their own SSE specifics.
Reacted by Dovid Levine, Kaspars Dambis, Ankit Kumar Shah, Greg Ziółkowski and Yogesh Bhutkar
Activity
thelovekesh commentedon Jun 18, 2026
I'm picking this up. Before implementing this, here's what I'm planning:
RequestOptionsto request a streamed response.ResponseDTO to expose the body as a stream.HttpTransporterto support streaming when sending the request and building theResponse.EventStreamParserInterface, so providers can plug in their own parser or fall back to the default.GenerativeAiResultChunkDTO and aStreamingTextGenerationModelInterfaceso models can expose streaming text generation and yield result chunks (which can be aggregated back into a finalGenerativeAiResult).PromptBuilder(and theAiClientfacade) with streaming entry points.I think this is sufficient within the scope of this SDK; individual providers can extend it based on their own SSE specifics.