fix(types): make logprobs Optional in response event types (fixes #2489)#2914
fix(types): make logprobs Optional in response event types (fixes #2489)#2914giulio-leone wants to merge 1 commit intoopenai:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #2489 by making the logprobs field optional (defaulting to None) in ResponseTextDeltaEvent and ResponseTextDoneEvent. Non-OpenAI providers (e.g., litellm, Anthropic proxies) may omit logprobs in streaming responses, which previously caused a pydantic ValidationError. The change aligns these event types with ResponseOutputText, which already treats logprobs as Optional.
Changes:
logprobsmadeOptional[List[Logprob]] = NoneinResponseTextDeltaEventlogprobsmadeOptional[List[Logprob]] = NoneinResponseTextDoneEvent- 6 regression tests added covering with/without/empty logprobs for both event types
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/openai/types/responses/response_text_delta_event.py |
Makes logprobs optional with a None default |
src/openai/types/responses/response_text_done_event.py |
Makes logprobs optional with a None default |
tests/test_response_event_logprobs.py |
Adds regression tests for the optional logprobs behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Remove unused `pytest` and `Logprob` imports flagged by Copilot review. Refs: openai#2914
3fc8453 to
799afa6
Compare
Note that logprobs fields were manually changed to Optional in the auto-generated files, referencing issue openai#2489. Also fix import sorting in the test file. Refs: openai#2914
aea1876 to
0571026
Compare
ea170bb to
881445e
Compare
881445e to
85c4e54
Compare
85c4e54 to
658b1f5
Compare
|
Intervention note for this PR: Current blocker appears to be missing CI execution rather than failing jobs:
Suggested unblock sequence:
If useful, I can run a follow-up status sweep as soon as checks are attached. |
Summary
Fixes #2489 — Validation error for
ResponseTextDeltaEventafter updating to v1.97.1.Root Cause
The
logprobsfield inResponseTextDeltaEventandResponseTextDoneEventis required, but non-OpenAI providers (litellm, Anthropic proxies) may not include it in streaming responses. This causes apydantic ValidationErrorwhen parsing those responses.Changes
logprobsfieldOptional[List[Logprob]] = Nonein:ResponseTextDeltaEventResponseTextDoneEventlogprobscontinue to work as beforeNote
ResponseOutputTextalready haslogprobsasOptional, so this aligns the event types with that pattern.Fixes #2489