BetaRealtimeConnection Class
An open realtime WebSocket connection to a voice agent.
Iterate over the connection to receive strongly-typed server events, and use the sub-namespaces to send strongly-typed client events:
with client.beta.voice_agents.realtime.connect(agent_name="my-agent") as conn:
for event in conn:
if event.type == RealtimeServerEventType.RESPONSE_DONE:
break
Constructor
BetaRealtimeConnection(connection: ClientConnection)
Parameters
| Name | Description |
|---|---|
|
connection
Required
|
|
Methods
| close |
Close the connection. |
| recv |
Receive and parse the next server event. Known event types are returned as their strongly-typed
|
| send |
Send a client event over the connection. |
close
recv
Receive and parse the next server event.
Known event types are returned as their strongly-typed
VoiceAgentServerEventXxx model. Event types not (yet) represented by a
generated model are returned as a plain dict for forward compatibility.
recv(*, timeout: float | None = None) -> RealtimeServerEventError | RealtimeServerEventResponseContentPartAdded | RealtimeServerEventConversationItemAdded | RealtimeServerEventConversationItemCreated | RealtimeServerEventConversationItemDeleted | RealtimeServerEventConversationItemDone | RealtimeServerEventConversationItemInputAudioTranscriptionCompleted | RealtimeServerEventConversationItemInputAudioTranscriptionDelta | RealtimeServerEventConversationItemInputAudioTranscriptionFailed | RealtimeServerEventConversationItemInputAudioTranscriptionSegment | RealtimeServerEventConversationItemRetrieved | RealtimeServerEventConversationItemTruncated | RealtimeServerEventInputAudioBufferCleared | RealtimeServerEventInputAudioBufferCommitted | RealtimeServerEventInputAudioBufferSpeechStarted | RealtimeServerEventInputAudioBufferSpeechStopped | RealtimeServerEventInputAudioBufferTimeoutTriggered | RealtimeServerEventMCPListToolsCompleted | RealtimeServerEventMCPListToolsFailed | RealtimeServerEventMCPListToolsInProgress | RealtimeServerEventOutputAudioBufferCleared | RealtimeServerEventRateLimitsUpdated | VoiceAgentServerEventResponseAnimationBlendshapesDelta | VoiceAgentServerEventResponseAnimationBlendshapesDone | VoiceAgentServerEventResponseAnimationVisemeDelta | VoiceAgentServerEventResponseAnimationVisemeDone | RealtimeServerEventResponseAudioDelta | RealtimeServerEventResponseAudioDone | VoiceAgentServerEventResponseAudioTimestampDelta | VoiceAgentServerEventResponseAudioTimestampDone | RealtimeServerEventResponseAudioTranscriptDelta | RealtimeServerEventResponseAudioTranscriptDone | RealtimeServerEventResponseContentPartDone | RealtimeServerEventResponseCreated | RealtimeServerEventResponseDone | RealtimeServerEventResponseFunctionCallArgumentsDelta | RealtimeServerEventResponseFunctionCallArgumentsDone | RealtimeServerEventResponseMCPCallArgumentsDelta | RealtimeServerEventResponseMCPCallArgumentsDone | RealtimeServerEventResponseMCPCallCompleted | RealtimeServerEventResponseMCPCallFailed | RealtimeServerEventResponseMCPCallInProgress | RealtimeServerEventResponseOutputItemAdded | RealtimeServerEventResponseOutputItemDone | RealtimeServerEventResponseTextDelta | RealtimeServerEventResponseTextDone | VoiceAgentServerEventResponseVideoDelta | VoiceAgentServerEventRtcCallError | VoiceAgentServerEventRtcCallSdpCreated | VoiceAgentServerEventSessionAvatarConnecting | VoiceAgentServerEventSessionAvatarSwitchToIdle | VoiceAgentServerEventSessionAvatarSwitchToSpeaking | RealtimeServerEventSessionCreated | VoiceAgentServerEventSessionSubagentAborted | VoiceAgentServerEventSessionSubagentCompleted | VoiceAgentServerEventSessionSubagentStarted | RealtimeServerEventSessionUpdated | VoiceAgentServerEventWarning | Mapping[str, Any]
Keyword-Only Parameters
| Name | Description |
|---|---|
|
timeout
|
Maximum time in seconds to wait for the next event. If Default value: None
|
Returns
| Type | Description |
|---|---|
|
<xref:azure.ai.projects.ServerEvent>
|
The parsed server event. |
Exceptions
| Type | Description |
|---|---|
|
If the connection was closed by the server, gracefully or
otherwise. Iterating over the connection ( |
|
|
If |
send
Send a client event over the connection.
send(event: RealtimeClientEventConversationItemCreate | RealtimeClientEventConversationItemDelete | RealtimeClientEventConversationItemRetrieve | RealtimeClientEventConversationItemTruncate | RealtimeClientEventInputAudioBufferAppend | RealtimeClientEventInputAudioBufferClear | RealtimeClientEventInputAudioBufferCommit | RealtimeClientEventOutputAudioBufferClear | RealtimeClientEventResponseCancel | RealtimeClientEventResponseCreate | VoiceAgentClientEventRtcCallSdpCreate | VoiceAgentClientEventSessionAvatarConnect | VoiceAgentClientEventSessionUpdate | str | Mapping[str, Any]) -> None
Parameters
| Name | Description |
|---|---|
|
event
Required
|
<xref:azure.ai.projects.ClientEvent> or
str
A strongly-typed client event, a ready-made mapping, or a raw JSON string. |
Exceptions
| Type | Description |
|---|---|
|
If |