Repository navigation
fix: read stream chunks as JSON in chat examples - #178
Merged
Merged
Conversation
CreateChatCompletionStreamResponse rejects standard OpenAI chunks (null finish_reason, deltas without role/content), so the streaming examples silently printed nothing. Read the parsed JSON directly. Closes #172 Co-authored-by: Eden Reich <[email protected]>
This was referenced Nov 17, 2026
Closed
Contributor
|
@claude can you remove the reference for an issue in the examples, and add this guideline to your AGENTS.md referencing issue numbers in docs is not allowed. |
Contributor
Author
|
Claude finished @edenreich's task in 25s —— View job Done
|
Co-authored-by: Eden Reich <[email protected]>
3 tasks
inference-gateway-releaser Bot
added a commit
that referenced
this pull request
Nov 17, 2026
## [0.26.0](v0.25.0...v0.26.0) (2026-11-17) ### ✨ Features * sync schemas v1.14.1 and accept standard OpenAI stream chunks ([#182](#182)) ([d4e2634](d4e2634)), closes [#181](#181) ### 🐛 Bug Fixes * allow null stop_reason in Messages stream message_start ([#179](#179)) ([cb9440e](cb9440e)) * read stream chunks as JSON in chat examples ([#178](#178)) ([fca4630](fca4630)), closes [#172](#172) ### 👷 CI * align Dependabot schedule and grouping ([#169](#169)) ([3f5ad19](3f5ad19)) * set up orchestrators from repos.yaml ([#170](#170)) ([bffe983](bffe983)) ### 📚 Documentation * add audio example for speech, sfx and music ([#176](#176)) ([c1f04d0](c1f04d0)) * add Responses API example and README section ([#180](#180)) ([ec0e02a](ec0e02a)) * sync examples and README with gateway config ([#177](#177)) ([ee0999d](ee0999d)) ### 🔧 Miscellaneous * **deps:** bump flox dependencies to latest ([#167](#167)) ([55f32c5](55f32c5)) * **deps:** bump flox dependencies to latest ([#168](#168)) ([de020e9](de020e9))
Contributor
|
🎉 This PR is included in version 0.26.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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.
Summary
CreateChatCompletionStreamResponse(generated from the upstream spec) requires a non-nullfinish_reasonand bothdelta.roleanddelta.contenton every chunk. Standard OpenAI-format chunks relayed by the gateway break all three rules, so the streaming examples rejected every chunk onValidationErrorand printed nothing.This PR changes the three streaming snippets to read the parsed JSON dict directly instead of validating with the strict model:
examples/chat/main.py- iteratesdata.get("choices", []), printsdelta.content, and prints[Finished: ...]for a non-nullfinish_reason. Dropped the now-unusedValidationError,CreateChatCompletionStreamResponseandSSEventimports.README.md"Streaming Content" - same approach, keeps thereasoning/reasoning_contenthandling, plus a note explaining why.examples/chat/README.md- same approach with a short note.inference_gateway/models.pyis not touched (generated code). The real fix is relaxing the spec upstream ininference-gateway/schemasand runningtask generate. The strict xfailtest_stream_response_delta_allows_missing_contentstays in place and will flip once that lands.Tests
examples/chat/main.pywith a mockedrequests.Session.post: it now printsAssistant: Helloand[Finished: stop](before: an empty line).task lint- passes (black, isort, mypy).task test- 53 passed, 1 xfailed (unchanged).Downstream impact
inference-gateway/schemas- the stream chunk spec needs a nullablefinish_reasonand optionalrole/contentonChatCompletionStreamResponseDelta. Tracked in a follow-up issue. Other generated SDKs likely have the same strict model.inference-gateway/docs-sdks.mdshows the same strict-model streaming snippet. Tracked in a[DOCS]issue.Closes #172
Generated with Claude Code