Skip to content

feat: expose configurable websocket max_size limit#3645

Open
anneheartrecord wants to merge 1 commit into
openai:mainfrom
anneheartrecord:feat/websocket-max-size
Open

feat: expose configurable websocket max_size limit#3645
anneheartrecord wants to merge 1 commit into
openai:mainfrom
anneheartrecord:feat/websocket-max-size

Conversation

@anneheartrecord

Copy link
Copy Markdown

Summary

Both websocket transports hard-coded max_size=None, which disables the websockets library's incoming message-size limit and gives applications no way to bound it without forking or monkeypatching the SDK:

  • OpenAIResponsesWebSocketOptions only exposed ping_interval / ping_timeout; _open_websocket_connection passed max_size=None.
  • TransportConfig (Realtime) only exposed ping_interval / ping_timeout / handshake_timeout; _create_websocket_connection passed max_size=None.

This adds an optional max_size: int | None to both option types and passes it through to websockets.connect when set, mirroring the existing keepalive knobs. Long-lived agent processes running behind proxies or in memory-constrained containers can now bound per-message memory, e.g.:

responses_websocket_options={"max_size": 8 * 1024 * 1024}
OpenAIRealtimeWebSocketModel(transport_config={"max_size": 8 * 1024 * 1024})

The default behavior is unchanged — when max_size is not provided the connection is still opened with no limit, so this is purely opt-in.

Test plan

  • Added test_websocket_model_passes_max_size_to_connect (Responses) and test_max_size_config_is_applied (Realtime) verifying the value reaches websockets.connect.
  • The existing test_websocket_model_open_websocket_connection_disables_message_size_limit (asserting the default stays None) still passes.
  • make lint, make format, mypy and pyright on the changed modules, and the full tests/models/test_openai_responses.py + tests/realtime/test_openai_realtime.py suites (181 passed) are green. Docs build succeeds.

Issue number

Closes #3644

Checks

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation
  • I've run make lint and make format
  • I've made sure tests pass

Both the Responses websocket transport (OpenAIResponsesWebSocketOptions)
and the Realtime websocket transport (TransportConfig) hard-coded
max_size=None, disabling the websockets library's incoming message-size
limit with no way to override it short of forking or monkeypatching.

Add an optional max_size field to both option types and pass it through
to websockets.connect when set, mirroring the existing ping_interval /
ping_timeout knobs. The default behavior is unchanged (no limit) so this
is purely opt-in for long-lived agent processes that need to bound
per-message memory usage behind proxies or in constrained containers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose configurable WebSocket message-size limits for Responses and Realtime transports

2 participants