-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Streaming: introduce opt-in unified StreamEvent (+ adapters, example, tests) #2650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Streaming: introduce opt-in unified StreamEvent (+ adapters, example, tests) #2650
Conversation
Hi team 👋
I believe this PR is valuable because it addresses a real developer experience gap: today responses.stream()
and chat.completions.stream()
emit different event shapes, which makes code harder to reuse.
By introducing a unified StreamEvent
with a simple helper (extract_text
), we get:
- Consistent handling of text deltas and completion signals
- A foundation to later support tool-calling and error events
- A smoother DX without breaking existing behavior
This is opt-in and fully backward-compatible, with basic tests and an example included. I think it can really help developers adopt streaming more easily. 🚀
Thanks for the PR but this is not something we want to do. The APIs are sufficiently different that it does not make sense to coalesce them.
Thanks for taking the time to review this, Robert — I completely understand your reasoning here.
When you have a chance, could you also take a look at my other open PRs (#2596, #2597, #2615, #2616, #2645)? They’re smaller in scope and more focused on tests/examples. I’d really appreciate your feedback on those.
Thanks again for your guidance!
Summary
This PR introduces an opt-in unified streaming event shape for both
responses.stream()
andchat.completions.stream()
:StreamEvent
+extract_text
helper for consistent DX.examples/async_stream_unified.py
.Why
Currently the two streaming APIs emit different shapes. A unified, typed surface:
output_text.delta
)response.completed
)Notes
.stream()
behavior is unchanged.Follow-ups (planned)
unified=True
flag in.stream()
to yieldStreamEvent
directly.