全部产品
Search
文档中心

大模型服务平台百炼:Qwen-Audio-Live 客户端事件

更新时间:Nov 24, 2026

配置会话、发送音频并回传任务结果。

通过控制 WebSocket 发送 JSON 事件。连接和鉴权见 WebSocket 接入。

session.update

发送此事件可配置会话,包括前台模型、对话指令和音频传输方式。省略 session.transport 时,音频通过控制 WebSocket 收发。服务通过 session.updated 确认配置已生效。仅用 WebSocket 时,收到确认后即可发送音频。使用 WebRTC 或 AOQ 时,还需等待媒体连接就绪。

typestring必填

事件类型,固定为 session.update。

event_idstring必填

客户端事件 ID。非空,最长 128 字符。

sessionobject必填

会话配置。

查看子字段

modelstring必填

会话使用的前台语音模型 ID。可选 qwen-audio-4.0-realtime-preview 或 qwen-audio-3.1-realtime-flash。

双工对话使用 qwen-audio-4.0-realtime-preview,并将 turn_detection.type 设为 duplex。

instructionsstring可选

初次配置会话时,如果省略 session.instructions,前台模型使用内置提示词。填写后,您提供的提示词会覆盖内置提示词。

modalitiesarray可选

输出模态。默认包含 audio 和 text。

voicestring可选

前台模型使用的系统音色 ID。默认值为 yunshu。

音色名称音色 ID
云舒yunshu
小满xiaoman
晚风wanfeng
青柚qingyou
破晓poxiao
麦芽maiya
乌龙wulong
雪松xuesong
turn_detectionobject可选

轮次检测配置。

查看子字段

typestring必填

使用双工对话时设为 duplex,前台模型选择 qwen-audio-4.0-realtime-preview。

input_audio_formatstring可选

输入格式。纯 WebSocket 使用 pcm,默认 16 kHz、单声道 PCM16LE。

output_audio_formatstring可选

输出格式。纯 WebSocket 使用 pcm,默认 24 kHz、单声道 PCM16LE。

toolsarray[object]可选

应用可以执行的前台函数。默认为空数组。

查看子字段

typestring

工具类型。自定义函数填 function。

namestring

函数名。

descriptionstring

函数用途。

parametersobject

使用 JSON Schema 描述函数参数。

查看子字段

typestring

参数结构类型。对象填 object。

propertiesobject

按参数名定义参数的类型和约束。键名由应用定义。

requiredarray[string]

必填参数的名称列表。

additionalPropertiesboolean | object

控制是否允许传入未声明的参数。设为 false 时拒绝未声明参数。

delegationobject必填

任务执行方式。

查看子字段

typestring必填

client 由应用执行任务。responses 由服务调用后台 Responses 模型。

responsesobject条件必填

Responses 模式必填。百炼将此处列出的配置传给后台模型。工具定义的格式见 Responses API。

查看子字段

modelstring必填

处理委派任务的后台 Responses 模型 ID,例如 qwen4-max。

instructionsstring可选

Responses 模式下的后台任务提示词由您配置。省略时,百炼不提供内置的后台提示词。

toolsarray[object]可选

声明供后台模型使用的工具。 工具元素通过 type 选择结构。以下字段适用于自定义函数(type 为 function)。

查看子字段

typestring

工具类型。自定义函数填 function。

namestring

函数名。

descriptionstring

函数用途。

parametersobject

使用 JSON Schema 描述函数参数。

查看子字段

typestring

参数结构类型。对象填 object。

propertiesobject

按参数名定义参数的类型和约束。键名由应用定义。

requiredarray[string]

必填参数的名称列表。

additionalPropertiesboolean | object

控制是否允许传入未声明的参数。设为 false 时拒绝未声明参数。

transportobject可选

省略或传空对象时使用 WebSocket。

查看子字段

typestring条件必填

显式选择传输方式时填写。websocket 使用 WebSocket,rtc 使用 WebRTC,aoq 使用 AOQ。

