The Qwen-Audio Realtime API provides real-time voice conversation capabilities over the WebSocket protocol. Clients interact with the server by sending and receiving JSON events. The API supports audio input, text input, voice activity detection (VAD), and streaming audio and text output.
User guide: Realtime Audio Chat (Qwen-Audio-Realtime). For detailed descriptions of client events and server events, see Client events and Server events.
Alibaba Cloud Model Studio has released a workspace-specific domain for the China (Beijing) region. The new dedicated domain delivers superior performance and higher stability for inference requests. We recommend migrating from dashscope.aliyuncs.com to {WorkspaceId}.cn-beijing.maas.aliyuncs.com.
Replace {WorkspaceId} with your actual Workspace ID. The existing domain remains fully functional.
Service endpoint
The WebSocket URL is fixed as follows. Specify the model name using the model query parameter (replace <model_name> with the actual model name):
China (Beijing)
wss://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api-ws/v1/realtime?model=<model_name>
Replace {WorkspaceId} (including the curly braces) with your actual workspace ID.
Use the wss:// protocol. Set the Authorization in the request header. Pass the model name in the model URL query parameter.
Request headers
Include the following headers in your request:
|
Parameter |
Type |
Required |
Description |
|
Authorization |
string |
Yes |
Authentication token in the format |
|
user-agent |
string |
No |
Client identifier for server-side request tracking. |
|
X-DashScope-WorkSpace |
string |
No |
Alibaba Cloud Model Studio workspace ID. |
Authorization is verified during the WebSocket handshake. If the API key is invalid or missing, the handshake fails with an HTTP 401/403 error.
Key concepts
-
Session: A single WebSocket connection corresponds to one session, which maintains configuration and conversation context.
-
Conversation item: An individual message in a conversation, maintained in sequence.
-
Response: The output generated by a single model inference, containing one or more output items . An output item can be an assistant message or a function call.
-
Function calling: An output item the model produces when it needs the client to run a tool function. After the client runs the tool, it sends the result back in
function_call_outputand triggers the next inference withresponse.create. -
Turn detection: Controls when to trigger model inference.
Interaction modes
The Qwen-Audio Realtime API supports three interaction modes, configured through the session.update event's turn_detection.type parameter:
|
Mode |
turn_detection.type |
Description |
Use cases |
|
server_vad |
|
Server-side VAD detects speech start and end, and automatically triggers inference. |
Hands-free conversation, voice assistants |
|
smart_turn |
|
Intelligent turn detection that combines acoustic and semantic analysis to determine turn boundaries, not just voice signals. Non-semantic sounds (such as "uh" and "ah") don't trigger a turn or interrupt playback. |
Low-latency natural conversation, high-quality interruption |
|
push-to-talk |
|
The client manually submits audio and triggers inference. |
Push-to-talk, precise control |
Interaction flow
For detailed descriptions of client events and server events, see Client events and Server events.
server_vad mode
The server performs voice activity detection on incoming audio and automatically triggers inference after detecting the end of speech.
How to enable: Set session.update event's turn_detection.type to server_vad.
Complete conversation turn
The following diagram illustrates the typical interaction sequence in server_vad mode:
The interaction proceeds as follows:
-
The client establishes a WebSocket connection, and the server returns a
session.createdevent. -
The client sends
session.updateto configure session parameters, and the server returnssession.updated. -
The client continuously sends
input_audio_buffer.appendto stream audio data. -
The server detects the start of speech and returns
input_audio_buffer.speech_started. It also streams ASR transcription deltas viaconversation.item.input_audio_transcription.delta. -
The server detects the end of speech and returns
input_audio_buffer.speech_stopped,input_audio_buffer.committed, andconversation.item.created. -
The server automatically generates a response, streaming text and audio deltas (
response.audio_transcript.delta,response.audio.delta), and finally returnsresponse.done.
User barge-in
If VAD detects the user starting to speak while the model is playing back a response, the server cancels the current response (returns response.done with status cancelled), then begins a new round of voice input and response. The following diagram illustrates the user barge-in interaction sequence:
smart_turn mode
smart_turn mode detects end of speech by combining acoustic perception and semantic understanding, filtering out backchannel responses, background noise, and other non-semantic sounds. Non-semantic sounds are passed through as conversation.item.ambient_audio_transcription.delta events without triggering a conversation turn.
How to enable: Set session.update event's turn_detection.type to smart_turn.
Complete conversation turn
The following diagram illustrates the typical interaction sequence in smart_turn mode:
Key differences from server_vad mode:
-
Non-semantic sounds ("uh", "ah", etc.) don't trigger inference. Instead, they're returned through
ambient_audio_transcriptionevents. -
Previously validated speech may be revoked (
input_audio_buffer.speech_stoppedreturnsreason=turn_invalid), in which case inference isn't triggered. -
While waiting for the user's next input, the client can explicitly send
response.createto trigger inference.
User barge-in
Barge-in handling is largely the same as in server_vad mode. The following diagram illustrates the user barge-in interaction sequence:
Invalid turn
Previously validated speech may be revoked (input_audio_buffer.speech_stopped returns reason=turn_invalid), in which case inference isn't triggered. The client should continue sending audio and wait for the next valid speech. The following diagram illustrates the invalid turn interaction sequence:
Speaker enhancement configuration flow
In smart_turn mode, when voiceprint_audio_urls is included in the first session.update, the server asynchronously performs voiceprint registration (loading the target speaker's audio features) and notifies the client of the registration progress through events. A failed voiceprint registration does not block the normal conversation flow.
The voiceprint registration interaction sequence is as follows:
-
The client sends
session.updatewith voiceprint audio URLs inturn_detection.voiceprint_audio_urls. The server returnssession.created. -
The server immediately starts voiceprint registration asynchronously and pushes
voiceprint_audio_list.in_progressbefore returningsession.updated. This event carries theitem_idthat uniquely identifies the registration task. -
The server returns
session.updatedto confirm that the session configuration has taken effect. -
After registration completes, the server pushes a terminal event (the
item_idmatches the one in step 2):-
Registration succeeded:
voiceprint_audio_list.completed. -
Registration failed:
voiceprint_audio_list.failed, with areasonfield describing the failure (for example, the audio URL could not be downloaded).
-
voiceprint_audio_urls is only configurable in the first session.update event. The field is ignored in subsequent session.update calls.
push-to-talk mode
The client manually controls audio submission and inference triggering. Use this mode when you need precise control over when audio is submitted and inference begins.
How to enable: Set session.update event's turn_detection to null.
Complete conversation turn
The following diagram illustrates the typical interaction sequence in push-to-talk mode:
The interaction proceeds as follows:
-
The client continuously sends
input_audio_buffer.appendto stream audio data. -
After the user finishes speaking, the client sends
input_audio_buffer.committo commit the buffer. -
The client sends
response.createto manually trigger inference. -
The server generates a response, streaming text and audio.
User barge-in
The client sends response.cancel to cancel the current response, and the server returns response.done (with status cancelled and reason client_cancelled). The following diagram illustrates the user barge-in interaction sequence:
Mode operation constraints
|
Operation |
push-to-talk |
server_vad |
smart_turn |
|
session.update |
All parameters can be changed in IDLE state; some are restricted in non-IDLE state |
All parameters can be changed in IDLE state; some are restricted in non-IDLE state |
All parameters can be changed in IDLE state; some are restricted in non-IDLE state |
|
input_audio_buffer.append |
Allowed |
Allowed |
Allowed |
|
input_audio_buffer.commit |
Allowed |
Ignored |
Ignored |
|
input_audio_buffer.clear |
Allowed |
Ignored |
Ignored |
|
response.create |
Allowed. Audio must be committed first via |
Allowed when no response is being generated; not allowed while a response is being generated |
Allowed while waiting for the user's next input; not allowed during an active turn (from |
|
response.cancel |
Allowed (during inference) |
Allowed (during inference) |
Allowed (during inference) |
|
conversation.item.create/delete/retrieve |
Allowed |
Allowed |
Allowed |
turn_detection and input_audio_format can only be changed before the first audio is sent (IDLE state).
Error handling
|
Type |
Behavior |
Examples |
|
Client error ( |
Connection stays open; the client receives an error event |
Invalid parameters, disallowed state, duplicate item_id |
|
Server error ( |
Connection terminated |
LLM connection failure, storage failure |