Skip to main content

Qwen-Omni-Realtime Java SDK

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.

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:
  1. 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.
  2. 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.
  3. 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:

  • Singapore region: wss://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/realtime

  • Beijing region: wss://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api-ws/v1/realtime

When calling, replace {WorkspaceId} with your actual Workspace ID.

Alibaba Cloud Model Studio has launched workspace-dedicated domains for the China (Beijing) and Singapore regions, which deliver superior performance and higher stability for inference requests. We recommend migrating to the new domains:
  • China (Beijing) region: migrate from wss://dashscope.aliyuncs.com to wss://{WorkspaceId}.cn-beijing.maas.aliyuncs.com
  • Singapore region: migrate from wss://dashscope-intl.aliyuncs.com to wss://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com
Among them, {WorkspaceId} is your workspace ID, which you can view on the Workspace Details page in the Alibaba Cloud Model Studio console. Qwen3.8-Omni-Flash-Realtime must use the workspace-dedicated domains above; earlier models can continue to use the original domains.
The following request parameters can be configured through the chained methods or setters of the OmniRealtimeConfig object, and then passed as a parameter to the updateSession API.
ParameterTypeDescription
modalitiesList<OmniRealtimeModality>Model output modality settings, which support setting [OmniRealtimeModality.TEXT] (text output only) or [OmniRealtimeModality.TEXT, OmniRealtimeModality.AUDIO] (outputs audio and text).
voiceStringThe voice of the audio generated by the model. For supported voices, see the voice list.Default Voices:
  • Qwen3.5-Omni: "Tina"
  • qwen3-omni-flash-realtime-2025-09-15:“Cherry”,
inputAudioFormatOmniRealtimeAudioFormatThe 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.
outputAudioFormatOmniRealtimeAudioFormatThe 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.
instructionsStringThe 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:
conversation.updateSession(OmniRealtimeConfig.builder()
        .modalities(Arrays.asList(OmniRealtimeModality.AUDIO, OmniRealtimeModality.TEXT))
        .voice("Tina")
        .enableTurnDetection(true)
        .enableInputAudioTranscription(true)
        .parameters(Map.of(
                "instructions", "你是个人助理小云"
        ))
        .build()
);
smooth_outputBooleanOnly qwen3-omni-flash-realtime-2025-09-15 supports this setting.
  • true: Get colloquial responses
  • false: Get more written, formal responses
    However, the results may be poor if the content is difficult to read aloud.
  • null: Default value. The model automatically selects a colloquial or written response style
smooth_output must be set through the parameters method of an OmniRealtimeConfig instance, with the same usage as instructions.
enableInputAudioTranscriptionBooleanWhether to enable speech recognition for input audio.
InputAudioTranscriptionStringThe speech recognition model used for input audio transcription, fixed to qwen3-asr-flash-realtime, and cannot be changed
enableTurnDetectionBooleanWhether to enable voice activity detection (VAD). If disabled, the user manually submits audio to create an omni response.
turnDetectionTypeStringThe VAD type. Valid values:
  • server_vad (default): Detects the end of user speech based on acoustic features.
  • semantic_vad: Detects the end of user speech based on semantic validity, and can filter out meaningless speech (such as backchannels and background noise). Supported by the Qwen3.8-Omni-Flash-Realtime and Qwen3.5-Omni-Realtime series models.
turnDetectionThresholdFloatThe VAD detection threshold. It is recommended to increase it in noisy environments and decrease it in quiet environments.
  • The closer the value is to -1, the higher the probability that noise is classified as speech.
  • The closer the value is to 1, the lower the probability that noise is classified as speech.
Defaults to 0.5. Value range: [-1.0, 1.0].
turnDetectionSilenceDurationMsIntegerThe silence duration for detecting speech stop; once exceeded, a model response is triggered. Defaults to 800. Value range: [200, 6000].
turnDetectionParamMapThe 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_searchBooleanApplies 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.
enable_search and search_options must be set through the parameters method of an OmniRealtimeConfig instance, with the same usage as instructions.
Tool calling (tools) and web search (enable_search) are incompatible and cannot be enabled at the same time.
search_optionsObjectWeb 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.
search_options must be set through the parameters method of an OmniRealtimeConfig instance, with the same usage as instructions.
toolsList<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:
  • type (String, required): Fixed to "function".
  • function (Map, required): The definition of the tool function, containing the following fields:
    • name (String, required): The custom name of the tool function. It is recommended to use the same name as the function, such as get_current_weather or get_current_time.
    • description (String, optional): A description of the tool function's capability. The model refers to this field to decide whether to use the tool function.
    • parameters (Map, optional): A description of the input parameters of the tool function. The model refers to this field to extract the input parameters. If the tool function does not require input parameters, you do not need to specify this field. It contains the following fields:
      • type (String, required): Fixed to "object".
      • properties (Map, optional): Describes the name, data type, and description of each input parameter. The Key is the name of the input parameter, and the Value is a Map containing the data type (type) and description (description).
      • required (List, optional): Specifies which input parameters are required.
search_options must be set through the parameters method of an OmniRealtimeConfig instance, with the same usage as instructions.
temperatureFloatSampling 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:
  • qwen3.8-omni-flash-realtime: 0.6
  • qwen3.5-omni-realtime series: 0.7
  • qwen3-omni-flash-realtime-2025-09-15: 0.9
