The key interfaces and request parameters for Qwen-Omni real-time using the DashScope Python SDK.
Prerequisites
Your SDK version must be 2.0.1 or later. Before you start, see Real-time multimodal interaction flow.
Getting started
To use qwen3.8-omni-flash-realtime, set the session constructor's model parameter to this model name. The default voice is Tina. For Python SDK session configuration and video aggregation examples, see the real-time guide.
Download the sample code from GitHub. Three calling methods are available:
-
Audio conversation example: Captures real-time audio input from the microphone, enables VAD mode to automatically detect the start and end of speech, and supports voice interruption.
enable_turn_detectionparameter must be set to True.We recommend that you use headphones for audio playback to prevent echoes from triggering voice interruption.
-
Audio and video conversation example: Captures real-time audio and video input from the microphone and camera, enables VAD mode to automatically detect the start and end of speech, and supports voice interruption.
enable_turn_detectionparameter must be set to True.We recommend that you use headphones for audio playback to prevent echoes from triggering voice interruption.
-
Local call: Uses local audio and images as input and enables Manual mode, which lets you manually control the sending pace.
enable_turn_detectionparameter must be set to False.
Request parameters
The following request parameters can be set with the client.audio.realtime.connect method. Server-side events are no longer delivered via callbacks. Instead, iterate the session's events() in a receiver thread and dispatch by event["type"] (see Event iteration).
Parameter | Type | Description |
|---|---|---|
model | str | The Qwen-Omni model to use. See Model list. |
ws_url | str | The full WebSocket endpoint. If not specified, the endpoint is automatically selected based on the
Replace |
ImportantAlibaba Cloud Model Studio has released workspace-specific domains for the China (Beijing) and Singapore regions. The new dedicated domains deliver superior performance and higher stability for inference requests. We recommend migrating to the new domains:
- China (Beijing): from
wss://dashscope.aliyuncs.comtowss://{WorkspaceId}.cn-beijing.maas.aliyuncs.com - Singapore: from
wss://dashscope-intl.aliyuncs.comtowss://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com
{WorkspaceId} is your workspace ID, which can be found on the Workspace Details page in the Alibaba Cloud Model Studio console. Qwen3.8-Omni-Flash-Realtime requires the workspace-specific domains above. Earlier models can continue to use the original domains.
Configure the following request parameters with the update_session method.
Parameter | Type | Description |
|---|---|---|
output_modalities | list[str] | The model output modality. Set to ['text'] for text only, or ['text', 'audio'] for both audio and text. |
voice | str | The voice for audio output. For supported voices, see Voice list. Default voices:
|
input_audio_config | dict | Input audio format configuration. Use a dict (with Applies to |
output_audio_config | dict | Output audio format configuration. Use a dict (with Applies to |
input_audio_format | str | Legacy compatibility field. For new integrations, we recommend that you use |
output_audio_format | str | Legacy compatibility field. For new integrations, we recommend that you use |
smooth_output | bool | This parameter is supported only by
|
instructions | str | A system message that sets the model's objective or role. For example: You are an AI agent for a five-star hotel. Answer customer questions about room types, facilities, prices, and booking policies. Be accurate and friendly. Always respond with a professional and helpful attitude. Do not provide unverified information or information outside the hotel's scope of services. |
enable_input_audio_transcription | bool | Enables speech recognition for input audio. |
input_audio_transcription_model | str | Speech recognition model for input audio transcription. The value is always qwen3-asr-flash-realtime. This parameter is not configurable. |
turn_detection_type | str | The Voice Activity Detection (VAD) type. Valid values:
|
turn_detection_threshold | float | VAD detection threshold. Increase in noisy environments and decrease in quiet environments.
Default: 0.2. Valid values: [-1.0, 1.0]. |
turn_detection_silence_duration_ms | int | Silence duration that indicates end of speech. If exceeded, the model triggers a response. Default: 800. Valid values: [200, 6000]. |
turn_detection_param | dict | Additional Example: |
enable_search | bool | Applies to Qwen3.8-Omni-Flash-Realtime and Qwen3.5-Omni-Realtime models. Enables web search. Default: Tool calling (tools) and web search (enable_search) are incompatible. You cannot enable both at the same time. |
search_options | object | Web search options. Takes effect only when Currently, you can only set |
tools | list[dict] | Applies to Qwen3.8-Omni-Flash-Realtime and Qwen3.5-Omni-Realtime models. Tool definitions. When provided, the model can call external tools to respond to user questions. For Function Calling, the model does not generate audio and only returns the tool calling parameters. Qwen3.8-Omni-Flash-Realtime supports Function Calling and MCP tools in the same session. See client events for MCP configuration and MCP call limits for quotas. The following fields describe Function Calling tools. Each tool is a dictionary that contains the following fields:
|
temperature | float | Sampling temperature that controls content diversity. Higher values produce more diverse content; lower values produce more deterministic content. Valid values: [0, 2). Because both temperature and top_p control content diversity, we recommend that you set only one of them.
|
top_p | float | Probability threshold for nucleus sampling that controls content diversity. Higher values produce more diverse content; lower values produce more deterministic content. Valid values: (0, 1.0]. Because both temperature and top_p control content diversity, we recommend that you set only one of them. Default top_p values:
|
top_k | integer | Candidate set size for sampling. For example, 50 means only the 50 highest-scoring tokens form the candidate set. Larger values increase randomness; smaller values increase determinism. Set to None or a value greater than 100 to disable top_k and use only top_p. The value must be greater than or equal to 0. Default top_k values:
|
max_tokens | integer | Maximum number of tokens to return.
For Use max_tokens to limit output length for generating summaries, keywords, controlling costs, or reducing response time. |
repetition_penalty | float | Controls repetition in generated sequences. Higher values reduce repetition. 1.0 means no penalty. Default repetition_penalty values:
|
presence_penalty | float | Controls content repetition in model output. Valid values: [-2.0, 2.0]. Positive values reduce repetition; negative values increase it. Default presence_penalty values:
Scenarios: Higher values suit scenarios requiring diversity or creativity, such as creative writing or brainstorming. Lower values suit scenarios requiring consistency or technical precision, such as technical documents. |
seed | integer | Makes generation more deterministic, ensuring consistent results across runs. Passing the same seed with identical parameters produces the same result as much as possible. Valid values: 0 to 231−1. Default value: -1. |
Key interfaces
RealtimeSession (client.audio.realtime.connect)
The real-time session is created with client.audio.realtime.connect(model=...). The connection is established when the with context is entered (or when the session's connect() method is called).
Method signature | Server-side response event (delivered via | Description |
|---|---|---|
|
| Creates a connection with the server. This method is automatically called when the |
|
| Updates session configuration. For parameter details, see Request parameters. After connecting, the server returns default session configurations. Call this method immediately after connecting to update settings. When the server receives the |
| None | Appends audio data to the cloud input buffer.
|
| None | Adds image data to the cloud video buffer. Image input limits:
|
|
| Deletes the audio from the current cloud buffer. |
|
| Commits audio and video from the cloud buffer. Returns an error if the buffer is empty.
Note:
|
|
response.audio_transcript.delta
response.audio_transcript.done
| Instructs the server to create a model response. When you configure a session in "turn_detection" mode, the server automatically creates a model response. |
| None | Cancels the in-progress response. If there is no response to cancel, the server responds with an error. |
| None | Sends a For a Function Calling tool result,
For MCP approval, the same event uses |
| None | Terminates the task and closes the connection (idempotent; does not send |
| None | Gets the session_id of the current task and the response_id of the last response (session attributes; additional first-packet delay metrics such as |
Audio format and sample rate configuration
Use the input_audio_config and output_audio_config parameters of update_session (dicts with type and sample_rate keys) to set the audio format and sample rate together.
qwen3.5-omni-plus-realtime and qwen3.5-omni-flash-realtime.
# Specify the format (type) and sample rate (sample_rate) together in the dict.
session.update_session(
output_modalities=['audio', 'text'],
voice="Tina",
input_audio_config={"type": "pcm", "sample_rate": 16000},
output_audio_config={"type": "wav", "sample_rate": 24000},
)
Event iteration (events())
The server returns response events and data in the form of events. You need to iterate the session's events() in a receiver thread and dispatch by event["type"] (see Server-side events for the complete event list).
def receive_events(session):
for event in session.events():
kind = event.get('type')
if kind == 'session.created':
print('start session: {}'.format(event['session']['id']))
elif kind == 'conversation.item.input_audio_transcription.completed':
print(f"[User] {event['transcript']}")
elif kind == 'response.audio.delta':
# Audio incrementally generated by the model (Base64); decode it before playback
audio = base64.b64decode(event['delta'])
elif kind == 'response.audio_transcript.done':
print(f"[LLM] {event['transcript']}")
Method signature | Parameters | Description |
|---|---|---|
| event: Server-side event | Continuously reads and yields server-side events ( |
| None | Blocking read of a single server-side event, without automatic looping. Returns |
FAQ
Q: How do I align input audio and images?
The Qwen-Omni real-time model uses the audio stream as the input timeline. Images are inserted into the audio stream based on the time they are sent. You can add images at any point in the audio timeline.
In real-time interaction scenarios, you can enable or disable video input at any time.
Q: What is the recommended frequency for inputting images and audio?
In real-time interaction scenarios, we recommend sending images at a frame rate of 1 or 2 fps and sending audio in 100 ms packets.
Q: What are the differences between the two modes of the turn_detection switch?
When turn_detection is enabled, it supports two modes: server_vad and semantic_vad:
-
Enable "turn_detection":
- Input state: The cloud-based VAD detects the end of a sentence in the input audio and immediately triggers Qwen-Omni inference to return the reply text and speech.
- Response state: In this state, you can continue to send audio and video input without interruption while the model is responding. After the response is complete, the state returns to the input state to await the next speech input.
- Interruption: If the user starts speaking while the model is responding, an interruption is triggered. The service immediately stops the current response and switches to the input state.
-
Disable "turn_detection":
- You must manually determine the end of a round of audio and video input and trigger Qwen-Omni inference to obtain a response using commit and create_response.
- While the model is responding, you must stop sending audio and video input. You can resume input for the next round only after the model has finished responding.
- You must use the cancel_response method to interrupt the model's response.
Note that when turn_detection is enabled, you can still actively trigger a response using commit and create_response, and actively interrupt it using cancel_response.
Q: Why do I need to select another model for input_audio_transcription?
Qwen-Omni real-time is an end-to-end multimodal model. Its text output is a response to the input, not a direct transcription of the input audio. A separate ASR model is required for transcription. Currently, the model is determined by the built-in configuration and is not configurable.