Use Qwen-Omni-Realtime over WebSocket and WebRTC to understand text, images, audio, and video, and generate voice replies. It is suitable for scenarios such as voice chat and intelligent customer service.
Supported regions: Singapore and Beijing. You must use the API Key of the corresponding region.
For real-time audio and video conversations, use Qwen3.8-Omni-Flash-Realtime first. The model supports full-duplex audio and video interaction, accepts text, image, streaming audio, and video input, and returns text and audio.
Obtain the API Key and workspace ID for the selected region and workspace, and configure the API Key in environment variables.
This example uses WebSocket and Manual mode to complete one Q&A round from a local audio file. If you need continuous recording or browser interaction, see Real-time conversation examples.
First, configure the API Key and install
If you already have an
Once the input is ready, run the following client. The example uses the "Longanlingxin" voice (
After successfully receiving the reply, wrap
The WebSocket examples provide two modes: VAD and Manual; WebRTC uses VAD.
After the installation is complete, install the dependencies with pip:
A single call completes connection establishment, session configuration, input, response triggering, and result retrieval in sequence.
The following WebSocket and WebRTC connection examples use
In the
For media formats and multi-channel configuration, see Input and output capabilities. For tool configuration, see Tool calling and web search.
After each session ends, you should disconnect. For WebSocket access, you can call
The total input token limit for
Choose audio input, images and video, multichannel audio, or voice based on your task. Tool calling describes Function Calling, MCP, and web search configuration.
Audio is the recommended primary input method and can be combined with images as needed.
With WebSocket, append Base64-encoded audio via input_audio_buffer.append; with WebRTC, audio is transmitted automatically through the audio track (RTP) added when establishing the connection, so this event is not needed. For audio formats, see Session configuration; for recording and sending implementation, see Real-time conversation examples.
Images can come from local files or be captured in real time from a video stream. Choose the sending method based on your protocol:
For Qwen3.8-Omni-Flash-Realtime,
After configuration, send frames following the steps in Image and video input. For video token metering, see Billing rules.
The following configuration applies to WebSocket access for Qwen3.8-Omni-Flash-Realtime.
Set
The model's response format depends on the configured output modality.
The following configuration applies to Qwen3.8-Omni-Flash-Realtime.
The default voice is
The following configuration applies to Qwen3.8-Omni-Flash-Realtime.
Configure public HTTPS MCP Streamable HTTP services in
The web search feature enables the model to respond based on real-time retrieved data, making it suitable for scenarios that require up-to-date information, such as stock prices and weather forecasts. The model can autonomously decide whether to search in order to answer the user's time-sensitive questions.
Add the following parameters to the
Responses are still received via text and audio events. The example below reads
The following example shows how to enable web search in a real-time conversation.
After web search is enabled, a new
Qwen-Omni-Realtime models are billed based on the token counts of different modalities (audio and image). For billing details, see the Bailian console.
When generating speech output, the audio and corresponding text of
For model rate limit rules, see Rate limits.
Maintaining a connection itself is not billed. Whether uploaded silence counts toward audio input usage depends on the mode used:
RPM limits the number of WebSocket connection requests per minute. Multiple rounds of responses within the same connection are not counted repeatedly; reconnections count as new requests. Currently, there is no separate limit on the total number of simultaneously maintained connections.
When establishing a connection, if the WebSocket closes with
You can provide business background, the exact spelling, and the pronunciation of terms via the
You can adjust via the
A: If you do not receive the
If a model call fails and returns an error message, see Error codes for troubleshooting.
For the process and examples of connecting via AOQ, see AOQ access. For protocol selection and reference entry points, see API reference.
Models and access methods
For real-time audio and video conversations, use Qwen3.8-Omni-Flash-Realtime first. The model supports full-duplex audio and video interaction, accepts text, image, streaming audio, and video input, and returns text and audio.
- Tool calling and web search: Supports custom Function Calling and remote MCP tools, or you can enable web search.
- Voice turn detection: Supports
semantic_vad, which filters out meaningless sounds such as backchannel acknowledgments and background noise, reducing false triggers of voice turns. - Multi-channel audio and video aggregation: WebSocket access supports 1, 2, and 4-channel audio; video aggregation reduces compute overhead when fine-grained visual information is not needed. For more information, see Input and output capabilities.
- Languages: Supports speech recognition in 113 languages and dialects and speech generation in 36 languages and dialects.
- Voices and Voice Cloning: The default voice is
Tina; for available voices and samples, see the voice list. For how to use custom voices, see Voice Cloning.
For model names, context, pricing, snapshot versions, and other information, see the Model Studio console. For concurrency rate limit conditions, see Rate limits.Qwen-Omni-Realtime models can be accessed through three protocols: WebSocket, WebRTC, and AOQ. WebSocket is suitable for server-side integration and quick access; WebRTC is suitable for browser-based, low-latency voice scenarios, where audio is transmitted directly over UDP with built-in echo cancellation and noise reduction. If you are integrating on the client side and value stable latency, interaction capability under weak networks, and real-time full-duplex noise reduction and echo cancellation, consider AOQ first. For protocol comparison and selection, see the API reference. Select an entry point based on your current task:
- Complete an audio Q&A session first
- Connect a microphone or use a browser for real-time conversation
- Verify the connection only
- Add image, multi-channel, or voice features
- Integrate tools or web search
Preparation
Obtain the API Key and workspace ID for the selected region and workspace, and configure the API Key in environment variables. qwen3.8-omni-flash-realtime must use the workspace-bound endpoint below.
- WebSocket
- WebRTC
- AOQ
| Configuration item | Description |
|---|---|
| Endpoint | Singapore region: wss://WorkspaceId.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/realtimeWhen making a call, replace WorkspaceId in the address with the actual workspace ID. |
| Query parameter | The query parameter is model, which must be set to the name of the model to access. Example: ?model=qwen3.8-omni-flash-realtime |
| Request header | Use Bearer Token authentication: Authorization: Bearer DASHSCOPE_API_KEYDASHSCOPE_API_KEY is the API Key you applied for on Model Studio. |
QuickStart: minimal audio Q&A
This example uses WebSocket and Manual mode to complete one Q&A round from a local audio file. If you need continuous recording or browser interaction, see Real-time conversation examples.
First, configure the API Key and install websocket-client. In the Python example below, select a region (cn-beijing or ap-southeast-1) and fill in the Workspace ID for the corresponding endpoint. Set PCM_FILE to the path of a short 16 kHz, 16-bit little-endian, mono, headerless PCM speech file.
The example uses Manual mode: wait for the session configuration to take effect, send the audio, commit the buffer, and then request a reply. Text is printed to the terminal, and audio is written to reply.pcm (24 kHz PCM, not a WAV file).
Run the following commands in a macOS or Linux terminal.
input.wav encoded as mono, 16 kHz, 16-bit PCM, you can use Python to extract the PCM audio. This step checks the format and does not resample.
longanlingxin):
reply.pcm into a WAV file, then play it with an audio player:
Real-time conversation examples
The WebSocket examples provide two modes: VAD and Manual; WebRTC uses VAD.
- WebSocket
- WebRTC
- AOQ
- DashScope Python SDK
- DashScope Java SDK
- Native Python WebSocket
- Prepare the runtime environment
- macOS
- Debian/Ubuntu
- CentOS
- Windows
-
Select the interaction mode
- VAD mode (Voice Activity Detection, automatically detects speech start and end) The server automatically determines when the user starts and stops speaking and responds accordingly.
- Manual mode (manually control speech start and end) The client controls the speech start and end. After the user finishes speaking, the client must proactively send a message to the server.
- VAD mode
- Manual mode
Create a new Python file named vad_dash.py, and copy the following code into the file:Runvad_dash.py
vad_dash.pyto have a real-time conversation with the Qwen-Omni-Realtime model through your microphone. The system detects where your audio starts and automatically sends it to the server, so you do not need to send it manually.
Invocation process and session management
A single call completes connection establishment, session configuration, input, response triggering, and result retrieval in sequence.
Establish a connection
The following WebSocket and WebRTC connection examples use qwen3.8-omni-flash-realtime.
- WebSocket
- WebRTC
- AOQ
- Native WebSocket connection
- DashScope Python SDK
- DashScope Java SDK
For the API endpoint and authentication, see Prerequisites.
Configure the session
In the session object of session.update, use instructions to set the business context and response requirements.
Use the client event session.update to configure output modality, voice, audio format, and VAD. The following is a WebSocket Manual mode configuration for Qwen3.8-Omni-Flash-Realtime, consistent with the minimal audio Q&A example. This example uses the "Longanlingxin" voice (longanlingxin):
Qwen3.5-Omni-Realtime configuration example
Qwen3.5-Omni-Realtime configuration example
The following example uses Qwen3.5-Omni-Realtime, the Ethan voice, and
semantic_vad mode.The audio formats and sampling rate options listed in this section apply to theqwen3.5-omni-plus-realtimeandqwen3.5-omni-flash-realtimemodels. The legacy compatibility fieldsinput_audio_format/output_audio_formatremain valid, but we recommend usingaudio.input.format/audio.output.format.
Turn control and event timing
- VAD mode
- Manual mode
Set the
session.turn_detection.type field of the session.update event to "server_vad" or "semantic_vad" to enable VAD mode. This is suitable for voice call scenarios. Both WebSocket and WebRTC support VAD mode; however, audio and images are transmitted differently, and some server events differ.When using Qwen3.8-Omni-Flash-Realtime series models for customer service or business conversations, you can set session.turn_detection.type to "semantic_vad_ec". Compared with semantic_vad, this mode makes it easier to detect user speech and interrupt model responses, while still filtering out meaningless sounds such as background noise.WebRTC supports only VAD mode, not Manual mode. WebRTC audio is transmitted directly via RTP, so there is no need to send theThe interaction flow is as follows:input_audio_buffer.appendevent; images are transmitted over the video track, and theinput_image_buffer.appendevent is not supported. Control commands and server events are transmitted over the DataChannel. For specific events, see Server events.
- The client sends audio data. WebSocket sends it via the input_audio_buffer.append event; WebRTC transmits it automatically over the audio track (RTP), with no manual event required.
- The server detects that speech has started and sends the input_audio_buffer.speech_started event via DataChannel (WebRTC) or WebSocket.
- The server detects that speech has ended and sends the input_audio_buffer.speech_stopped event.
- The server automatically commits the audio buffer and sends the input_audio_buffer.committed event.
- The server starts generating the response, sending events such as response.created and conversation.item.created. The model's audio response is returned incrementally via the
response.audio.deltaevent over WebSocket, or transmitted directly over the WebRTC audio track (RTP). - During the response, the server incrementally returns the text transcript via
response.audio_transcript.deltaevents, and finally sends theresponse.doneevent to signal that the response is complete.
| Lifecycle | Client events | Server events |
|---|---|---|
| Session initialization | session.updateSession configuration | session.createdSession createdsession.updated Session configuration updated |
| User audio input | input_audio_buffer.appendWebSocket: Use this event to append audio to the bufferinput_image_buffer.append WebSocket: Adds images to the buffer via this event WebRTC: Audio is automatically transmitted via the RTP audio track and images via the video track, so the above events are not required. | input_audio_buffer.speech_startedSpeech start detectedinput_audio_buffer.speech_stopped Speech end detectedinput_audio_buffer.committed The server has received the committed audio |
| Server audio output | None | response.createdThe server starts generating a responseresponse.output_item.added New output content during the responseconversation.item.created Conversation item createdresponse.content_part.added New output content is added to the assistant messageresponse.audio_transcript.delta Incrementally generated transcription textresponse.audio.delta WebSocket: Audio incrementally generated by the model is returned via this event. WebRTC: Audio is transmitted directly via the RTP audio track, and this event is not returned.response.audio_transcript.done Text transcription completedresponse.audio.done Audio generation completedresponse.content_part.done Streaming output of the text or audio content of the Assistant message is completedresponse.output_item.done Streaming of the entire output item of the Assistant message is completedresponse.done Response completed conversation.item.input_audio_transcription.deltaStreaming transcription of the text of user speech input (requires enabling input_audio_transcription in session.update) conversation.item.input_audio_transcription.completedTranscription of the text of user speech input completed (requires enabling input_audio_transcription in session.update) |
End the session
After each session ends, you should disconnect. For WebSocket access, you can call close() to close the connection; for WebRTC access, you need to stop the media and close the PeerConnection. For detailed steps, see Ending the session and cleaning up resources. Keeping the same session open causes the context to keep accumulating.
When calling close() to close a WebSocket connection, if the connection is closed right after it is established (with no session interaction), closing takes about 5-10 seconds. This is normal. The server must finish processing the audio stream, caching the context, and initializing inference resources before it can respond to the close request. We recommend executing close() asynchronously to avoid blocking the main flow.
Session duration and context limits
The total input token limit for qwen3.8-omni-flash-realtime is 196608, and the input length calculation rules are the same as those for Qwen3.5-Omni-Realtime.
- When the total number of tokens of the conversation history plus the current turn of input exceeds the maximum input length, the server automatically truncates the conversation history and continues the conversation. Text and tool call results also count toward the input length.
- If the current turn of input itself exceeds the maximum input length, the server returns an error.
- A single session can last up to 120 minutes; once this limit is reached, the service proactively closes the connection.
-
The model maintains the conversation history context. When the number of conversation turns or the cumulative duration exceeds the limits below, earlier history is automatically discarded. Maximum duration refers to the upper limit on the cumulative duration of audio or video (image frames) that can be retained in the model context. This duration is not the total duration of the session.
Because video is input by frame extraction (1 frame per second recommended), the maximum video duration is the cumulative duration of image frames the model can retain. For example, 240 seconds means the model retains at most the frames received within the most recent 240 seconds; beyond that, earlier frames are discarded.
Model
Maximum audio turns
Maximum video turns
Maximum audio duration
Maximum video duration
qwen3.8-omni-flash-realtime
100 turns
50 turns
600 s
240 s
qwen3.5-omni-plus-realtime
100 turns
50 turns
600 s
240 s
qwen3.5-omni-flash-realtime
80 turns
50 turns
480 s
120 s
Input and output capabilities
Choose audio input, images and video, multichannel audio, or voice based on your task. Tool calling describes Function Calling, MCP, and web search configuration.
Audio input
Audio is the recommended primary input method and can be combined with images as needed.
With WebSocket, append Base64-encoded audio via input_audio_buffer.append; with WebRTC, audio is transmitted automatically through the audio track (RTP) added when establishing the connection, so this event is not needed. For audio formats, see Session configuration; for recording and sending implementation, see Real-time conversation examples.
Image and video input
Images can come from local files or be captured in real time from a video stream. Choose the sending method based on your protocol:
- WebSocket
- WebRTC
Send Base64-encoded images to the server-side buffer via input_image_buffer.append. Before sending an image, send
input_audio_buffer.append at least once.- VAD mode: The server automatically commits the audio and images and triggers a response when it detects the end of speech. Images for the current turn should be sent before
input_audio_buffer.speech_stopped. - Manual mode: After appending the audio and images for the current turn, send
input_audio_buffer.commit. After receivinginput_audio_buffer.committed, sendresponse.createto request a response. See Event sequence.
manual_mode.py, and uncomment the two sections of code for image input and sending.In video call scenarios, you can extract frames from the video. We recommend sending images at a rate of 1 frame per second via input_image_buffer.append. For DashScope SDK code, see Omni-Realtime sample code.Optional: Video aggregation
For Qwen3.8-Omni-Flash-Realtime, session.video.input.representation_compact defaults to none; setting it to normal aggregates video representations to reduce computational overhead, suitable for scenarios that do not rely on fine-grained visual information. It must be configured before the first audio segment and cannot be changed after input starts.
The following configuration uses Manual mode, text and audio output, the Tina voice, and disables input transcription. conversation is the connected SDK session. The SDK sends the voice, VAD, and other configurations at the same time; if you need to adjust them, set them in full in the same call.
- Python
- Java
Use DashScope Python SDK 2.0.1 or later, and select "WebSocket → DashScope Python SDK → Manual mode" in Real-time conversation examples:
- In
manual_dash.py, set the model toqwen3.8-omni-flash-realtime. - Replace the original
update_sessioncall with the call below (input_video_representation_compactis the video aggregation configuration), calling it once before the first audio segment. - Because this example disables input transcription, skip
ctx['transcription_done'].wait(timeout=10)after the commit, and continue with the existing commit and response initiation flow.
Python
Multichannel audio
The following configuration applies to WebSocket access for Qwen3.8-Omni-Flash-Realtime.
Set session.audio.input.format before the first audio segment. 1, 2, and 4 channels are supported; multichannel must be PCM, 16000 Hz, s16le, interleaved. Use raw_mic_array for 2 channels and foa_ambix for 4 channels. For field constraints and JSON snippets, see Client events.
For the input token multiplier, see Billing rules.
Receiving text and audio
The model's response format depends on the configured output modality.
- WebSocket
- WebRTC
- Text output only Receive streaming text via the response.text.delta event, and get the complete text via the response.text.done event.
-
Text and audio output
- Text: Receive streaming text via the response.audio_transcript.delta event, and get the complete text via the response.audio_transcript.done event.
- Audio: Get Base64-encoded streaming output audio data via the response.audio.delta event. The response.audio.done event indicates that audio data generation is complete.
Voices and voice cloning
The following configuration applies to Qwen3.8-Omni-Flash-Realtime.
The default voice is Tina. New integrations use session.audio.output.voice; if both it and the legacy field session.voice are set, the output audio uses the voice specified by session.audio.output.voice. For available voices and demos, see Qwen3.8 voices. For custom voices, see Voice Cloning. For other models, see the complete voice list.
Tool calling and web search
- Web search and tool calling are mutually exclusive and cannot be enabled at the same time.
conversation.item.create, with item.type set to function_call_output.
MCP
The following configuration applies to Qwen3.8-Omni-Flash-Realtime.
Configure public HTTPS MCP Streamable HTTP services in session.tools; update the MCP configuration only when there is no active Response. Approval is required by default. Confirm that tool discovery is complete before initiating a Response that requires the tool. For execution results, rejection and failure handling, and follow-up steps, see MCP interaction process.
Web search
The web search feature enables the model to respond based on real-time retrieved data, making it suitable for scenarios that require up-to-date information, such as stock prices and weather forecasts. The model can autonomously decide whether to search in order to answer the user's time-sensitive questions.
The Qwen3.8-Omni-Flash-Realtime and Qwen3.5-Omni-Realtime series models support web search, which is disabled by default and must be enabled via the session.update event.
For billing, see the agent policy in Billing details.
How to enable
Add the following parameters to the session.update event:
enable_search: set totrueto enable web search.search_options.enable_source: set totrueto return the list of search result sources.
Responses and search execution
Responses are still received via text and audio events. The example below reads count and strategy from the search usage after receiving response.done, and prints the search count and strategy; for usage fields, see Search usage.
Sample code
The following example shows how to enable web search in a real-time conversation.
- DashScope Python SDK
- DashScope Java SDK
- WebSocket(Python)
Pass the
enable_search and search_options parameters in the update_session call:Search usage
After web search is enabled, a new plugins field is added to usage in the response.done event to record search usage information:
Billing and rate limits
Billing rules
Qwen-Omni-Realtime models are billed based on the token counts of different modalities (audio and image). For billing details, see the Bailian console.
When generating speech output, the audio and corresponding text of qwen3.8-omni-flash-realtime are billed separately at the audio output and text output unit prices; the Qwen3.5-Omni-Realtime series is billed only for audio, and the corresponding text is not billed.
MCP tool calls incur no additional charge; model inference is still billed at the model price. For the MCP invocation process and usage limits, see MCP interaction process.
In multi-turn real-time conversations, each time the model generates a response, it processes all historical conversation content within the context window (including audio, images, and text from previous turns) together with the new input of the current turn as input tokens. Therefore, input tokens accumulate turn by turn as the number of conversation turns increases, rather than only counting the new input of the current turn.For example, suppose a 10-second audio input is converted into 70 tokens (Qwen3.5-Omni-Realtime series models). In the 3rd turn of the conversation, if that audio is still within the context window, it is still counted as part of the input tokens for the 3rd turn. The actual billed input token count = token count of all historical turns' content within the context window + token count of the new input in the current turn.
Rules for converting audio, images, and video into token counts
Rules for converting audio, images, and video into token counts
- Audio
- Image
- Video
-
Qwen3.8-Omni-Flash-Realtime and Qwen3.5-Omni-Realtime series models:
- Input audio calculation formula:
Total token count = Audio duration (in seconds) * 7 - Output audio calculation formula:
Total Tokens count = Audio duration (in seconds) * 12.5
- Input audio calculation formula:
-
qwen3-omni-flash-realtime-2025-09-15: The calculation formula for both input and output audio is
Total token count = Audio duration (in seconds) * 12.5If the audio duration is less than 1 second, it is counted as 1 second.
qwen3.8-omni-flash-realtime enables spatial audio input, the audio input Token count is 2 times that of regular audio, and the multiplier is the same for 2-channel and 4-channel audio.Rate limits
For model rate limit rules, see Rate limits.
FAQ
Will I be billed if I stay connected but don't speak?
Maintaining a connection itself is not billed. Whether uploaded silence counts toward audio input usage depends on the mode used:
- Server-side VAD: Silence filtered out by the server does not count toward audio input usage.
- Manual mode: Silence manually committed by the client counts toward audio input usage.
response → usage → input_tokens_details → audio_tokens. The model is billed by input and output Tokens. For detailed rules, see Billing rules.
What does RPM limit? Does it limit the total number of simultaneously maintained connections?
RPM limits the number of WebSocket connection requests per minute. Multiple rounds of responses within the same connection are not counted repeatedly; reconnections count as new requests. Currently, there is no separate limit on the total number of simultaneously maintained connections.
When establishing a connection, if the WebSocket closes with 1007 and the reason is Requests rate limit exceeded, please try again later., it indicates that the request rate limit has been triggered. Reduce the connection frequency and use exponential backoff for reconnection.
How do I configure hotwords or business terms?
You can provide business background, the exact spelling, and the pronunciation of terms via the session.instructions of session.update to help the model understand and use proper nouns in context. This is prompt-based guidance, not a standalone hotword parameter, and its effectiveness depends on the audio and context.
For example, when having Omni directly convert audio to text, you can state in the prompt that the AI coding product Qoder is homophonous with the English word coder to guide the model to use the product name. The following shows only the prompt configuration; merge the content into your existing instructions, keep the other session configurations, and complete the setup before sending audio:
VAD does not trigger responses in time. How do I adjust it?
You can adjust via the session.turn_detection of session.update based on the VAD mode currently in use:
server_vad: Lowersilence_duration_msappropriately to shorten the silence wait time after the user stops speaking. Setting it too low may cause brief pauses mid-sentence to be detected as the end of speech and trigger responses prematurely.semantic_vad: If valid short responses such as "OK" or "yes" fail to trigger a response, when using Qwen3.8-Omni-Flash-Realtime series models, try switchingtypetosemantic_vad_ec. Compared withsemantic_vad, this mode makes it easier to detect user speech and trigger interruptions, while retaining the ability to filter out meaningless sounds such as background noise.
What if I don't receive the ASR transcription text (transcript)?
A: If you do not receive the conversation.item.input_audio_transcription.completed event, or the transcript in the event is empty, check the following in order:
- Input transcription configuration. The
enable_input_audio_transcriptionparameter of the DashScope Python SDK'supdate_sessiondefaults toTrue; when set toFalse, the SDK setsinput_audio_transcriptionin the session tonull. When using WebSocket directly, or sending session configuration via a WebRTC DataChannel, check thesession.update.session.input_audio_transcriptionyou send against Input audio transcription configuration.enable_input_audio_transcriptionis an SDK parameter, not a top-level field ofsession.update. - Transcription failure event. Also listen for
conversation.item.input_audio_transcription.failed. On failure, check the error information in the event'serror.code,error.message, anderror.param. - Whether the audio has been committed. In VAD mode, check whether the server detected the start and end of speech; in Manual mode, confirm that
input_audio_buffer.commithas been sent. If the current round of audio has not been committed, do not just wait for the transcription completion event. - Connection and SDK version. Confirm that the connection was not interrupted during the current round of audio input; for WebRTC access, also check the DataChannel status. When using the DashScope Python SDK, verify that the version meets the minimum requirement of this document (2.0.1).