Use Qwen-Omni-Realtime through WebSocket or WebRTC to understand text, images, audio, and video and generate spoken responses for voice chat, customer service, and similar applications.
Supported regions: Singapore, China (Beijing). Each region requires its own API key.
Use Qwen3.8-Omni-Flash-Realtime for real-time audio/video conversations. It supports full-duplex interaction, accepts text, images, streaming audio, and video, and returns text and audio.
Obtain an API key and workspace ID for the selected region and workspace, and set the API key as an environment variable.
This WebSocket Manual-mode example completes one exchange using a local audio file. For continuous microphone input or browser interaction, see Realtime conversation examples.
Configure an API key and install
If you have a mono, 16 kHz, 16-bit PCM WAV file named
Run the following client after preparing the input. The example uses the Long An Ling Xin voice (
After a successful response, convert
WebSocket examples provide VAD and Manual modes; WebRTC uses VAD.
Install the other dependencies:
A call establishes a connection, configures the session, sends input, triggers a response, and receives results.
The following WebSocket and WebRTC connection examples use
Set
For media formats and multichannel input, see Input and output features; for tool configuration, see Tools and web search.
Close the connection at the end of a conversation. For WebSocket access, call
Choose audio input, images and video, multichannel audio, or voices. For Function Calling, MCP, and web search, see Tools and web search.
Audio is the recommended primary input, with optional images.
For WebSocket, append Base64-encoded audio through input_audio_buffer.append. WebRTC automatically transmits audio through the RTP track added during connection establishment, without this event. See Session configuration for formats and Realtime conversation examples for recording and sending implementations.
Images can come from local files or be captured from a live video stream. Choose the sending method for your protocol:
For Qwen3.8-Omni-Flash-Realtime,
After configuration, follow Image and video input to send frames. For video token accounting, see Billing.
The following configuration applies to WebSocket connections to Qwen3.8-Omni-Flash-Realtime.
Configure
The 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 a public HTTPS MCP Streamable HTTP service in
Web search lets the model use real-time data to answer questions about timely information such as stock prices and weather. The model automatically determines if a search is needed.
Add the following parameters to the
Receive replies through the usual text and audio events. After
Enable web search in a real-time conversation:
When web search is enabled, the
Billing is token-based, metered by modality (audio, image, text). Check the Model Studio console for pricing.
For speech output,
For model rate limits, see Rate limiting.
Keeping a connection open is not billed. If you send silent audio, whether it counts as audio input depends on the mode you use:
RPM limits the number of WebSocket connection requests per minute. Responses on an existing connection do not count toward RPM. Reconnecting counts as a new request. There is currently no separate limit on the total number of connections open at the same time.
If a WebSocket closes during setup with code
Use
Adjust
If you do not receive
If the model call fails and returns an error message, see Error codes for resolution.
For the AOQ access flow and examples, see AOQ access. For protocol selection and reference links, see the API reference.
Models and connection protocols
Use Qwen3.8-Omni-Flash-Realtime for real-time audio/video conversations. It supports full-duplex interaction, accepts text, images, streaming audio, and video, and returns text and audio.
- Tools and web search: Supports custom function calling and remote MCP tools, or web search.
- Turn detection: Supports
semantic_vad, which filters out backchannel speech and background noise to reduce false turn detection. - Multichannel audio and video aggregation: WebSocket supports 1, 2, and 4 audio channels. Video aggregation can reduce compute cost when fine-grained visual details are unnecessary. See Input and output features.
- Languages: Recognizes speech in 113 languages and dialects and generates speech in 36 languages and dialects.
- Voices and voice cloning: The default voice is
Tina. See the voice list for available voices and previews, and Voice cloning for using a custom voice.
Check the Model Studio console for model names, context, pricing, and snapshot versions. For concurrency rate limits, see Rate limiting.Qwen-Omni-Realtime models support WebSocket, WebRTC, and AOQ access. WebSocket is suitable for server-side integration and quick access. WebRTC is suitable for browser-based, low-latency voice scenarios. It transmits audio directly over UDP and includes echo cancellation and noise suppression. For client-side integration that prioritizes stable latency, interaction under poor network conditions, and noise suppression and echo cancellation for real-time full-duplex communication, consider AOQ first. For protocol comparison and selection, see the API reference. Choose an entry point for your task:
- Run a minimal audio question and answer
- Integrate microphone or browser conversations
- Verify a connection
- Add images, multichannel input, or voices
- Use tools or web search
Connection prerequisites
Obtain an API key and workspace ID for the selected region and workspace, and set the API key as an environment variable. qwen3.8-omni-flash-realtime requires the workspace-specific endpoint below.
- WebSocket
- WebRTC
- AOQ
| Parameter | Description |
|---|---|
| Endpoint | China (Beijing) region: wss://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api-ws/v1/realtimeSingapore region: wss://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/realtimeReplace {WorkspaceId} with your actual workspace ID. |
| Query parameter | Use the model query parameter to specify the model. Example: ?model=qwen3.8-omni-flash-realtime |
| Request header | Use a Bearer token for authentication: Authorization: Bearer DASHSCOPE_API_KEY
|
Quick start: minimal audio question and answer
This WebSocket Manual-mode example completes one exchange using a local audio file. For continuous microphone input or browser interaction, see Realtime conversation examples.
Configure an API key and install websocket-client. Set REALTIME_WS_URL to the full regional WebSocket endpoint in Connection prerequisites with the workspace ID replaced; the example adds the model query parameter. Set PCM_FILE to a short 16 kHz, 16-bit little-endian, mono PCM speech file without a file header.
This example uses Manual mode: wait for session configuration, send audio, commit the buffer, and request a response. Text is printed to the terminal; audio is saved to reply.pcm (24 kHz PCM, not a WAV file).
Run the following commands in a macOS or Linux terminal. Replace the WebSocket endpoint with the regional URL for your workspace, without the model query parameter. The example adds it automatically.
input.wav, use Python to extract its PCM frames. This step checks the format; it does not resample audio.
longanlingxin):
reply.pcm to a WAV file for playback with an audio player:
Realtime conversation examples
WebSocket examples provide VAD and Manual modes; WebRTC uses VAD.
- WebSocket
- WebRTC
- AOQ
- DashScope Python SDK
- DashScope Java SDK
- Native Python WebSocket
- Runtime environment
- macOS
- Debian/Ubuntu
- CentOS
- Windows
-
Interaction mode
- VAD mode (Voice Activity Detection, automatically detects the start and end of speech) The server responds after detecting the end of the user's speech.
- Manual mode (client-controlled recording) The client controls the start and end of speech. After speaking, your application must notify the server.
- VAD mode
- Manual mode
Create a Python file named vad_dash.py and copy the following code into the file:Runvad_dash.py
vad_dash.pyto start a real-time conversation through your microphone. The system detects speech and streams audio to the server.
Call flow and session management
A call establishes a connection, configures the session, sends input, triggers a response, and receives results.
Establish a connection
The following WebSocket and WebRTC connection examples use qwen3.8-omni-flash-realtime.
- WebSocket
- WebRTC
- AOQ
- Native WebSocket
- DashScope Python SDK
- DashScope Java SDK
For endpoints and authentication, see Connection prerequisites.
Configure the session
Set instructions in the session object of a session.update event to provide background and response requirements.
Use the session.update client event to configure output modalities, voice, audio format, and VAD. The following Qwen3.8-Omni-Flash-Realtime WebSocket Manual-mode configuration matches the minimal audio example. This example uses the Long An Ling Xin 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.Turn control and event sequence
- VAD mode
- Manual mode
Set
session.turn_detection.type in the session.update event to "server_vad" or "semantic_vad" to enable VAD mode. This mode is suitable for voice calls. Both WebSocket and WebRTC support VAD mode, but their audio and image transport methods and some server events differ.For customer service or business conversations with the Qwen3.8-Omni-Flash-Realtime series, set session.turn_detection.type to "semantic_vad_ec". Compared with semantic_vad, this mode detects user speech more readily to interrupt the model response, while still filtering out meaningless sounds such as background noise.WebRTC supports only VAD mode, not Manual mode. WebRTC transmits audio directly over RTP, so you do not need to sendThe interaction flow is as follows:input_audio_buffer.appendevents. Images are transmitted through video tracks, andinput_image_buffer.appendevents are not supported. Control instructions and server events are transmitted through the DataChannel. For details, see Server events.
- The client sends audio data. WebSocket sends it via input_audio_buffer.append events; WebRTC transmits it automatically via the audio track (RTP) without manually sending events.
- The server detects the start of speech and sends the input_audio_buffer.speech_started event via DataChannel (WebRTC) or WebSocket.
- The server detects the end of speech and sends the input_audio_buffer.speech_stopped event.
- The server commits the audio buffer and sends the input_audio_buffer.committed event.
- The server begins generating a response, sending conversation.item.created and other events. Audio responses are returned incrementally via the WebSocket
response.audio.deltaevent, or transmitted directly via the WebRTC audio track (RTP). - During the response, the server returns incremental text transcription via
response.audio_transcript.deltaevents, and sends theresponse.doneevent when the response is complete.
| Lifecycle | Client events | Server events |
|---|---|---|
| Session initialization | session.updateSession configuration | session.createdSession created.session.updated Session configuration updated. |
| User audio input | input_audio_buffer.appendWebSocket: Appends audio to the buffer via this event.input_image_buffer.append WebSocket: Appends an image to the buffer via this event. WebRTC: Audio is transmitted automatically via the RTP audio track, and images are transmitted via the video track. These events are not needed. | input_audio_buffer.speech_startedSpeech start detected.input_audio_buffer.speech_stopped Speech end detected.input_audio_buffer.committed Audio buffer committed. |
| Server audio output | None | response.createdResponse generation started.response.output_item.added New output item added to the response.conversation.item.created Conversation item created.response.content_part.added New content part added to the assistant message.response.audio_transcript.delta Incrementally generated transcribed text.response.audio.delta WebSocket: Incrementally generated audio from the model is returned via this event. WebRTC: Audio is transmitted directly via the RTP audio track; this event is not returned.response.audio_transcript.done Text transcription completed.response.audio.done Audio generation completed.response.content_part.done Streaming of the assistant's text or audio content is complete.response.output_item.done The assistant's entire output item has finished streaming.response.done Response completed. conversation.item.input_audio_transcription.completedUser audio input transcription completed (requires enabling input_audio_transcription in session.update). |
End a session
Close the connection at the end of a conversation. For WebSocket access, call close(). For WebRTC access, stop the media and close the PeerConnection as described in End a session and clean up resources. Leaving the same session open causes its context to continue accumulating.
When close() is called immediately after connecting, before any interaction, closing the WebSocket can take about 5–10 seconds. The server must finish audio stream handling, context caching, and inference resource initialization before responding to the close request. Run close() asynchronously to avoid blocking the main flow.
Session duration and context limits
qwen3.8-omni-flash-realtime supports up to 196608 total input tokens. Input length is calculated using the same rules as Qwen3.5-Omni-Realtime.
- If the combined token count of the conversation history and the current turn exceeds the maximum input length, the server automatically truncates the history and continues the conversation. Text and tool results also count toward the input length.
- If the current turn alone exceeds the maximum input length, the server returns an error.
- A single WebSocket session can last up to 120 minutes. The connection closes automatically at this limit.
-
The model retains conversation history up to the following turn and duration limits. When exceeded, the oldest history is discarded. Max duration is the cumulative audio or video (image frame) duration retained in context. It is not the duration of the entire session.
Video is input as extracted frames (recommended: 1 fps). Video max duration is the cumulative frame duration retained — for example, 240 s means only frames from the last 240 seconds are kept.
Model
Audio max turns
Video max turns
Audio max duration
Video max duration
qwen3.8-omni-flash-realtime
100 turns
50 turns
600 seconds
240 seconds
qwen3.5-omni-plus-realtime
100 turns
50 turns
600 seconds
240 seconds
qwen3.5-omni-flash-realtime
80 turns
50 turns
480 seconds
120 seconds
Input and output features
Choose audio input, images and video, multichannel audio, or voices. For Function Calling, MCP, and web search, see Tools and web search.
Audio input
Audio is the recommended primary input, with optional images.
For WebSocket, append Base64-encoded audio through input_audio_buffer.append. WebRTC automatically transmits audio through the RTP track added during connection establishment, without this event. See Session configuration for formats and Realtime conversation examples for recording and sending implementations.
Image and video input
Images can come from local files or be captured from a live video stream. Choose the sending method for your protocol:
- WebSocket
- WebRTC
Send Base64-encoded images to the server buffer through input_image_buffer.append. Before sending an image, send at least one
input_audio_buffer.append event.- VAD mode: The server automatically submits audio and images and triggers a response at the end of speech. Send this turn's images before
input_audio_buffer.speech_stopped. - Manual mode: After appending this turn's audio and images, send
input_audio_buffer.commit, wait forinput_audio_buffer.committed, and sendresponse.createto request a response. See the event sequence.
manual_mode.py, and uncomment its image-input and image-sending sections.For video calls, extract frames and send them through input_image_buffer.append at the recommended rate of one frame per second. For SDK code, see the Omni-Realtime sample code.Optional: video aggregation
For Qwen3.8-Omni-Flash-Realtime, session.video.input.representation_compact defaults to none. Set it to normal to aggregate video representations and reduce computation when fine visual detail is unnecessary. Configure it before the first audio segment; it cannot change after audio input starts.
The configuration below uses Manual mode, text and audio output, the Tina voice, and disabled input transcription. conversation is a connected SDK session. The SDK also sends voice and VAD settings; provide any changes together in the same call.
- Python
- Java
Use DashScope Python SDK 2.0.1 or later. In Realtime conversation examples, select “WebSocket → DashScope Python SDK → Manual mode”:
- In
manual_dash.py, set the model toqwen3.8-omni-flash-realtime. - Replace the existing
update_sessioncall with the call below (input_video_representation_compactis the video aggregation configuration). Apply it once before the first audio segment. - Because this configuration disables input transcription, omit
ctx['transcription_done'].wait(timeout=10)after commit. Keep the existing commit and response-creation calls.
Python
Multichannel audio
The following configuration applies to WebSocket connections to Qwen3.8-Omni-Flash-Realtime.
Configure session.audio.input.format before the first audio segment. It supports 1, 2, or 4 channels; multichannel input requires PCM, 16000 Hz, s16le, and interleaved samples. Use raw_mic_array for 2 channels and foa_ambix for 4. See client events for constraints and JSON fragments.
For the input token multiplier, see Billing.
Receive text and audio
The response format depends on the configured output modality.
- WebSocket
- WebRTC
- Text only Receive streaming text with the response.text.delta event, and the complete text with the response.text.done event.
-
Text and audio
- Text: Receive streaming text with the response.audio_transcript.delta event, and the complete text with the response.audio_transcript.done event.
- Audio: Receive Base64-encoded streaming audio with the response.audio.delta event. The response.audio.done event indicates that audio generation is complete.
Voices and voice cloning
The following configuration applies to Qwen3.8-Omni-Flash-Realtime.
The default voice is Tina. Use session.audio.output.voice for new integrations. If it and the compatibility field session.voice are both set, the audio output uses the voice specified by session.audio.output.voice. See Qwen3.8 voices for available voices and previews, voice cloning for custom voices, and the full voice list for other models.
Tools and web search
- Web search and tool calling are mutually exclusive.
conversation.item.create and item.type=function_call_output.
MCP
The following configuration applies to Qwen3.8-Omni-Flash-Realtime.
Configure a public HTTPS MCP Streamable HTTP service in session.tools. Update MCP configuration only when there is no active Response. Approval is required by default. Wait for discovery to complete before creating a Response that needs the tool. See the MCP interaction flow for results, rejections, failures, and continuation.
Web search
Web search lets the model use real-time data to answer questions about timely information such as stock prices and weather. The model automatically determines if a search is needed.
Qwen3.8-Omni-Flash-Realtime and the Qwen3.5-Omni-Realtime series support web search. Disabled by default; enable it with session.update.
For billing, see the agent policy in billing rules.
Enable web search
Add the following parameters to the session.update event:
enable_search: Set totrueto enable the web search feature.search_options.enable_source: Set totrueto include the sources of the search results in the response.
Replies and search execution
Receive replies through the usual text and audio events. After response.done, the examples below read count and strategy from search usage and print the search count and strategy. See Search usage for these fields.
Code example
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
When web search is enabled, the usage object in response.done includes a plugins field with search metering information:
Billing and rate limits
Billing
Billing is token-based, metered by modality (audio, image, text). Check the Model Studio console for pricing.
For speech output, qwen3.8-omni-flash-realtime bills both the audio and its corresponding text at their respective output rates. Qwen3.5-Omni-Realtime models bill only the audio; the corresponding text is not charged.
MCP tool invocations incur no additional fee; model inference remains subject to model pricing. See the MCP interaction flow for the calling procedure and limits.
In a multi-turn real-time conversation, 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. As a result, input tokens accumulate with each turn rather than being counted only for the new input in the current turn.For example, if a 10-second audio input converts to 70 tokens (Qwen3.5-Omni-Realtime), and that audio is still within the context window at turn 3, it will still be counted toward the input tokens for turn 3. The actual billed input tokens = tokens from all historical turns within the context window + tokens from the new input in the current turn.
Rules for converting audio, images, and video to tokens
Rules for converting audio, images, and video to tokens
- Audio
- Image
- Video
-
Qwen3.8-Omni-Flash-Realtime and Qwen3.5-Omni-Realtime:
- Input audio:
total tokens = Audio duration (seconds) * 7 - Output audio:
total tokens = Audio duration (seconds) * 12.5
- Input audio:
-
qwen3-omni-flash-realtime-2025-09-15:Input and output audio use the same formula:total tokens = Audio duration (seconds) * 12.5Audio durations of less than 1 second are billed as 1 second.
qwen3.8-omni-flash-realtime, spatial audio input uses twice as many input audio tokens as regular audio. The multiplier is the same for 2-channel and 4-channel input.Rate limiting
For model rate limits, see Rate limiting.
FAQ
Is there a charge while the connection is open but nobody speaks?
Keeping a connection open is not billed. If you send silent audio, whether it counts as audio input depends on the mode you use:
- Server VAD: Filtered silence does not count as audio input.
- Manual mode: Silence you explicitly commit counts as audio input.
response → usage → input_tokens_details → audio_tokens. The model is billed by input and output tokens. See Billing rules for details.
What does RPM limit? Is there a limit on the total number of simultaneous connections?
RPM limits the number of WebSocket connection requests per minute. Responses on an existing connection do not count toward RPM. Reconnecting counts as a new request. There is currently no separate limit on the total number of connections open at the same time.
If a WebSocket closes during setup with code 1007 and reason Requests rate limit exceeded, please try again later., the request rate limit was reached. Reduce the connection rate and reconnect with exponential backoff.
How do I configure hotwords or business terms?
Use session.instructions in session.update to provide business context, the correct spelling of terms, and pronunciation hints. This helps the model interpret and use proper names in context. This is prompt guidance rather than a dedicated hotword parameter; results depend on the audio and context.
For example, when asking Omni to transcribe audio directly, explain that the AI coding product Qoder is pronounced like the English word coder so the model can use the product name. The following shows only the prompt configuration. Merge it into your existing instructions, retain the other session settings, and apply it before sending audio:
How do I adjust VAD when it does not trigger a response promptly?
Adjust session.turn_detection through session.update based on the VAD mode in use:
server_vad: Lowersilence_duration_msto reduce the silence interval after the user stops speaking. If the value is too low, a brief pause within a sentence can be treated as the end of speech, triggering a response too early.semantic_vad: If a valid short answer, such as “yes” or “可以” (yes in Chinese), does not trigger a response, try switchingtypetosemantic_vad_ecwhen using the Qwen3.8-Omni-Flash-Realtime series. Compared withsemantic_vad, this mode detects user speech more readily to trigger an interruption, while still filtering out meaningless sounds such as background noise.
What if I do not receive an ASR transcript?
If you do not receive conversation.item.input_audio_transcription.completed, or its transcript is empty, check the following:
- Input transcription configuration: In the DashScope Python SDK,
update_sessiondefaultsenable_input_audio_transcriptiontoTrue. Setting it toFalsesendsinput_audio_transcription: nullin the session configuration. For direct WebSocket access or a WebRTC DataChannel that sends session configuration, checksession.update.session.input_audio_transcriptionagainst the input audio transcription configuration.enable_input_audio_transcriptionis an SDK argument, not a top-levelsession.updatefield. - Transcription failure event: Also handle
conversation.item.input_audio_transcription.failed. Itserror.code,error.message, anderror.paramfields provide the error details. - Audio submission: In VAD mode, check whether the server detected speech start and stop. In Manual mode, make sure you sent
input_audio_buffer.commit. Do not wait only for a completed transcription event if the audio has not been committed. - Connection and SDK version: Check that the connection remained active during this audio input. For WebRTC, also check the DataChannel state. If you use the DashScope Python SDK, check that its version meets this guide's minimum requirement (2.0.1).