This article introduces the key APIs and request parameters for calling Qwen-Omni realtime models with the DashScope Java SDK.
For connection and authentication, see WebSocket access; for event fields and JSON examples, see client events and server events.
Your Java SDK version must be v2.22.15 or later. Read Realtime multimodal interaction workflow first.
When using
The following request parameters can be configured through the chained methods or setters of the
The following request parameters can be configured through the chained methods or setters of the
OmniRealtimeConversation is imported via
The server returns response events and data to the client through callbacks. You need to implement the callback methods to process the information or data returned by the server.
Import it through
Prerequisites
Your Java SDK version must be v2.22.15 or later. Read Realtime multimodal interaction workflow first.
QuickStart
When using qwen3.8-omni-flash-realtime, set the session construction parameter model to this model name; the default voice is Tina. For Java SDK session configuration and video aggregation parameter examples, see the realtime invocation guide.
Visit github to download the sample code. We provide sample code for three invocation methods:
-
Audio conversation example: captures real-time audio input from the microphone, enables VAD mode (automatically detects the start and end of speech), and supports voice interruption.
The enableTurnDetection parameter must be set to
true.We recommend using 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 (automatically detects the start and end of speech), and supports voice interruption.
The enableTurnDetection parameter must be set to
true.We recommend using headphones for audio playback to prevent echoes from triggering voice interruption.
-
Local invocation: uses local audio and images as input, and enables Manual mode (manually controls the sending pace).
The enableTurnDetection parameter must be set to
false.
Request parameters
The following request parameters can be configured through the chained methods or setters of the OmniRealtimeParam object, and then passed as a parameter to the constructor of OmniRealtimeConversation.
Parameter | Type | Description |
|---|---|---|
model | String | The name of the Qwen-Omni realtime model. See Models. |
url | String | Endpoint:
When calling, replace |
OmniRealtimeConfig object, and then passed as a parameter to the updateSession API.
| Parameter | Type | Description |
|---|---|---|
| modalities | List<OmniRealtimeModality> | Model output modality settings, which support setting [OmniRealtimeModality.TEXT] (text output only) or [OmniRealtimeModality.TEXT, OmniRealtimeModality.AUDIO] (outputs audio and text). |
| voice | String | The voice of the audio generated by the model. For supported voices, see the voice list.Default Voices:
|
| inputAudioFormat | OmniRealtimeAudioFormat | The format of the user's input audio. Currently it can only be set to PCM_16000HZ_MONO_16BIT, which indicates a PCM audio stream with a 16 kHz sampling rate. |
| outputAudioFormat | OmniRealtimeAudioFormat | The format of the model's output audio. Currently it can only be set to PCM_24000HZ_MONO_16BIT, which indicates a PCM audio stream with a 24 kHz sampling rate. Custom output sampling rates are not currently supported. |
| instructions | String | The system message, used to define the model's goals or role.For example: You are an AI customer service specialist at a five-star hotel. Please answer customers' questions about room types, facilities, pricing, and booking policies accurately and in a friendly manner. Always respond in a professional and helpful attitude, and never provide unverified information or information beyond the hotel's service scope.instructions must be set through the parameters method of an OmniRealtimeConfig instance: |
| smooth_output | Boolean | Only qwen3-omni-flash-realtime-2025-09-15 supports this setting.
|
| enableInputAudioTranscription | Boolean | Whether to enable speech recognition for input audio. |
| InputAudioTranscription | String | The speech recognition model used for input audio transcription, fixed to qwen3-asr-flash-realtime, and cannot be changed |
| enableTurnDetection | Boolean | Whether to enable voice activity detection (VAD). If disabled, the user manually submits audio to create an omni response. |
| turnDetectionType | String | The VAD type. Valid values:
|
| turnDetectionThreshold | Float | The VAD detection threshold. It is recommended to increase it in noisy environments and decrease it in quiet environments.
|
| turnDetectionSilenceDurationMs | Integer | The silence duration for detecting speech stop; once exceeded, a model response is triggered. Defaults to 800. Value range: [200, 6000]. |
| turnDetectionParam | Map | The VAD extension parameter, used to pass additional configuration items for turn_detection. Currently, idle_timeout_ms (Integer) is supported: the silence timeout period (in milliseconds). Only takes effect when using theqwen3.5-omni-plus-realtimeorqwen3.5-omni-flash-realtimemodel with the VAD type set toserver_vad. After the server finishes playing the audio and the user remains silent for longer than this duration (without speech.started being triggered), the model will proactively trigger a response turn to guide the user to continue the conversation based on the current context. Value range: [5000, 30000].Example: turnDetectionParam(Map.of("idle_timeout_ms", 5000)) |
| enable_search | Boolean | Applies to the Qwen3.8-Omni-Flash-Realtime and Qwen3.5-Omni-Realtime series models.Whether to enable the web search feature. Set to true to enable; the default is false. When enabled, the model can autonomously decide whether to search to answer the user's immediate questions.
Tool calling (tools) and web search (enable_search) are incompatible and cannot be enabled at the same time. |
| search_options | Object | Web search option configuration. Only takes effect after enable_search is enabled. Currently, enable_source (Boolean) is supported, which indicates whether to return the list of search result sources. Set to true to enable.
|
| tools | List<Map<String, Object>> | Applies to the Qwen3.8-Omni-Flash-Realtime and Qwen3.5-Omni-Realtime series models.The list of tool definitions. When enabled, the model can autonomously decide whether to call external tools to answer the user's questions. When Function Calling is hit, the model does not generate audio and only returns the tool call parameters.Qwen3.8-Omni-Flash-Realtime can be configured with both Function Calling and MCP tools in the same session. For MCP configuration fields, see Client events; for call limits, see MCP call limits. tools and enable_search cannot be enabled at the same time, and this limit also applies to MCP.The following fields describe Function Calling tools. Each tool is a Map that contains the following fields:
|
| temperature | Float | Sampling temperature, which controls the diversity of the content generated by the model.The higher the temperature, the more diverse the generated content; conversely, the more deterministic the generated content.Value range: [0, 2)Since temperature and top_p can both control the diversity of the generated content, we recommend that you set only one of them.Default value of temperature:
|
| top_p | Float | The probability threshold for nucleus sampling, which controls the diversity of the content generated by the model.The higher the top_p, the more diverse the generated content; conversely, the more deterministic the generated content.Value range: (0, 1.0]Since temperature and top_p can both control the diversity of the generated content, we recommend that you set only one of them.Default value of top_p:
|
| top_k | Integer | The size of the sampling candidate set during generation. For example, when the value is 50, only the top 50 highest-scoring tokens in a single generation run form the candidate set for random sampling. A larger value increases the randomness of generation; a smaller value increases the determinism of generation. A value of None, or a top_k greater than 100, means the top_k policy is disabled, in which case only the top_p policy takes effect.The value must be greater than or equal to 0.Default value of top_k:
|
| max_tokens | Integer | The maximum number of tokens returned by this request.The qwen3.8-omni-flash-realtime accepts values in the range [1, 65536]. For other models, the default value and maximum value are both the model's maximum output length. For the maximum output length of each model, see Models.The max_tokens parameter is useful for scenarios where you need to limit the word count (such as generating summaries or keywords), control costs, or reduce response time.
|
| repetition_penalty | Float | The degree of repetition in consecutive sequences during model generation. Increasing repetition_penalty reduces the repetitiveness of the model's output, and 1.0 means no penalty. qwen3.8-omni-flash-realtime supports the value 0; other models have no strict value range, as long as the value is greater than 0.Default value of repetition_penalty:
|
| presence_penalty | Float | Controls the repetition level of the content generated by the model.Value range: [-2.0, 2.0]. A positive value reduces repetition, while a negative value increases repetition.presence_penalty default value:
|
| seed | Integer | Setting the seed parameter makes the model generation process more deterministic, and it is typically used to make the model return consistent results on each run.If you pass the same seed value (specified by you) in each model call and keep other parameters unchanged, the model will return the same results as much as possible.Value range: 0 to 231−1, default value -1.
|
API Reference
OmniRealtimeConversation class
OmniRealtimeConversation is imported via import com.alibaba.dashscope.audio.omni.OmniRealtimeConversation;.
| Method signature | Server-side response events (delivered via callbacks) | Description |
|---|---|---|
Server-side eventsSession createdsession.updated Session configuration updated | Establishes a connection with the server. | |
session.updatedSession configuration updated | Updates the default configuration for this session interaction. For parameter configuration, see the Request parameters section.After you establish a connection, the server immediately returns the default input and output configuration for this session. If you need to update the default session configuration, we recommend that you always call this API immediately after establishing the connection.After receiving the session.update event, the server validates the parameters. If a parameter is invalid, an error is returned; otherwise, the server-side session configuration is updated. | |
| None | Appends a base64-encoded audio data fragment to the cloud-side input audio buffer. The audio buffer is temporary storage that you can write to and commit later.
| |
| None | Adds base64-encoded image data to the cloud-side video buffer. The image data can be a local image or image data captured in real time from a video stream.The following limitations currently apply to image input:
| |
input_audio_buffer.clearedClears the audio received by the server | Deletes the audio in the current cloud buffer. | |
input_audio_buffer.committedThe server has received the committed audio | Commits the audio and video previously appended to the cloud buffer via append. An error occurs if the input audio buffer is empty.
| |
Server-side eventsThe server starts generating a responseresponse.output_item.added New output content during the responseServer-side events A conversation item is createdresponse.content_part.added New output content is added to the assistant message itemresponse.audio_transcript.delta Transcription text generated incrementallyresponse.audio.delta Audio incrementally generated by the modelresponse.audio_transcript.done Text transcription completedresponse.audio.done Audio generation completedresponse.content_part.done Streaming of the text or audio content of the Assistant mesasge is completeresponse.output_item.done Streaming of the entire output item of the Assistant mesasge is completeresponse.done Response completed | Instructs the server to create a model response.When a session is configured with "turn_detection" enabled, the server automatically creates model responses. | |
| None | Cancels the in-progress response. If there is no response to cancel, the server responds with an error. | |
| None | Sends the conversation.item.create event to the server.When returning the result of a Function Calling tool, item is a JsonObject that contains the following fields:
item.type is mcp_approval_response; for the fields, see MCP approval response in client events. | |
| None | Terminates the task and closes the connection. | |
| None | Gets the session_id of the current task. | |
| None | Gets the response_id of the most recent response. |
Callback interface (OmniRealtimeCallback)
The server returns response events and data to the client through callbacks. You need to implement the callback methods to process the information or data returned by the server.
Import it through import com.alibaba.dashscope.audio.omni.OmniRealtimeCallback;.
| Method | Parameter | Return value | Description |
|---|---|---|---|
| None | None | This method is called back immediately after the connection to the server is established. | |
| message: the server response event. | None | It includes the response to the API call and the text and audio generated by the model. For more information, see Server events. | |
| code: the status code of the websocket shutdown.reason: the closing reason of the websocket shutdown. | None | This method is called back after the server has closed the connection. |