Skip to content

[BUG] ChatCompletionStreamResponseDelta.content is required but streaming first chunk has no content #29

Closed

Description

@inference-gateway-maintainer

Description

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.

Activity

  1. added
    bug
    on Jun 6, 2026
  2. moved this to Todo in 2026on Jun 6, 2026
  3. added theissue type on Jun 6, 2026
  4. edenreich commented on Jun 6, 2026

    @edenreich
    Contributor

    @claude Can you work on this? use /maintainer

  5. claude commented on Jun 6, 2026

    @claude
    Contributor

    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.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).

    Done:

    • Gather context (models.py, openapi.yaml, Taskfile.yml, examples, tests)
    • Understand the request & determine the correct fix path
    • openapi.yaml — dropped content from the required list of ChatCompletionStreamResponseDelta
    • inference_gateway/models.py — content: str | None = None (matches regeneration)
    • examples/chat/main.py + README.md — removed the try/except ValidationError workaround
    • tests/test_client.py — added test_stream_response_delta_allows_missing_content
    • Commit & open PR

    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.

    PR: #31
    · branch fix/issue-29-20260606-1249

  6. moved this from Todo to Done in 2026on Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions