RealtimeConnection Class
An open realtime WebSocket connection to a voice agent.
Iterate to receive events. Use conversation, response, and the audio
buffers to send messages and control replies:
with client.voice_agents.realtime.connect(agent_name="my-agent") as conn:
for event in conn:
if event.type == RealtimeServerEventType.RESPONSE_DONE:
break
Constructor
RealtimeConnection(connection: ClientConnection)
Parameters
| Name | Description |
|---|---|
|
connection
Required
|
|
Methods
| close |
Close the socket once. |
| recv |
Receive and parse the next server event. Known events use SDK model classes. Unknown event types are returned as dictionaries. |
| send |
Send a client event over the connection. |
close
recv
Receive and parse the next server event.
Known events use SDK model classes. Unknown event types are returned as dictionaries.
recv(*, timeout: float | None = None) -> RealtimeServerEventError | RealtimeServerEventResponseContentPartAdded | RealtimeServerEventConversationItemAdded | RealtimeServerEventConversationItemCreated | RealtimeServerEventConversationItemDeleted | RealtimeServerEventConversationItemDone | RealtimeServerEventConversationItemInputAudioTranscriptionCompleted | RealtimeServerEventConversationItemInputAudioTranscriptionDelta | RealtimeServerEventConversationItemInputAudioTranscriptionFailed | RealtimeServerEventConversationItemInputAudioTranscriptionSegment | RealtimeServerEventConversationItemRetrieved | RealtimeServerEventConversationItemTruncated | RealtimeServerEventInputAudioBufferCleared | RealtimeServerEventInputAudioBufferCommitted | RealtimeServerEventInputAudioBufferSpeechStarted | RealtimeServerEventInputAudioBufferSpeechStopped | RealtimeServerEventInputAudioBufferTimeoutTriggered | VoiceAgentServerEventInputCollectionStatus | 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 | VoiceAgentServerEventSystemToolArgumentsDelta | VoiceAgentServerEventSystemToolArgumentsDone | VoiceAgentServerEventResponseVideoDelta | VoiceAgentServerEventRtcCallError | VoiceAgentServerEventRtcCallSdpCreated | VoiceAgentServerEventSessionAvatarConnecting | VoiceAgentServerEventSessionAvatarSwitchToIdle | VoiceAgentServerEventSessionAvatarSwitchToSpeaking | RealtimeServerEventSessionCreated | VoiceAgentServerEventSessionHandoffAborted | VoiceAgentServerEventSessionHandoffCompleted | VoiceAgentServerEventSessionHandoffStarted | 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 client event model, mapping, or JSON string. |
Exceptions
| Type | Description |
|---|---|
|
If |