BetaLiveConnection Class

Send and receive events on a GPT Live connection.

Service errors arrive as error events. Use the context manager to close the connection. Send session.close to end the session; Live has no response.cancel command.

Constructor

BetaLiveConnection(connection: ClientConnection)

Parameters

Name Description
connection
Required

Methods

close

Close the socket once.

recv

Receive an SDK event model, or a dictionary for an unknown event type.

send

Send an SDK event model, mapping, or JSON string.

close

Close the socket once.

close(*, code: int = 1000, reason: str = '') -> None

Keyword-Only Parameters

Name Description
code
int

WebSocket close code.

Default value: 1000
reason
str

WebSocket close reason.

recv

Receive an SDK event model, or a dictionary for an unknown event type.

recv(*, timeout: float | None = None) -> LiveServerEvent | Mapping[str, Any]

Keyword-Only Parameters

Name Description
timeout
float or None

Maximum receive wait in seconds; None waits indefinitely.

Default value: None

Returns

Type Description

The server event.

Exceptions

Type Description

On graceful or abnormal socket closure.

When the receive deadline expires.

send

Send an SDK event model, mapping, or JSON string.

send(event: LiveClientEvent | str | Mapping[str, Any]) -> None

Parameters

Name Description
event
Required
<xref:azure.ai.projects.operations.LiveClientEvent>

The client event.

Exceptions

Type Description

If the supplied JSON string is invalid.

Attributes

closed

Whether the underlying WebSocket connection has been closed.

Returns

Type Description