sdpstring条件必填

当 type 为 rtc 时必填。传入客户端生成的 Offer SDP。见 WebRTC 接入。

aoqobject可选

AOQ 配置。

查看子字段

ws_audioboolean可选

是否通过 WebSocket 附加一份下行音频。默认 false。

Client 模式

{
  "type": "session.update",
  "event_id": "evt_update_client",
  "session": {
    "model": "qwen-audio-4.0-realtime-preview",
    "modalities": [
      "text",
      "audio"
    ],
    "turn_detection": {
      "type": "duplex"
    },
    "delegation": {
      "type": "client"
    }
  }
}

Responses 模式

{
  "type": "session.update",
  "event_id": "evt_update_responses",
  "session": {
    "model": "qwen-audio-4.0-realtime-preview",
    "modalities": [
      "text",
      "audio"
    ],
    "turn_detection": {
      "type": "duplex"
    },
    "delegation": {
      "type": "responses",
      "responses": {
        "model": "qwen4-max"
      }
    }
  }
}

session.input_audio.append

仅用 WebSocket 接入时,通过此事件发送一帧音频。使用 WebRTC 时,通过 WebRTC 媒体轨道发送音频。使用 AOQ 时,通过 AOQ 媒体连接发送音频。

typestring必填

事件类型,固定为 session.input_audio.append。

event_idstring可选

客户端事件 ID。非空,最长 128 字符。

audiostring必填

Base64 编码的 16 kHz、16 位、单声道 PCM16LE。

{
  "type": "session.input_audio.append",
  "audio": "AAAAAA=="
}

session.input_audio.mute

将输入静音。服务返回 session.input_audio.muted。

typestring必填

事件类型,固定为 session.input_audio.mute。

event_idstring可选

客户端事件 ID。非空,最长 128 字符。

{
  "type": "session.input_audio.mute",
  "event_id": "evt_mute"
}

session.input_audio.unmute

恢复音频输入。服务返回 session.input_audio.unmuted。

typestring必填

事件类型,固定为 session.input_audio.unmute。

event_idstring可选

客户端事件 ID。非空,最长 128 字符。

{
  "type": "session.input_audio.unmute",
  "event_id": "evt_unmute"
}

session.item.create

输入用户文本,或回传前台函数结果。应用对同一 call_id 只执行一次函数。

typestring必填

事件类型,固定为 session.item.create。

event_idstring可选

客户端事件 ID。非空,最长 128 字符。

itemobject按用途填写

待写入的会话内容。

查看子字段

typestring必填

填 message 或 function_call_output。

rolestring按类型填写

消息发送者的角色。下方的用户文本示例使用 user。

contentarray按类型填写

message 的内容。

查看子字段

typestring必填

文本输入填 input_text。

textstring必填

用户文本。

call_idstring按类型填写

function_call_output 对应的前台函数调用 ID。

outputstring按类型填写

function_call_output 的字符串结果。

回传函数结果

{
  "type": "session.item.create",
  "event_id": "evt_function_result",
  "item": {
    "type": "function_call_output",
    "call_id": "call_stock",
    "output": "{\"stock\":7}"
  }
}

输入文本

{
  "type": "session.item.create",
  "event_id": "evt_user_message",
  "item": {
    "role": "user",
    "type": "message",
    "content": [
      {
        "type": "input_text",
        "text": "请查询雨伞库存。"
      }
    ]
  }
}

session.thinking.append

更新任务进度。服务返回 session.thinking.appended。

typestring必填

事件类型,固定为 session.thinking.append。

event_idstring可选

客户端事件 ID。非空,最长 128 字符。

delegation_idstring必填

使用当前连接收到的 session.delegation.created 中的 ID。

contentstring必填

任务进度。

start_msnumber可选

会话时间线上的开始时间,单位为毫秒。

end_msnumber可选

