Skip to content

fix: transform Omit values in pre-connect Realtime manager send()#3448

Open
C1-BA-B1-F3 wants to merge 1 commit into
openai:mainfrom
C1-BA-B1-F3:fix/realtime-preconnect-send-omit
Open

fix: transform Omit values in pre-connect Realtime manager send()#3448
C1-BA-B1-F3 wants to merge 1 commit into
openai:mainfrom
C1-BA-B1-F3:fix/realtime-preconnect-send-omit

Conversation

@C1-BA-B1-F3

Copy link
Copy Markdown

Fixes #3402.

Summary

The pre-connect send() methods on both AsyncRealtimeConnectionManager and RealtimeConnectionManager called json.dumps(event) directly on dict payloads, which crashed with TypeError when the event contained Omit values (e.g. event_id=omit).

The connected send() methods already used maybe_transform() to strip Omit values before serialization. This PR applies the same transformation to the pre-connect send() methods for consistency.

Changes

  • src/openai/resources/realtime/realtime.py: Updated both sync and async pre-connect send() methods to use maybe_transform(event, RealtimeClientEventParam) before json.dumps()
  • tests/test_realtime_manager_send_omit.py: Added regression tests verifying:
    • Dict events with omit values are properly stripped before serialization
    • Dict events without omit values preserve all fields
    • Multiple omit fields are all stripped correctly

Reproduction

Before this fix:

from openai import OpenAI
from openai._types import omit

client = OpenAI()
manager = client.realtime.connect(model='gpt-4o-realtime-preview')
manager.send({'type': 'response.cancel', 'event_id': omit})
# TypeError: Object of type Omit is not JSON serializable

After this fix, the omit value is stripped and the event is serialized correctly.

The pre-connect send() methods on both AsyncRealtimeConnectionManager and
RealtimeConnectionManager called json.dumps(event) directly on dict
payloads, which crashed with TypeError when the event contained Omit
values (e.g. event_id=omit).

The connected send() methods already used maybe_transform() to strip
Omit values before serialization. This commit applies the same
transformation to the pre-connect send() methods for consistency.

Fixes openai#3402
@C1-BA-B1-F3 C1-BA-B1-F3 requested a review from a team as a code owner June 26, 2026 00:35

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1279b173be

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

"""Pre-connect send() should strip all Omit values from dict events."""
manager = _make_sync_manager()

event = {"type": "response.create", "event_id": omit, "response": {"modalities": omit}}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Fix nested omit test to use the typed field

This nested omit case still raises before the assertions because modalities is not a field in the current RealtimeResponseCreateParamsParam (the typed field is output_modalities), and _transform_typeddict preserves unknown keys instead of stripping their omit values. As written, maybe_transform leaves response.modalities = omit, so json.dumps(...) fails with TypeError and the new regression test suite fails; the async copy below has the same issue.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pre-connect Realtime manager.send crashes on Omit in dict events

1 participant