temperature must be set through the parameters method of the OmniRealtimeConfig instance, with the same usage as instructions.
top_pFloatThe 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:
  • qwen3.8-omni-flash-realtime: 0.95
  • qwen3.5-omni-realtime series: 0.8
  • qwen3-omni-flash-realtime-2025-09-15: 1.0
top_p must be set through the parameters method of the OmniRealtimeConfig instance, with the same usage as instructions.
top_kIntegerThe 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:
  • qwen3.8-omni-flash-realtime: 20
  • qwen3.5-omni-realtime series: 20
  • qwen3-omni-flash-realtime-2025-09-15: 50
top_k must be set through the parameters method of the OmniRealtimeConfig instance, with the same usage as instructions.
max_tokensIntegerThe maximum number of tokens returned by this request.
The max_tokens setting does not affect the model's generation process. If the number of tokens generated by the model exceeds max_tokens, this request returns truncated content.
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.
max_tokens must be set through the parameters method of the OmniRealtimeConfig instance, with the same usage as instructions.
repetition_penaltyFloatThe 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:
  • qwen3.8-omni-flash-realtime: 0
  • qwen3.5-omni-realtime series: 1.0
  • Other models: 1.05
repetition_penalty must be set through the parameters method of the OmniRealtimeConfig instance, with the same usage as instructions.
presence_penaltyFloatControls 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:
  • qwen3.8-omni-flash-realtime: 1
  • qwen3.5-omni-realtime series: 1.5
  • Other models: 0.0
Applicable Scenario:A higher presence_penalty is suitable for scenarios that require diversity, fun, or creativity, such as creative writing or brainstorming.A lower presence_penalty is suitable for scenarios that require consistency or professional terminology, such as technical documents or other formal documents.
presence_penalty must be set through the parameters method of the OmniRealtimeConfig instance, with usage the same as instructions.
seedIntegerSetting 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.
seed must be set through the parameters method of the OmniRealtimeConfig instance, with usage the same as instructions.

API Reference

OmniRealtimeConversation class

OmniRealtimeConversation is imported via import com.alibaba.dashscope.audio.omni.OmniRealtimeConversation;.
Method signatureServer-side response events (delivered via callbacks)Description
public void connect() throws NoApiKeyException, InterruptedException
Server-side events
Session created
session.updated
Session configuration updated
Establishes a connection with the server.
public void updateSession(OmniRealtimeConfig config)
session.updated
Session 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.
public void appendAudio(String audioBase64)
NoneAppends 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.
  • With "turn_detection" enabled, the audio buffer is used for speech detection, and the server decides when to commit.
  • With "turn_detection" disabled, the client can choose how much audio to place in each event, up to 15 MiB. For example, streaming smaller chunks from the client can make VAD respond more quickly.
public void appendVideo(String videoBase64)
NoneAdds 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:
  • The image format must be JPG or JPEG. The recommended image resolution is 480P or 720P, with a maximum of 1080P;
  • A single image must not exceed 256KB after Base64 encoding. We recommend that the original image size before encoding does not exceed 190KB;
  • The image data must be Base64-encoded;
  • We recommend that you send images to the server at a rate of 1 image per second;
public void clearAppendedAudio()
input_audio_buffer.cleared
Clears the audio received by the server
Deletes the audio in the current cloud buffer.
public void commit()
input_audio_buffer.committed
The 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.
  • When "turn_detection" is enabled, the client does not need to send this event; the server automatically commits the audio buffer.
  • When "turn_detection" is disabled, the client must commit the audio buffer to create a user message item.
Note:
  1. If input_audio_transcription is configured for the session to transcribe audio, the system transcribes the audio.
  2. Committing the input audio buffer does not create a response from the model.
public void createResponse(String instructions, List<OmniRealtimeModality> modalities)
Server-side events
The server starts generating a response
response.output_item.added
New output content during the response
Server-side events
A conversation item is created
response.content_part.added
New output content is added to the assistant message item
response.audio_transcript.delta
Transcription text generated incrementally
response.audio.delta
Audio incrementally generated by the model
response.audio_transcript.done
Text transcription completed
response.audio.done
Audio generation completed
response.content_part.done
Streaming of the text or audio content of the Assistant mesasge is complete
response.output_item.done
Streaming of the entire output item of the Assistant mesasge is complete
response.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.
public void cancelResponse()
NoneCancels the in-progress response. If there is no response to cancel, the server responds with an error.
public void createItem(JsonObject item)
NoneSends 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:
  • type: Fixed to function_call_output.
  • call_id: Corresponds to the call_id in the response.function_call_arguments.done event.
  • output: A string of the tool execution result.
MCP approval also uses this event, but item.type is mcp_approval_response; for the fields, see MCP approval response in client events.
public void close()
NoneTerminates the task and closes the connection.
public String getSessionId()
NoneGets the session_id of the current task.
public String getResponseId()
NoneGets 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;.
MethodParameterReturn valueDescription
public void onOpen()
NoneNoneThis method is called back immediately after the connection to the server is established.
public abstract void onEvent(JsonObject message)
message: the server response event.NoneIt includes the response to the API call and the text and audio generated by the model. For more information, see Server events.
public abstract void onClose(int code, String reason)
code: the status code of the websocket shutdown.reason: the closing reason of the websocket shutdown.NoneThis method is called back after the server has closed the connection.