Use WebSocket to establish a session, stream audio, and handle task events.
Endpoint and authentication
China (Beijing)
{WorkspaceId} with your workspace ID in the selected region. Set the Authorization header to Bearer <API Key> using an API key from the same region.
The model query parameter selects the Qwen-Audio-Live service. Set session.model to the frontend speech model, such as qwen-audio-4.0-realtime-preview for a full-duplex conversation.
Start a session and stream audio
- Open the connection and send
session.update. To send and receive audio over this connection, omitsession.transportfrom the session configuration. Wait forsession.updated. - After confirmation, send audio frame by frame with
session.input_audio.appendas Base64-encoded 16 kHz, 16-bit, mono PCM. Decode the Base64 data insession.output_audio.deltaas 24 kHz, 16-bit, mono PCM. - Read
session.input_transcript.deltafor input transcription andsession.output_transcript.deltafor reply captions. - Send
session.closeand release resources when you receivesession.closed.
Handle tasks
| Mode | Task flow |
|---|---|
| Client | Execute the task from session.delegation.created and submit the result using session.commentary.append. The frontend model can respond in speech. |
| Responses | Read backend progress and results from response.event after the delegation event. Use the frontend audio events to receive the spoken reply. |
session.event. Return the result with session.item.create. See client events, server events, and AOQ access.