feat(openai): native content-block streaming for chat completions#37999
Open
Nick Hollon (nick-hollon-lc) wants to merge 1 commit into
Open
Conversation
bb7bc73 to
406736a
Compare
1202519 to
770135f
Compare
406736a to
a3ef4d9
Compare
770135f to
b67eab5
Compare
This was referenced Jun 10, 2026
a3ef4d9 to
f7d7e0b
Compare
b67eab5 to
7a7f79a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on the shared
BlockStreamTrackerto giveChatOpenAInative content-block streaming events for the Chat Completions path, sostream_events(version="v3")no longer rides the compat bridge for plain OpenAI streaming.What it does
A thin pure converter (
convert_openai_completions_stream/ async twin) drives raw OpenAI Chat Completions chunks into the shared tracker, reusing the existing_convert_chunk_to_generation_chunkfor content extraction — the same two-layer pattern Anthropic uses.BaseChatOpenAIgains_stream_chat_model_events/_astream_chat_model_events(the hooks core detects);ChatOpenAIand Azure inherit them. The converters are exported so the OpenAI-compatible providers (deepseek, fireworks, groq, xai, openrouter) can reuse them in follow-up PRs — either as a direct pass-through or via a small chunk adapter.Scope and deferrals
This PR specializes the Chat Completions path only. The hooks defer to the existing compat bridge — unchanged behavior — when any of these apply:
_use_responses_api); a native Responses converter is the next PR,response_format, including when set viamodel_kwargs), whoseget_final_completion()flow the native path doesn't reproduce,include_response_headers).The deferral guard mirrors
ChatOpenAI._stream's own dispatch so the Responses path is never hijacked.Worth careful review
_stream's routing exactly. A test (test_response_format_in_model_kwargs_takes_bridge_path) is mutation-verified to fail if themodel_kwargsbranch of the guard is removed.stream_chunk_timeoutby wrapping the stream the same way_astreamdoes.test_openai_stream_events_v3_lifecycle, which previously exercised the bridge and now routes through the native hook unchanged (plus a new async twin).Known limitation
On the v3 events path
on_llm_new_tokenis called with text only (the legacychunk=/logprobs=kwargs aren't threaded through the pure converter); the lifecycle events themselves carry the block and usage detail. Flagged in-code.