Build voice assistants and customer service apps that can talk and use tools at the same time.
The old WebSocket path for Qwen-Audio-Live,
/api-ws/v1/realtime, remains available but will no longer be maintained. If your application uses this path, switch to /api-ws/v1/live as soon as possible.
Quickstart
- Test with a recording. Run the Python example on this page and check the captions and audio returned by the model.
- Talk to the model using your microphone. Run the WebRTC browser example to hear model responses directly.
Establish your first session
This example sends a recorded audio clip to the model via WebSocket and saves the voice response to reply.wav.
Prepare the audio recording and credentials
- Qwen-Audio-Live requires a workspace-specific domain. For this example, obtain a China (Beijing) workspace ID and an API key for that workspace. Keep the API key on your application server. For the Singapore endpoint, see WebSocket access.
- Install Python and FFmpeg. Record the phrase 'Please count from one to three' and save it as
input.wav.
DASHSCOPE_API_KEY environment variable to your API key. Install the dependency and convert the recording to 16 kHz, 16-bit, mono PCM.
Send the recording and receive the response
Save the following code as live_quickstart.py and enter your workspace ID in the connection URL. You can use the model values in the example.
reply.wav to hear the model count. The file contains 24 kHz, 16-bit, mono audio. To change the model, voice, or audio transport, see Configure a session.
If no response is received, first verify that the API Key, Workspace ID, and connection URL all belong to the same region. Audio transmission begins only after receiving session.updated. For troubleshooting audio, captions, and errors, see Troubleshoot integration issues.
Choose how to connect
Both setups start with a WebSocket connection. Choose a setup based on how you want to send and receive audio.
-
WebSocket only. One connection carries audio, transcripts, and task events. Use it to test with a recording or to stream audio from a server. You can connect with the C# SDK or the Ruby SDK.

-
WebSocket + WebRTC or AOQ. Keep the control WebSocket open to configure the session, set up the media connection, and send task requests. Once the media connection is ready, use it to send and receive audio. Receive server events over either connection.

