Connect to Realtime API models and applications over the AOQ, WebRTC, and WebSocket protocols. This topic covers the connection flow, sequence diagrams, and code examples for each protocol.
Prerequisites
- Before you connect, check Supported models and applications
- Learn about Token authentication
Try the demo
Use the Android demo from Alibaba Cloud Model Studio to quickly verify AOQ connectivity. Download the APK and configure the API key and workspaceId to try selected models.
Scan the following QR code to download the demo:

AOQ connection
AOQ is deeply customized on top of the QUIC protocol. It suits native mobile apps, supports mixed audio, video, and data transmission, and has built-in weak-network resilience. The following example uses the Real-time omni (Omni) iOS demo to walk through the AOQ connection flow. For AOQ SDK API details, see AOQ client SDK.
Overall sequence diagram

Create engine and set callbacks
AoqEngineDelegate protocol to listen for callbacks such as onConnectionStatusChange, onDataMsg, and onError.
Start audio capture and playback
Get connection credentials
The business AppServer proxies the request to Model Studio. See Token authentication.
Configure codecs and establish connection
Configure the codec parameters, then call connect:
Configure AI session
After the connection succeeds, send a session.update event. For details, see Client events:
Enable media sending after receiving session.updated
The following example handles the session.updated reply from the model. For details, see Server events:
Disconnect and destroy engine
WebRTC connection
WebRTC doesn't have a dedicated SDK. On the web, connect directly with the browser's native JavaScript API. On other clients, connect through an open source WebRTC library or a third-party RTC service that supports the standard WebRTC protocol. The following example uses JavaScript on the web.
Overall flow diagram

Establish connection
Configure model parameters
Listen for messages that the model returns over the DataChannel to keep the interaction sequence correct:
Send and receive media data
The audio and video tracks added during connection setup (the RTP media channels) automatically transmit data to the server.
- Audio: transmitted directly over the audio track (RTP). No
input_audio_buffer.appendevents are needed. - Images: frames are sent over the video track (RTP).
input_image_buffer.appendevents are not supported.
WebRTC supports only server-side VAD modes (
server_vad or semantic_vad). Manual mode is not supported.Demo source code
Prerequisites
- A modern browser that supports WebRTC (such as Chrome, Edge, Firefox, or Safari).
- Microphone permission granted to the browser.
- The browser can't send the connection request directly to the server because of cross-origin security policies. Run the curl command in a terminal to establish the connection.
Run the demo
Create an HTML file named webrtc_demo.html and copy the following code into it:
webrtc_demo.html.
Open the file in a browser and follow these steps:
- Click Start session. The page automatically generates the Offer SDP and the corresponding curl command.
- Click Copy curl command and run the command in a terminal. The command returns the Answer SDP.
- Paste the Answer SDP into the Answer SDP text box on the page, then click Set Answer to establish the connection and start the voice conversation.