Skip to content

fix: read stream chunks as JSON in chat examples - #178

Merged
edenreich merged 2 commits into
mainfrom
fix/issue-172-20261117-1939
Nov 17, 2026
Merged

edenreich merged 2 commits into
mainfrom
fix/issue-172-20261117-1939

Conversation

@inference-gateway-maintainer

Copy link
Copy Markdown
Contributor

Summary

CreateChatCompletionStreamResponse (generated from the upstream spec) requires a non-null finish_reason and both delta.role and delta.content on every chunk. Standard OpenAI-format chunks relayed by the gateway break all three rules, so the streaming examples rejected every chunk on ValidationError and 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 - iterates data.get("choices", []), prints delta.content, and prints [Finished: ...] for a non-null finish_reason. Dropped the now-unused ValidationError, CreateChatCompletionStreamResponse and SSEvent imports.
  • README.md "Streaming Content" - same approach, keeps the reasoning / reasoning_content handling, plus a note explaining why.
  • examples/chat/README.md - same approach with a short note.

inference_gateway/models.py is not touched (generated code). The real fix is relaxing the spec upstream in inference-gateway/schemas and running task generate. The strict xfail test_stream_response_delta_allows_missing_content stays in place and will flip once that lands.

Tests

Downstream impact

  • inference-gateway/schemas - the stream chunk spec needs a nullable finish_reason and optional role / content on ChatCompletionStreamResponseDelta. Tracked in a follow-up issue. Other generated SDKs likely have the same strict model.
  • inference-gateway/docs - sdks.md shows the same strict-model streaming snippet. Tracked in a [DOCS] issue.

Closes #172

Generated with Claude Code

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]>
@edenreich

Copy link
Copy Markdown
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.

@inference-gateway-maintainer

inference-gateway-maintainer Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Claude finished @edenreich's task in 25s —— View job


Done

  • Removed the #172 links from README.md (Streaming Content note) and examples/chat/README.md. The notes still explain why the strict model isn't used.
  • Added a rule to AGENTS.md under Code Readability: no issue or PR numbers or links in docs, examples or code comments. Explain the reason in place instead. Issue references go in commit messages and PR descriptions.
  • Pushed in commit 9fd4ece

examples/chat/main.py didn't reference any issue, so it's unchanged. The PR description still says Closes #172. That's on purpose because it links the PR to the issue. I didn't run lint or tests because only Markdown changed.
| Branch

@edenreich
edenreich merged commit fca4630 into main Nov 17, 2026
1 check passed
@edenreich
edenreich deleted the fix/issue-172-20261117-1939 branch November 17, 2026 20:08
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))
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.26.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Chat stream chunk model rejects standard OpenAI chunks - streaming examples print nothing

1 participant