Skip to content

fix: emit integer output_index in Chat Completions streaming events#3113

Closed
Quratulain-bilal wants to merge 2 commits intoopenai:mainfrom
Quratulain-bilal:fix/chatcmpl-output-index-bool-expression
Closed

fix: emit integer output_index in Chat Completions streaming events#3113
Quratulain-bilal wants to merge 2 commits intoopenai:mainfrom
Quratulain-bilal:fix/chatcmpl-output-index-bool-expression

Conversation

@Quratulain-bilal
Copy link
Copy Markdown
Contributor

Fixes #3109. The Chat Completions streaming handler computed output_index as
state.reasoning_content_index_and_output is not None, yielding bool instead of int across 7 event sites.
Replaced each with 1 if state.reasoning_content_index_and_output else 0 (the existing correct pattern
at line 426). All 396 model tests pass; ruff + format clean.

The Chat Completions streaming handler was computing output_index as
`state.reasoning_content_index_and_output is not None`, which evaluates
to a `bool` (True/False). Downstream consumers and the response event
schema expect an `int` (0 or 1).

Although Python's `bool` is a subclass of `int`, this leaks `True`/`False`
through to JSON serialization and to consumers that compare or index by
the integer value, causing subtle mismatches with the Responses API
contract used elsewhere in the SDK.

Replace each occurrence with the explicit conditional already used at
one site in the same file: `1 if state.reasoning_content_index_and_output else 0`.

Fixes openai#3109.
@github-actions github-actions Bot added bug Something isn't working feature:chat-completions labels May 4, 2026
@seratch seratch marked this pull request as draft May 4, 2026 13:21
@Quratulain-bilal Quratulain-bilal marked this pull request as ready for review May 4, 2026 17:09
@seratch
Copy link
Copy Markdown
Member

seratch commented May 5, 2026

#3108 covers more scenarios, so let us close this one.

@seratch seratch closed this May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:chat-completions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat Completions streaming computes assistant output_index with a bool expression

2 participants