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
{{ message }}
Repository navigation
[BUG] ChatCompletionStreamResponseDelta.content is required but streaming first chunk has no content #29
The ChatCompletionStreamResponseDelta.content field in inference_gateway/models.py is typed as str (required), but in streaming chat completions the first chunk typically contains only role with no content. This causes ValidationError when parsing the initial stream chunk.
Impact
Consumers using CreateChatCompletionStreamResponse.model_validate() on the first stream chunk will get a ValidationError because content is missing
The example code in examples/chat/main.py and examples/chat/README.md has to wrap validation in try/except to handle this, which is a workaround for a model bug
Location
inference_gateway/models.py line 534: content: str
Suggested Fix
Change content: str to content: str | None = None in ChatCompletionStreamResponseDelta to match the actual streaming protocol behavior.
Fixed: ChatCompletionStreamResponseDelta.content is now optional
The first streaming chunk carries only role (no content), which made model_validate() raise ValidationError because the generated content field was required. Since models.py is generated from openapi.yaml, the fix is applied at the spec level (not by hand-editing generated output).
Validation: I could not run pytest/black/mypy here — this sandbox denies pip install, so dev deps aren't available (please add the relevant tools to --allowedTools if you'd like me to run the suite in-job). What I verified manually:
python -m py_compile passes on all edited .py files
New/changed lines are within black's line-length = 100; imports follow isort (black profile) ordering
CI (black --check . + pytest tests/) will confirm on the PR
Cross-repo (source of truth):openapi.yaml is vendored from inference-gateway/schemas. The same change is needed there, otherwise the next task generate re-downloads the spec and reverts the vendored copy. I did not push to schemas automatically — say the word and I'll open that PR too.
Heads-up (out of scope for this issue): validating a full real streaming chunk via CreateChatCompletionStreamResponse.model_validate() can still fail on other strict fields — ChatCompletionStreamChoice.finish_reason is required and its enum doesn't allow null, and index is required. This issue asked specifically about content, so I kept the fix focused (the regression test validates the delta directly). Happy to file a follow-up to relax those too if you want robust full-chunk validation.
Activity
edenreich commentedon Jun 6, 2026
@claude Can you work on this? use /maintainer
claude commentedon Jun 6, 2026
Claude finished @edenreich's task in 10m 48s —— View job •
fix/issue-29-20260606-1249• [Create PR ➔](https://github.com/inference-gateway/python-sdk/compare/main...fix/issue-29-20260606-1249?quick_pull=1&title=Issue%20%2329%3A%20Changes%20from%20Claude&body=This%20PR%20addresses%20issue%20%2329%0A%0AGenerated%20with%20%5BClaude%20Code%5D(https%3A%2F%2Fclaude.ai%2Fcode)Fixed:
ChatCompletionStreamResponseDelta.contentis now optionalThe first streaming chunk carries only
role(nocontent), which mademodel_validate()raiseValidationErrorbecause the generatedcontentfield was required. Sincemodels.pyis generated fromopenapi.yaml, the fix is applied at the spec level (not by hand-editing generated output).Done:
models.py,openapi.yaml,Taskfile.yml, examples, tests)openapi.yaml— droppedcontentfrom therequiredlist ofChatCompletionStreamResponseDeltainference_gateway/models.py—content: str | None = None(matches regeneration)examples/chat/main.py+README.md— removed thetry/except ValidationErrorworkaroundtests/test_client.py— addedtest_stream_response_delta_allows_missing_contentValidation: I could not run
pytest/black/mypyhere — this sandbox deniespip install, so dev deps aren't available (please add the relevant tools to--allowedToolsif you'd like me to run the suite in-job). What I verified manually:python -m py_compilepasses on all edited.pyfilesline-length = 100; imports follow isort (black profile) orderingblack --check .+pytest tests/) will confirm on the PRPR: #31
· branch
fix/issue-29-20260606-1249feat: add openai-compatible chat completion parameters
feat: regenerate SDK with OpenAI-compatible chat params (schemas#71) (#…
chore(release): 0.8.0 [skip ci]