Complete workflow for connecting to a model via AOQ, WebRTC, or WebSocket
Describes how to connect to Realtime API models or applications via AOQ, WebRTC, and WebSocket, including connection flows, sequence diagrams, and code samples for each protocol.
AOQ is deeply customized on the QUIC protocol, optimized for native mobile apps. It supports mixed audio/video/data transport with exceptional poor-network resilience. The following example uses an iOS demo.
Implement the
Have your AppServer proxy the request to QwenCloud. See the Token authentication section.
Set codec parameters and call
Example of sending
Example of handling the
WebRTC does not provide an SDK. On the web, connect using JavaScript. On other platforms, use an open-source library or a third-party RTC provider that supports the standard WebRTC protocol. The following example uses JavaScript on the web.
Listen for DataChannel messages from the model to ensure correct interaction ordering:
The audio and video tracks added during connection (RTP media channels) automatically deliver data to the server.
Create an HTML file named
You can connect via the DashScope SDK or the model API. For details, see:
AOQ connection
AOQ is deeply customized on the QUIC protocol, optimized for native mobile apps. It supports mixed audio/video/data transport with exceptional poor-network resilience. The following example uses an iOS demo.
Overall sequence diagram

Create engine and set callbacks
AoqEngineDelegate protocol to listen for callbacks including onConnectionStatusChange, onDataMsg, and onError.
Start audio capture and playback
Get connection credentials
Have your AppServer proxy the request to QwenCloud. See the Token authentication section.
Configure codecs and establish connection
Set codec parameters and call connect:
The AOQ SDK starts sending media data by default after connecting. This example demonstrates how to disable media sending when connecting to a model.
Configure AI session
Example of sending session.update after a successful connection. For details, see Model client events reference:
Enable media sending after receiving session.updated
Example of handling the session.updated event from the model. For details, see Model server events reference:
- Start sending media streams only after receiving
session.updated. The AI may not be ready to receive data before this event. - The audio and video tracks added during connection (AOQ media channels) automatically deliver data to the server.
- Audio: transmitted directly through the audio track -- no need to send
input_audio_buffer.appendevents. - Video: frames are sent through the video track -- no need to send
input_image_buffer.appendevents.
- Audio: transmitted directly through the audio track -- no need to send
Disconnect and destroy engine
WebRTC connection
WebRTC does not provide an SDK. On the web, connect using JavaScript. On other platforms, use an open-source library or a third-party RTC provider that supports the standard WebRTC protocol. The following example uses JavaScript on the web.
Overall flow diagram

Establish connection
Configure model parameters
Listen for DataChannel messages from the model to ensure correct interaction ordering:
Send and receive media data
The audio and video tracks added during connection (RTP media channels) automatically deliver data to the server.
- Audio: transmitted directly through the audio track (RTP) -- no need to send
input_audio_buffer.appendevents. - Image: frames are sent through the video track (RTP). The
input_image_buffer.appendevent is not supported.
WebRTC supports only server-side VAD mode (
server_vad or semantic_vad). Manual mode is not supported.Demo source code
Prerequisites
- Use a modern browser that supports WebRTC (Chrome, Edge, Firefox, Safari, and so on).
- The browser must have microphone permission.
- Browsers cannot directly send connection requests to the server due to cross-origin security restrictions. Use a terminal to run the curl command to establish the connection.
Run the demo
Create an HTML file named webrtc_demo.html and paste the following code into it:
webrtc_demo.html.
Open the file in a browser and follow these steps:
- Click Start session. The page generates an Offer SDP and the corresponding curl command.
- Click Copy curl command and run it in a terminal. The output is the Answer SDP.
- Paste the Answer SDP into the Answer SDP text box on the page and click Set Answer to establish the connection and start the voice conversation.