Realtime Class

Connect to a voice agent through client.voice_agents.realtime.

Open a connection with connect:


   from azure.ai.projects import AIProjectClient
   from azure.identity import DefaultAzureCredential

   client = AIProjectClient(endpoint, DefaultAzureCredential())
   with client.voice_agents.realtime.connect(agent_name="my-agent") as conn:
       conn.input_audio_buffer.append(audio=chunk)
       conn.input_audio_buffer.commit()
       conn.response.create()
       for event in conn:
           if event.type == RealtimeServerEventType.RESPONSE_DONE:
               break

Constructor

Realtime(*args: Any, **kwargs: Any)

Parameters

Name Description
client
Required

The voice-agent client that supplies the project endpoint and credential.

Methods

connect

Open a realtime WebSocket connection to a voice agent.

connect

Open a realtime WebSocket connection to a voice agent.

connect(*, agent_name: str, agent_session_id: str | None = None, transport: str | VoiceAgentTransport | None = None, structured_inputs: Mapping[str, Any] | None = None, connection_url: str | None = None, api_version: str | None = None, credential_scopes: List[str] | None = None, extra_query: Mapping[str, str] | None = None, extra_headers: Mapping[str, str] | None = None, **kwargs: Any) -> RealtimeConnectionManager

Keyword-Only Parameters

Name Description
agent_name
str

The name of the voice agent to connect to.

agent_session_id
str or None

An optional identifier used to correlate the voice session. Default value is None.

Default value: None
transport

VoiceAgentTransport.WEBSOCKET (service default) or VoiceAgentTransport.WEBRTC. An explicit value overrides extra_query. WebRTC requires your app to handle the peer connection, media, and SDP exchange.

Default value: None
structured_inputs

Values for the agent's structured-input placeholders.

Default value: None
connection_url
str or None

Full wss:// URL that overrides the route computed from the client endpoint. Query parameters are still appended. Default value is None.

Default value: None
api_version
str or None

Overrides the client's API version for the handshake. Default value is None.

Default value: None
credential_scopes
list[str] or None

Overrides the client's token scopes for the handshake. Default value is None.

Default value: None
extra_query

Additional query-string parameters for the handshake.

Default value: None
extra_headers

Additional headers for the handshake. Preview voice features require allow_preview=True on the project client or an explicit {"Foundry-Features": "VoiceAgents=V1Preview"} header. GA voice sessions need no opt-in.

Default value: None

Returns

Type Description

A context manager yielding a RealtimeConnection.

Exceptions

Type Description

If transport is not a string or VoiceAgentTransport.