Write prompts
Write the frontend conversation prompt
Use session.instructions to define the frontend role, tone, when to ask for missing information, when to delegate, and how to present the result.
If you omit session.instructions in the initial session configuration, the frontend model uses its built-in instructions. Providing session.instructions replaces them. Include all the conversation rules you need in your custom instructions.
To make the customer service agent first give a brief answer and then ask whether the user needs further assistance, add the following field to the session object in session.update while retaining existing settings such as model and delegation.
Define task instructions
Define task steps, input checks, and result formats where the task runs. In Client mode, put those rules in your application or agent. In Responses mode, use session.delegation.responses.instructions. Model Studio supplies no built-in backend instructions.
Split the prompts for a calculation
In this Responses mode example, the frontend asks for missing inputs and the backend calculates the total.
- Frontend prompt. Ask for the unit price or quantity if either is missing. When you have both, delegate the calculation to the backend model. Read the result aloud in one sentence.
- Backend prompt. Calculate the total from the unit price and quantity. Return the amount and currency.
Manage sessions
After connecting, configure the session to choose the frontend model, voice, audio transport, and task delegation mode.
Configure a session
| Setting | What to configure |
|---|---|
| Frontend model | In the connection URL, model=qwen-audio-3.1-live selects the service. In the session, session.model selects the model that speaks with the user. The quickstart uses qwen-audio-4.0-realtime-preview and sets session.turn_detection.type to duplex for full-duplex conversation. The model can keep listening while it speaks. |
| Conversation instructions and voice | Set instructions and voice. See Write prompts and Set the voice. |
| Output types | When modalities includes both text and audio, the service returns both speech and subtitles. |
| Audio transport | Omit session.transport to send and receive audio over the control WebSocket. To use WebRTC or AOQ, configure session.transport and follow the connection instructions to establish a media connection. |
| Task delegation mode | Set session.delegation. See Task delegation and tools. |
session.update, check session.updated for the effective configuration. With WebSocket only, you can send audio as soon as you receive this event. With WebRTC or AOQ, also wait for the media connection to become ready.
Set the voice
Set the voice ID in the session object in session.update and keep your other session settings.
qingyou corresponds to 'Qing You', and the default value is yunshu ('Yun Shu'). The full list is available in Client Events.
Send and receive speech and subtitles
The method of sending and receiving audio depends on the protocol selected during connection establishment.
- WebRTC sends and receives audio via media tracks. Browsers deliver remote audio tracks to the player.
- AOQ sends and receives audio via the SDK. Uplink audio must be sent through AOQ. After setting
session.transport.aoq.ws_audiototrue, the WebSocket control channel also receives a copy of downlink audio. See AOQ access for details. - WebSocket transmits audio via JSON events. Both input and output use mono PCM, but with different sampling rates.
| Data | Event | Processing method |
|---|---|---|
| Microphone audio or recording | Send session.input_audio.append | Split the 16 kHz, 16-bit, mono PCM audio into frames and Base64-encode each frame. The quickstart uses 20 ms frames. |
| Model audio response | Receive session.output_audio.delta | Decode the delta in the event and play the 24 kHz, 16-bit, mono PCM audio in arrival order. |
| Transcripts | Receive session.input_transcript.delta and session.output_transcript.delta | The first event carries the user’s speech transcript. The second carries the model’s response transcript. |
event_id before appending text.
If the UI has a microphone switch, send session.input_audio.mute or session.input_audio.unmute when the user toggles it. Update the switch after the service confirms the change. The session stays connected while muted.
Send text messages
In addition to voice, users can supplement information with text during a call—for example, typing a product name to look up. The application sends this text as a user message to the model via session.item.create.
End a session and view usage
When the user hangs up or selects End, send session.close and stop capturing microphone audio. After you receive session.closed, close the connection and release resources.
Once the session is active, the service reports usage.seconds in session.usage.updated every 5 seconds. This value is the cumulative billable session duration in seconds. Use the latest value during the call and the value in session.closed for final usage.
A session has no maximum duration. Qwen-Audio-Live charges for session time in seconds, with a 3-second minimum once the connection is established. Sessions longer than 3 seconds are billed for their actual duration. Text messages, silence, and idle time all count toward the session duration. When Model Studio calls a backend model, its actual token usage is billed separately. See Model pricing.
Troubleshooting integration issues
| Symptom | Troubleshooting method |
|---|---|
| No response after uploading audio | First confirm receipt of session.updated. For pure WebSocket integration, verify that the upstream audio is mono PCM at 16 kHz and 16 bits. For WebRTC or AOQ integrations, ensure the media connection is ready and audio is being sent over it. |
| Subtitles received but no audio response heard | For pure WebSocket integration, verify receipt of session.output_audio.delta and playback at 24 kHz. For WebRTC or AOQ integrations, verify the player is receiving downstream audio on the selected channel. |
| Words or whole sentences appear twice in the transcript | With WebRTC or AOQ, the same transcript event can arrive over both the control WebSocket and the media connection. Update the transcript from one connection, or deduplicate events by event_id across both connections before appending text. |
| Task processed but no voice announcement heard | Verify whether the application receives and plays the frontend model’s voice. In Client mode, confirm the returned delegation_id matches the task. |
Receive error or session.closed | Upon receiving error, refer to the Error Events for request diagnostics. After session closure, reestablish the connection and reconfigure the session to continue the conversation. |
Task delegation and tools
The examples in this section use the WebSocket-only connection from Quickstart. With WebRTC or AOQ, use the control WebSocket to configure the session and send task requests. Send and receive audio over the media connection.
Choose where to configure tools
When a user makes a request during a conversation, the frontend model can call a function directly or delegate the task to the backend. Choose where to configure each tool based on the steps involved and how quickly the user needs a response.
- Frontend tools suit straightforward actions that need a quick response. For example, when a user says “Play music,” the frontend model calls a function registered in
session.tools, and your application plays the music. - Backend tools suit tasks that require checking conditions or calling several tools in sequence. For example, if the backend model has the tools to look up a booking, change rules, and departures, it can use them to find eligible departures. The frontend model reads the options to the user.
Choose a task delegation mode
Choose Responses mode if you want Model Studio to call a backend model and pass its result to the frontend model. Choose Client mode if you already have a business API, workflow, or agent, or if your application needs to verify the result before deciding what the user hears.
Set session.delegation.type in session.update. Set it to responses for Responses mode or client for Client mode.
| Decision | Responses mode | Client mode |
|---|---|---|
| Who handles the task? | Model Studio calls the configured backend Responses model. | Your application calls a business API, workflow, agent, or model. |
| Who prepares the input? | Your application configures the backend model and its instructions in advance. When the frontend delegates a task, Model Studio prepares the input from the current conversation and sends the request. | Your application combines the task summary and context from the delegation event with its business data. |
| Who decides what to return? | Model Studio passes the backend result to the frontend model. | Your application can validate, combine, or filter the result before returning the information to speak. |
call_id to match a call to its result. Client delegation uses delegation_id to match a task to its updates. Before connecting a business system, check your application's API permissions, required inputs, and response format.
Call a backend model in Responses mode
Before you begin
Choose a backend Responses model your workspace can call. This example uses qwen4-max to calculate a total, which the frontend model reads aloud.
Configure the session
Set session.delegation.type to responses and select the backend model in session.delegation.responses.model. You can also set backend task instructions in instructions and configure tools in tools within the same object.
For example, to calculate a total, the frontend prompt can say, “If the unit price or quantity is missing, ask the user for it. Once you have both, delegate the calculation to the backend.” The backend prompt can say, “Calculate the total from the unit price and quantity. Return the amount and currency.”
Receive backend events
When automatic delegation starts, the service sends session.delegation.created. During backend generation, it forwards backend events in response.event. Use the outer delegation_id, when present, to match events to a task, and use event.type to distinguish backend events.
A nested response.completed means the backend has finished generating. The frontend model delivers the spoken reply. The script displays its transcript and saves the audio to reply.wav.
Test delegation and playback
Save the following complete example as live_responses.py and enter your workspace ID in the connection URL. The script allows 30 seconds for backend processing and speech output.
responses.wav. Convert the recording and run the script.
reply.wav to verify that the model announces the total amount of 4,251 yuan. Backend generation completion is marked by response.completed in response.event. Playback progress is tracked by the player.
Record a second request that gives only the unit price, such as “Each item costs 327 yuan. What is the total?” Convert it and run the script again. Check the transcript or the new reply.wav to see whether the model asks for the quantity.
Configure and monitor backend tools
Declare tools for the backend model in session.delegation.responses.tools. See the Responses API for the tool definition format. For automatic delegation, the service runs supported backend tools and handles their results. Your application can monitor tool execution through response.event. When the nested event is response.output_item.done and event.item.type is function_call, read the function name (name), arguments (arguments), and call ID (call_id) from event.item.
If your application needs to run and verify a business operation, use Client mode to receive the task, or declare a frontend function to receive structured arguments.
Start backend generation from your application
If your application already has the input, send response.item.create to provide text and then send response.create to start a separate backend task. Read its output from response.event.
Save the following complete example as live_responses_text.py and enter your workspace ID in the connection URL. The script sends text and prints the backend model’s result in your terminal.
python live_responses_text.py. The terminal prints the amount returned by the backend model.
Connect your application in Client mode
In Client mode, the frontend model delegates tasks to your application. The application performs the business operation and returns the result for the frontend model to share with the user.
Before you begin
- Run the example. Follow the quickstart to prepare your workspace ID, API key, and runtime. Record a spoken inventory request. When the application receives the task, it returns the preset answer “Seven black folding umbrellas are in stock” for the frontend to read aloud. You can run this example without an inventory API.
- Connect your own business system. Check that your application can call the API, knows its required inputs, and can identify the data to share with the user. For example, if an inventory API takes a product ID, the application looks up the ID from the name the user provided, queries the stock, and returns both the name and the quantity available.
Configure the session
Set session.delegation.type to client. In the frontend prompt, specify which tasks to delegate and how to respond when results arrive. The inventory example uses “Delegate inventory checks to the application and speak the result when it arrives.”
Receive the task and prepare context
When you receive session.delegation.created, deduplicate by event_id and save the delegation_id to track updates for the same task. Read the task information from summary and context, if present, and combine it with your application’s business data. For example, your application can use the product name and the current store to find the product ID for an inventory lookup.
If required information is missing, have the frontend model ask the user for it. For example, if the user asks about stock without naming a product, ask which product they mean. Match subsequent session.delegation.created events to the task by delegation_id. Read any additional details from supplements when present, and run the lookup once you have the required inputs.
Send progress, clarification requests, and results
Include the current task's delegation_id and choose the event for the content you want to send.
| What to send | Event | Example content |
|---|---|---|
| Progress to share without speaking it | session.thinking.append | Checking stock at the selected store. |
| A detail to ask the user for | session.instruction.append | Ask the user which product to look up. |
| A result for the frontend model to speak | session.commentary.append | Seven black folding umbrellas are in stock. |
Test task delegation and spoken results
Save the following complete example as live_client.py and enter your workspace ID in the connection URL.
client.wav. Convert the recording and run the script.
reply.wav to verify the speech includes the returned inventory result. When integrating with a real inventory API, replace the fixed result with the API’s actual response.
Configure and handle the frontend function
The previous example delegates the entire inventory lookup to the application, which prepares the query. If you already have a function that looks up stock by product name, the frontend model can call it directly. Declare the function and its parameters in session.tools so the frontend model can extract the name from the conversation and pass it to your application. Frontend functions work in both Client and Responses modes.
Add the following fields to the session object in session.update and retain your other session settings.
- Upon receiving
session.event, read the invocation entry inevent.itemwheretypeequalsfunction_call. - Locate the function per
name, parseargumentsfrom its JSON string into parameters, validate them, then execute. Eachcall_idexecutes only once. - Send
session.item.createto return the result. Setitem.typetofunction_call_outputand setitem.call_idto thecall_idfrom the function call.
Migrate from Qwen-Audio-Realtime
If your application already uses Qwen-Audio-Realtime, retain your existing business interfaces and tool implementations. First validate audio send/receive functionality with Quickstart for Qwen-Audio-Live, then migrate event handling and task logic.
| Migration Items | Handling Method in Qwen-Audio-Live |
|---|---|
| WebSocket Connection | Use Qwen-Audio-Live request URL and configure the frontend model and task processing mode in session.update. |
| WebSocket Audio | Switch upstream to session.input_audio.append and downstream to reading session.output_audio.delta. When using duplex conversation as shown on this page, continuously send audio—no need to retain the manual-mode input_audio_buffer.commit and response.create. See Audio and Subtitle Transmission for format and sampling rate details. |
| WebRTC Signaling | Previously, SDP was exchanged over HTTP. When integrating with Live, send the Offer via the control WebSocket and read the Answer from session.transport.sdp in session.updated. See WebRTC access. |
| Frontend Functions | Read function invocations from session.event. After execution, return results via session.item.create following call_id. The legacy flow used response.create to resume frontend replies. Live’s response.create explicitly initiates backend tasks. |
| Time-Consuming Business Tasks | Choose Client or Responses per Task Delegation and Tools. Validate task results and speech playback using a voice request requiring tool invocation. |