结束时间,单位为毫秒。与 start_ms 成对提供。两者须为有限非负数,结束时间不得早于开始时间。

{
  "type": "session.thinking.append",
  "event_id": "evt_thinking",
  "delegation_id": "task_stock",
  "content": "正在查询库存。"
}

session.instruction.append

提供需要用户补充的问题。服务返回 session.instructions.appended。

typestring必填

事件类型,固定为 session.instruction.append。

event_idstring可选

客户端事件 ID。非空,最长 128 字符。

delegation_idstring必填

使用当前连接收到的 session.delegation.created 中的 ID。

task_idstring可选

通常省略。

contentstring必填

需要用户补充的信息。

start_msnumber可选

会话时间线上的开始时间,单位为毫秒。

end_msnumber可选

结束时间,单位为毫秒。与 start_ms 成对提供。两者须为有限非负数,结束时间不得早于开始时间。

{
  "type": "session.instruction.append",
  "event_id": "evt_instruction",
  "delegation_id": "task_stock",
  "content": "请问要查哪种商品的库存?"
}

session.commentary.append

回传本连接受理的任务结果,也可提交用户文本。服务返回 session.commentary.appended。

typestring必填

事件类型,固定为 session.commentary.append。

event_idstring可选

客户端事件 ID。非空,最长 128 字符。

delegation_idstring任务回传时必填

使用当前连接收到的 session.delegation.created 中的 ID。

contentstring可选

任务结果或用户文本。

start_msnumber可选

会话时间线上的开始时间,单位为毫秒。

end_msnumber可选

结束时间,单位为毫秒。与 start_ms 成对提供。两者须为有限非负数,结束时间不得早于开始时间。

errorobject可选

任务错误信息。

回传任务结果

{
  "type": "session.commentary.append",
  "event_id": "evt_stock_result",
  "delegation_id": "task_stock",
  "content": "库存还有七把雨伞。"
}

输入文本

{
  "type": "session.commentary.append",
  "event_id": "evt_user_text",
  "content": "请查询雨伞库存。"
}

response.item.create

在 Responses 模式中添加后台输入。随后发送 response.create 启动生成。

typestring必填

事件类型,固定为 response.item.create。

event_idstring可选

客户端事件 ID。非空,最长 128 字符。

itemobject必填

后台输入。支持 message 和 function_call_output。

查看子字段

typestring必填

输入项类型。

rolestring按类型填写

消息发送者的角色。下方的用户文本示例使用 user。

contentarray按类型填写

用户消息内容。

查看子字段

typestring必填

文本输入填 input_text。

textstring必填

用户文本。

call_idstring

function_call_output 的函数调用 ID。使用后台事件返回的 call_id。

outputstring

function_call_output 的函数结果,格式为字符串。

输入文本

{
  "type": "response.item.create",
  "event_id": "evt_backend_item",
  "item": {
    "role": "user",
    "type": "message",
    "content": [
      {
        "type": "input_text",
        "text": "请查询雨伞库存。"
      }
    ]
  }
}

回传后台函数结果

{
  "type": "response.item.create",
  "event_id": "evt_backend_output",
  "item": {
    "type": "function_call_output",
    "call_id": "call_stock_001",
    "output": "{\"stock\":7}"
  }
}

response.create

应用通过此事件发起后台任务后,直接从 response.event 读取后台事件。只有前台模型自动委派任务时,服务才会发送 session.delegation.created。

typestring必填

事件类型,固定为 response.create。

event_idstring可选

客户端事件 ID。非空,最长 128 字符。

responseobject可选

传入后台生成配置。配置格式参见 Responses API。

{
  "type": "response.create",
  "event_id": "evt_backend_create"
}

session.close

结束会话。服务返回 session.closed。

typestring必填

事件类型,固定为 session.close。

event_idstring必填

客户端事件 ID。非空,最长 128 字符。

{
  "type": "session.close",
  "event_id": "evt_close"
}