Read session status, voice responses, and task execution results.
Receive JSON events over the control WebSocket. When using WebRTC or AOQ, wait for session.updated on that WebSocket. Once the media connection is ready, you can also receive server events over the WebRTC DataChannel or the AOQ data track.
Handle events according to type. The client_event_id in the acknowledgment corresponds to the event_id in the request. The event_id of each server-side event uniquely identifies that event.
session.created
After the connection is established, the service returns default session information. After sending session.update, wait for session.updated to confirm that the configuration has taken effect.
typestringRequiredEvent type; fixed value: session.created.
event_idstringRequiredServer-side event ID.
sessionobjectRequiredDefault session information.
View child fields
idstringRequiredBusiness session ID. AOQ Relay uses an independent sid.
objectstringRequiredCompatible object name, e.g., realtime.session.
modelstringRequiredDeployed default frontend voice model.
modalitiesarrayReturned per modelOutput modality.
voicestringReturned per modelDefault voice style.
turn_detectionobjectReturned per modelDefault turn detection configuration. The detection settings below are returned when type is server_vad.
View child fields
typestringTurn detection type.
thresholdnumberVoice activity detection threshold.
prefix_padding_msintegerLength of audio retained before the detected speech start, in milliseconds.
silence_duration_msintegerDuration of silence required to detect the end of speech, in milliseconds.
create_responsebooleanWhether to generate a reply automatically when speech ends.
interrupt_responsebooleanWhether to interrupt an ongoing reply when the user starts speaking.
input_audio_transcriptionobjectReturned per modelAudio transcription capability and its default configuration.
View child fields
modelstringModel used to transcribe input audio.
model_inferencebooleanRequiredThe service supports integration with models. Inference and interaction begin only after the session configuration takes effect.
{
"type": "session.created",
"event_id": "evt_created",
"session": {
"id": "sess_demo",
"object": "realtime.session",
"model": "<default frontend model ID>",
"modalities": [
"text",
"audio"
],
"turn_detection": {
"type": "server_vad"
},
"input_audio_transcription": {
"model": "<transcription model ID>"
},
"model_inference": true
}
}
session.updated
The session configuration has taken effect. Use the returned configuration.
typestringRequiredEvent type; fixed value: session.updated.
event_idstringRequiredServer-side event ID.
sessionobjectRequiredEffective session configuration, including session metadata and task mode.
View child fields
idstringRequiredBusiness session ID.
modelstringRequiredEffective frontend voice model.
objectstringReturned per configurationSession object type.
modalitiesarrayReturned per configurationEffective output modality.
delegationobjectRequiredTask mode.
View child fields
typestringRequiredclient or responses.
transportobjectReturned per configurationReturns connection information for the selected transmission method.
View child fields
typestringReturned per configurationWhen using WebRTC, the value is rtc.
sdpstringReturned per configurationWhen using WebRTC, returns the Answer SDP. The client sets it as the remote description. For details, see WebRTC access.
aoqobjectReturned per configurationWhen using AOQ, returns temporary connection information. Use the returned sid and temporary credentials to initiate the AOQ connection within 5 minutes of receiving session.updated. For steps to connect, see AOQ access.
View child fields
sidstringAOQ session ID.
aoqTokenForClientstringTemporary token that the client uses to connect to the Relay.
clientRelayCertFingerprintstringFingerprint of the Relay’s TLS certificate.
clientRelayEndpointsarrayList of Relay addresses for the connection.
View child fields
endpointstringRelay address.
portintegerRelay port.
route_indexintegerRelay route index.
extraInfoobjectAdditional connection information.
View child fields
workspaceIdHashstringHash of the workspace ID.
WebSocket
{
"type": "session.updated",
"event_id": "evt_updated",
"session": {
"id": "sess_demo",
"object": "realtime.session",
"model": "qwen-audio-4.0-realtime-preview",
"modalities": [
"text",
"audio"
],
"delegation": {
"type": "client"
}
}
}
WebRTC (excerpt)
{
"type": "session.updated",
"event_id": "evt_updated",
"session": {
"id": "sess_demo",
"transport": {
"type": "rtc",
"sdp": "<Answer SDP>"
}
}
}
AOQ (excerpt)
{
"type": "session.updated",
"event_id": "evt_updated",
"session": {
"id": "sess_demo",
"transport": {
"aoq": {
"sid": "<AOQ session ID>",
"aoqTokenForClient": "<temporary token>",
"clientRelayCertFingerprint": "<Relay TLS certificate fingerprint>",
"clientRelayEndpoints": [
{
"endpoint": "192.0.2.10",
"port": 8443,
"route_index": 0
}
],
"extraInfo": {
"workspaceIdHash": "<workspace ID hash>"
}
}
}
}
}
session.input_audio.muted
Input is muted.
typestringRequiredEvent type; fixed value: session.input_audio.muted.
event_idstringRequiredServer-side event ID.
client_event_idstringOptionalCorresponds to the client’s requested event_id.
{
"type": "session.input_audio.muted",
"event_id": "evt_muted",
"client_event_id": "evt_mute"
}
session.input_audio.unmuted
Input is unmuted.
typestringRequiredEvent type; fixed value: session.input_audio.unmuted.
event_idstringRequiredServer-side event ID.
client_event_idstringOptionalCorresponds to the client’s requested event_id.
{
"type": "session.input_audio.unmuted",
"event_id": "evt_unmuted",
"client_event_id": "evt_unmute"
}
session.input_transcript.delta
Receives the transcription of user speech.
typestringRequiredEvent type; fixed value: session.input_transcript.delta.
event_idstringRequiredServer-side event ID.
deltastringRequiredThe transcription text returned in this response.
start_msnumberRequiredStart time on the session timeline, in milliseconds.
end_msnumberRequiredEnd time on the session timeline, in milliseconds.
{
"type": "session.input_transcript.delta",
"event_id": "evt_input_transcript",
"delta": "帮我查库存。",
"start_ms": 1600,
"end_ms": 1600
}
session.output_transcript.delta
Receives subtitles for the frontend voice reply. Subtitle timestamps are used to locate positions on the session timeline.
typestringRequiredEvent type; fixed value: session.output_transcript.delta.
event_idstringRequiredServer-side event ID.
deltastringRequiredThe reply text returned in this response.
start_msnumberRequiredStart time on the session timeline, in milliseconds.
end_msnumberRequiredEnd time on the session timeline, in milliseconds.
{
"type": "session.output_transcript.delta",
"event_id": "evt_output_transcript",
"delta": "库存还有七把雨伞。",
"start_ms": 5400,
"end_ms": 5400
}
session.output_audio.delta
Receives an audio chunk from the frontend voice.
typestringRequiredEvent type; fixed value: session.output_audio.delta.
event_idstringOptionalServer-side event ID.
deltastringRequiredBase64-encoded 24 kHz mono PCM16LE raw audio. After decoding, the byte count is even. The audio has no WAV file header.
start_msnumberRequiredStart time on the session timeline, in milliseconds.
end_msnumberRequiredEnd time on the session timeline, in milliseconds.
{
"type": "session.output_audio.delta",
"delta": "AAAAAA==",
"start_ms": 5400,
"end_ms": 5420
}
session.delegation.created
The frontend model dispatches a task. This event is received in both Client mode and Responses mode. When returning the task result, use the delegation_id from the corresponding task event.
typestringRequiredEvent type; fixed value: session.delegation.created.
event_idstringRequiredServer-side event ID.
offset_msnumberRequiredThe offset of this dispatch on the session timeline, in milliseconds.
delegation_idstringRequiredThe task ID associated with this dispatch.
task_idstringOptionalTask ID. Used in the return payload as delegation_id.
summarystringReturned upon task dispatchSummary of the dispatched task in this response.
contextobjectReturned upon task dispatchContext snapshot at the time the task is accepted.
View child fields
summarystringRequiredContext summary.
messagesarray[object]Returned upon task dispatchContext messages.
View child fields
seqintegerSequence number of the message in the context.
item_idstringMessage item ID.
rolestringRole of the message sender.
sourcestringSource of the message.
audio_start_msintegerStart offset of the audio on the session timeline, in milliseconds.
audio_end_msintegerEnd offset of the audio on the session timeline, in milliseconds.
playbackstringAudio playback status.
contentstringMessage text.
incompletebooleanWhether the context snapshot is incomplete.
truncatedbooleanWhether the context snapshot was truncated.
supplementsarrayReturned per taskAdditional content accepted in this batch and their respective contexts.
View child fields
summarystringRequiredSupplementary content summary.
contextobjectReturned upon task dispatchContext snapshot at the time the task is accepted.
View child fields
summarystringRequiredContext summary.
messagesarrayReturned upon task dispatchContext messages.
argumentsstringOptionalCompatible field. A JSON string that may contain summary.
{
"type": "session.delegation.created",
"event_id": "evt_delegation",
"offset_ms": 3600,
"delegation_id": "task_stock",
"task_id": "task_stock",
"summary": "查询雨伞库存。",
"context": {
"summary": "",
"messages": [
{
"seq": 1,
"item_id": "item_stock_001",
"role": "user",
"audio_start_ms": 900,
"audio_end_ms": 3600,
"content": "查询雨伞库存。"
}
],
"incomplete": false,
"truncated": false
},
"supplements": [
{
"summary": "查询雨伞库存。",
"context": {
"summary": "",
"messages": []
}
}
],
"arguments": "{\"summary\":\"查询雨伞库存。\"}"
}
session.event
Receives frontend function calls. Uses call_id to correlate results.
typestringRequiredEvent type; fixed value: session.event.
event_idstringRequiredServer-side event ID.
client_event_idstringOptionalCorresponds to the client’s requested event_id.
eventobjectRequiredFrontend model function call event.
View child fields
typestringRequiredInner event name.
itemobjectReturns per event.Function call item.
View child fields
typestringRequiredThe function call item is function_call.
namestringRequiredFunction name.
call_idstringRequiredCall ID.
argumentsstringRequiredFunction arguments in JSON string format.
idstringReturns per event.Call item ID.
statusstringReturns per event.Call item status.
output_indexnumberReturns per event.Output location of the call item.
response_idstringReturns per event.Frontend response ID.
{
"type": "session.event",
"event_id": "evt_frontend_tool",
"event": {
"type": "response.output_item.added",
"item": {
"type": "function_call",
"name": "lookup_stock",
"call_id": "call_stock",
"arguments": "{\"item\":\"雨伞\"}",
"id": "item_stock",
"status": "completed"
},
"output_index": 0,
"response_id": "resp_frontend"
}
}
response.event
Receives backend generation or task events. The inner response.completed indicates the end of backend generation. Frontend voice responses have their own subtitle and audio events.
typestringRequiredEvent type; fixed value: response.event.
event_idstringRequiredServer-side event ID.
delegation_idstringReturns per event.Associated task ID.
client_event_idstringOptionalCorresponds to the client’s requested event_id.
eventobjectRequiredBackend native event or task event.
View child fields
typestringRequiredInner event name.
responseobjectReturns per event.Backend response. Fields vary by event.
View child fields
idstringReturns per event.Backend response ID.
usageobjectOptionalBackend model token usage.
View child fields
input_tokensintegerReturns per event.Number of input tokens consumed by the backend model.
output_tokensintegerReturns per event.Number of output tokens generated by the backend model.
total_tokensintegerReturns per event.Total number of input and output tokens.
{
"type": "response.event",
"event_id": "evt_backend_completed",
"delegation_id": "task_calc",
"event": {
"type": "response.completed",
"response": {
"id": "resp_calc",
"usage": {
"input_tokens": 28,
"output_tokens": 12,
"total_tokens": 40
}
}
}
}
session.thinking.appended
Service has accepted the task progress. For request session.thinking.append, the acknowledgment can be matched using the associated field.
typestringRequiredEvent type; fixed value: session.thinking.appended.
event_idstringRequiredServer-side event ID.
start_msnumberRequiredStart time on the session timeline, in milliseconds.
end_msnumberRequiredEnd time on the session timeline, in milliseconds.
client_event_idstringOptionalCorresponds to the client’s requested event_id.
{
"type": "session.thinking.appended",
"event_id": "evt_ack",
"start_ms": 2000,
"end_ms": 2000,
"client_event_id": "evt_client_request"
}
session.instructions.appended
Service has accepted the follow-up content. For request session.instruction.append, the acknowledgment can be matched using the associated field.
typestringRequiredEvent type; fixed value: session.instructions.appended.
event_idstringRequiredServer-side event ID.
start_msnumberRequiredStart time on the session timeline, in milliseconds.
end_msnumberRequiredEnd time on the session timeline, in milliseconds.
client_event_idstringOptionalCorresponds to the client’s requested event_id.
{
"type": "session.instructions.appended",
"event_id": "evt_ack",
"start_ms": 2000,
"end_ms": 2000,
"client_event_id": "evt_client_request"
}
session.commentary.appended
Service has accepted the result or text. For request session.commentary.append, the acknowledgment can be matched using the associated field.
typestringRequiredEvent type; fixed value: session.commentary.appended.
event_idstringRequiredServer-side event ID.
start_msnumberRequiredStart time on the session timeline, in milliseconds.
end_msnumberRequiredEnd time on the session timeline, in milliseconds.
client_event_idstringOptionalCorresponds to the client’s requested event_id.
{
"type": "session.commentary.appended",
"event_id": "evt_ack",
"start_ms": 2000,
"end_ms": 2000,
"client_event_id": "evt_client_request"
}
session.usage.updated
After session activation, the service reports cumulative billing duration every 5 seconds; reports are also sent during idle periods. The current value takes the latest usage.seconds, and the final value is read from session.closed. Backend model token usage is available in response.event.
typestringRequiredEvent type; fixed value: session.usage.updated.
event_idstringRequiredServer-side event ID.
usageobjectRequiredSession usage.
View child fields
secondsnumberRequiredCumulative billing duration for the session (in seconds). This is the greater of 3 seconds and the elapsed session duration.
context_windowobjectOptionalContext usage.
View child fields
usage_rationumberOptionalToken usage divided by the context limit. Results may be delayed.
{
"type": "session.usage.updated",
"event_id": "evt_usage",
"usage": {
"seconds": 32.5
},
"context_window": {
"usage_ratio": 0.12
}
}
session.closed
The session has ended. Stop sending events and release resources. To continue the conversation, establish a new connection and initialize a new session.
typestringRequiredEvent type; fixed value: session.closed.
event_idstringRequiredServer-side event ID.
reasonstringRequiredReason for closure. Possible values are close_requested, expired, content, remote_hangup, or connection_lost.
sessionobjectRequiredConfiguration snapshot returned when the session closes.
View child fields
idstringReturned with the snapshot.Business session ID.
objectstringReturned with the snapshot.Session object type.
statusstringReturned with the snapshot.The status in the snapshot may still show active. Use the session.closed event to determine that the session has closed.
modelstringReturned with the snapshot.Frontend speech model used for the session.
usageobjectRequiredFinal usage metrics at session termination.
View child fields
secondsnumberRequiredCumulative billing duration for the session (in seconds). This is the greater of 3 seconds and the elapsed session duration.
{
"type": "session.closed",
"event_id": "evt_closed",
"reason": "close_requested",
"session": {
"id": "sess_demo",
"object": "realtime.session",
"status": "active",
"model": "qwen-audio-4.0-realtime-preview"
},
"usage": {
"seconds": 45.8
}
}
error
Check the request and session status based on the error code. After receiving a close event, reestablish the connection.
typestringRequiredEvent type; fixed value: error.
event_idstringRequiredServer-side event ID.
errorobjectRequiredError details.
View child fields
typestringRequiredinvalid_request_error or server_error.
codestringRequiredError code. For example, invalid_session_configuration or invalid_event_state.
messagestringRequiredError description.
event_idstringOptionalCorresponds to the client’s requested event_id.
{
"type": "error",
"event_id": "evt_server_error",
"error": {
"type": "invalid_request_error",
"code": "invalid_session_configuration",
"message": "Invalid session configuration",
"event_id": "evt_update_client"
}
}