Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Openai Openai python Websocket Connection Options

From Leeroopedia
Revision as of 13:42, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Openai_Openai_python_Websocket_Connection_Options.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains API_Types, Python
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete tool for configuring WebSocket connection options when using the OpenAI Realtime API, provided by the openai-python SDK.

Description

WebsocketConnectionOptions is a TypedDict that exposes WebSocket connection configuration options sourced from the websockets library. It allows fine-tuning of connection parameters including extensions (negotiated WebSocket extensions), subprotocols (preferred subprotocols), compression (permessage-deflate control), max_size (incoming message size limit), max_queue (receive buffer high-water mark), and write_limit (write buffer high-water mark). These options are passed through to the underlying websockets.asyncio.client.connect call.

Usage

Import this type when you need to customize the WebSocket connection parameters for the OpenAI Realtime API, particularly for performance tuning, protocol negotiation, or disabling compression.

Code Reference

Source Location

Signature

class WebsocketConnectionOptions(TypedDict, total=False):
    """Websocket connection options copied from websockets."""

    extensions: Sequence[ClientExtensionFactory] | None
    subprotocols: Sequence[Subprotocol] | None
    compression: str | None
    max_size: int | None
    max_queue: int | None | tuple[int | None, int | None]
    write_limit: int | tuple[int, int | None]

Import

from openai.types import WebsocketConnectionOptions

I/O Contract

Fields

Name Type Required Description
extensions Sequence[ClientExtensionFactory] or None No List of supported extensions, in order of negotiation and execution.
subprotocols Sequence[Subprotocol] or None No List of supported subprotocols, in order of decreasing preference.
compression str or None No Compression setting. Set to None to disable permessage-deflate (enabled by default).
max_size int or None No Maximum size of incoming messages in bytes. None disables the limit.
max_queue int or None or tuple[int or None, int or None] No High-water mark of the buffer where frames are received. Defaults to 16 frames.
write_limit int or tuple[int, int or None] No High-water mark of write buffer in bytes. Defaults to 32 KiB.

Usage Examples

from openai.types import WebsocketConnectionOptions

ws_options: WebsocketConnectionOptions = {
    "compression": None,       # Disable compression
    "max_size": 10 * 1024 * 1024,  # 10 MB max message size
    "max_queue": 32,           # 32 frames buffer
}

# Pass to Realtime API connection
# client.beta.realtime.connect(model="gpt-4o-realtime", **ws_options)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment