Connect to Realtime API models and applications over the AOQ, WebRTC, and WebSocket protocols. Covers the connection flow, sequence diagrams, and code examples for each protocol
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.
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.
Implement the
The business AppServer proxies the request to QwenCloud. See Token authentication.
Configure the codec parameters, then call
After the connection succeeds, send a
The following example handles the
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.
Listen for messages that the model returns over the DataChannel to keep the interaction sequence correct:
The audio and video tracks added during connection setup (the RTP media channels) automatically transmit data to the server.
Create an HTML file named
The connection method and flow vary by model. For details, see:
Prerequisites
- Before you connect, check Supported models and applications
- Learn about Token authentication
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 QwenCloud. See Token authentication.
Configure codecs and establish connection
Configure the codec parameters, then call connect:
The AOQ SDK sends media data by default after the connection is established. This example disables media sending when connecting to the model and enables it only after the session is ready.
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:
- Enable media stream sending only after you receive
session.updated. Otherwise, the server might not be ready to receive data. - The audio and video tracks added during connection setup (the AOQ media channels) automatically transmit data to the server.
- Audio: transmitted directly over the audio track. No
input_audio_buffer.appendevents are needed. - Video: frames are sent over the video track. No
input_image_buffer.appendevents are needed.
- Audio: transmitted directly over the audio track. No
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.