本文介绍 Qwen-Omni-Realtime API 的服务端事件,包括工具调用(Function Calling)相关事件。
相关文档:实时(Qwen-Omni-Realtime)。
error
服务端返回的错误信息。
event_idstring本次事件唯一标识符。typestring事件类型,固定为error。errorobject错误的详细信息。
属性 type string错误类型。codestring错误码。messagestring错误信息。paramstring与错误相关的参数,如session.modalities。 |
session.created
客户端连接后,服务端返回的第一个事件,包含本次连接的默认配置信息。
event_idstring本次事件唯一标识符。typestring事件类型,固定为session.created。sessionobject会话的配置信息。
属性 object string固定为realtime.session。modelstring使用的模型。modalitiesarray模型输出模态设置。voicestring模型生成音频的音色。input_audio_formatstring用户输入音频的格式,当前仅支持设为pcm。输入音频要求为16 kHz采样率的PCM音频流。output_audio_formatstring模型输出音频的格式,当前仅支持设为pcm。输出音频为24 kHz采样率的PCM音频流。当前不支持自定义输出采样率。input_audio_transcriptionobject语音转录的配置。
属性 model string语音转录模型,固定为qwen3-asr-flash-realtime,不支持修改。object语音活动检测(VAD)的配置。
属性 type stringVAD类型。取值:server_vad(默认值)或 semantic_vad。详情请参见客户端事件。thresholdfloatVAD检测阈值。silence_duration_msinteger检测语音停止的静音持续时间。idle_timeout_msinteger静默超时时间(毫秒)。仅在 server_vad 模式下,使用 qwen3.5-omni-plus-realtime 或 qwen3.5-omni-flash-realtime 模型时返回。boolean是否启用联网搜索功能。仅 Qwen3.5-Omni-Realtime 系列模型支持。search_optionsobject联网搜索选项配置。temperaturefloat模型的温度参数。 |
session.updated
收到用户的 session.update 请求后,若处理成功,则返回此事件;若出错,则返回 error 事件。
event_idstring本次事件唯一标识符。typestring事件类型,固定为session.updated。sessionobject会话的配置信息。
属性 temperature float模型的温度参数。modalitiesarray模型输出模态设置。voicestring模型生成音频的音色。instructionsstring模型的目标与角色。audioobject回显的音频格式配置。若客户端传入了 session.audio.input.format / session.audio.output.format,服务端将在 session.updated 中按相同嵌套结构回显。未使用嵌套字段的客户端,服务端事件结构保持原有行为。
属性 audio.input.format.type string用户输入音频格式。可选值:pcm(默认值)、wav。audio.input.format.sample_rateinteger用户输入音频采样率,单位为 Hz。audio.output.format.typestring模型输出音频格式。可选值:pcm(默认值)、wav。audio.output.format.sample_rateinteger模型输出音频采样率,单位为 Hz。string历史兼容字段,回显客户端配置的输入音频格式。output_audio_formatstring历史兼容字段,回显客户端配置的输出音频格式。input_audio_transcriptionobject语音转录的配置。
属性 model string语音转录模型,固定为qwen3-asr-flash-realtime,不支持修改。object语音活动检测(VAD)的配置。
属性 type stringVAD类型。取值:server_vad(默认值)或 semantic_vad。详情请参见客户端事件。thresholdfloatVAD检测阈值。silence_duration_msinteger检测语音停止的静音持续时间。idle_timeout_msinteger静默超时时间(毫秒)。仅在 server_vad 模式下,使用 qwen3.5-omni-plus-realtime 或 qwen3.5-omni-flash-realtime 模型时返回。boolean(可选)是否启用联网搜索功能。仅 Qwen3.5-Omni-Realtime 系列模型支持。search_optionsobject(可选)联网搜索选项配置。toolsarray(可选)工具定义列表。配置后模型可根据用户输入自主决定是否调用工具。
属性 type string(必选)固定为 function。function.namestring(必选)自定义的工具函数名称,建议使用与函数相同的名称,如get_current_weather或get_current_time。function.descriptionstring(可选)对工具函数功能的描述,大模型会参考该字段来选择是否使用该工具函数。function.parametersobject(可选)对工具函数入参的描述,大模型会参考该字段来进行入参的提取。如果工具函数不需要输入参数,则无需指定。
属性 type string(必选)固定为 object。propertiesobject(可选)描述各入参的名称、数据类型与描述。Key 值为入参的名称,Value 值为包含数据类型(type)与描述(description)的对象。requiredarray(可选)指定哪些入参为必填项。float核采样的概率阈值。top_kinteger模型生成过程中,采样候选集的大小。max_tokensinteger模型在本次请求返回的最大 Token 数。repetition_penaltyfloat控制模型生成时,连续序列中的重复度*。*presence_penaltyfloat控制模型在生成内容时的重复度。seedinteger模型在每次请求时,运行结果一致性程度。 |
input_audio_buffer.speech_started
在 VAD 模式下,当服务端在音频缓冲区中检测到语音开始时,会返回此事件。
若服务端尚未检测到语音,则每次向缓冲区添加音频时都可能触发此事件。
event_idstring本次事件唯一标识符。typestring事件类型,固定为input_audio_buffer.speech_started。audio_start_msinteger从音频开始写入缓冲区到首次检测到语音所经过的毫秒数。item_idstring语音停止时将创建的用户消息项的 ID。用户消息项用于将用户输入追加到对话历史,供模型后续推理与生成使用。 |
input_audio_buffer.speech_stopped
在 VAD 模式下,当音频缓冲区中检测到语音结束时,服务端会返回此事件。
同时,服务端还会返回一个 conversation.item.created 事件,以创建对应的用户消息项。
event_idstring本次事件唯一标识符。typestring事件类型,固定为input_audio_buffer.speech_stopped。audio_end_msinteger语音停止时刻距会话开始经过的毫秒数。item_idstring将创建的用户消息项的 ID。 |
input_audio_buffer.committed
当输入音频缓冲区被提交时返回此事件。
- 在VAD模式下,当检测到用户说话结束时,服务端会自动提交音频缓冲区并返回此事件。
- 在 Manual 模式下,当客户端发送
input_audio_buffer.commit事件后,服务端返回此事件。
event_idstring本次事件唯一标识符。typestring事件类型,固定为input_audio_buffer.committed。item_idstring将创建的用户消息项的 ID。 |
input_audio_buffer.cleared
客户端发送input_audio_buffer.clear事件后,服务端将返回此事件。
event_idstring本次事件唯一标识符。typestring事件类型,固定为input_audio_buffer.cleared。 |
conversation.item.created
当对话项创建时返回此事件。
event_idstring本次事件唯一标识符。typestring事件类型,固定为conversation.item.created。itemobject要添加到对话中的项。
属性 id string对话项的唯一ID。objectstring始终为 realtime.item 。statusstring对话项的状态。rolestring消息的角色。contentstring消息的内容。当 type 为 message 时存在。typestring对话项的类型。可选值为 message(常规消息)或 function_call(工具调用)。namestring当 type 为 function_call 时,被调用的函数名称。call_idstring当 type 为 function_call 时,本次函数调用的唯一 ID。argumentsstring当 type 为 function_call 时,函数调用的参数(JSON 字符串)。 |
conversation.item.input_audio_transcription.delta
开启输入音频转录后,此事件会在用户说话过程中高频发送,用于展示实时识别的中间结果。您可以通过拼接 text + stash 获取当前最完整的句子预览。
event_idstring本次事件唯一标识符。typestring事件类型,固定为conversation.item.input_audio_transcription.delta。item_idstring关联的对话项 ID。content_indexinteger包含音频的内容部分的索引。textstring已确认的文本前缀。这是当前句子中,模型已确认不会再变更的部分。stashstring预识别的文本后缀。这是紧跟在已确认部分之后,模型仍在处理、可能会被修正的临时草稿。languagestring被识别音频的语种。emotionstring被识别音频的情感。可选值:neutral(平静)、happy(愉快)、sad(悲伤)、angry(愤怒)、surprised(惊讶)、disgusted(厌恶)、fearful(恐惧)。 | text + stash。
点击查看示例 假设用户正在说:"今天天气不错,阳光明媚。"以下是您可能会收到的事件流以及如何解读它们:
|
conversation.item.input_audio_transcription.completed
此事件表示用户音频写入缓冲区后生成的转录结果。其转录由内置的语音识别模型(固定为 qwen3-asr-flash-realtime)处理,不支持修改。
语音识别模型生成的转录文本可能与 Qwen-Omni-Realtime 模型的理解存在差异,仅供参考。
event_idstring本次事件唯一标识符。typestring事件类型,固定为conversation.item.input_audio_transcription.completed。item_idstring用户消息项的 ID。content_indexinteger当前固定为0。transcriptstring转录的文本内容。 |
conversation.item.input_audio_transcription.failed
启用输入音频转录后,若用户音频转录失败,服务端会返回此事件。此事件独立于 error 事件,便于客户端识别。
event_idstring本次事件唯一标识符。typestring事件类型,固定为conversation.item.input_audio_transcription.failed。item_idstring用户消息项的 ID。content_indexinteger当前固定为0。errorobject错误信息。
属性 code string错误码。message string错误消息。param string错误相关的参数。 |
response.created
当服务端生成新的模型响应时,会返回此事件。
event_idstring本次事件唯一标识符。typestring事件类型,固定为response.created。responseobject响应对象。
属性 id string响应的唯一 ID。conversation_id string当前会话的唯一ID。object string对象类型,此事件下固定为realtime.response。status string响应的状态。在[completed, failed, in_progress, or incomplete]范围内。modalities array响应的模态。voice string模型生成音频的音色。output string此事件下目前为空。 |
response.done
响应生成完成后,服务端会返回此事件。事件中的 response 对象包含除原始音频数据外的全部输出项。
event_idstring本次事件唯一标识符。typestring事件类型,固定为response.done。responseobject响应对象。
属性 id string响应的唯一 ID。conversation_id string当前会话的唯一ID。object string对象类型,此事件下固定为realtime.response。status string响应的状态。modalities array响应的模态。voice string模型生成音频的音色。output object响应的输出。
属性 id string响应输出对应的ID。type string输出项的类型,可选值为 message(常规消息)或 function_call(工具调用)。object string输出项的对象类型,当前固定为realtime.item。status string输出项的状态。role string输出项的角色。content array输出项的内容。当 type 为 message 时存在。
属性 type string输出内容的类型。输出为纯文本时,为text;输出包含音频时,为audio。text string输出的文本内容。transcript string音频转录为文字后的内容。string当 type 为 function_call 时,被调用的函数名称。call_id string当 type 为 function_call 时,函数调用的唯一 ID。arguments string当 type 为 function_call 时,函数调用的完整参数(JSON 字符串)。object本次响应的 Token 消耗信息。
属性 total_tokens integer本次响应消耗的总 Token 数。input_tokens integer输入 Token 数。output_tokens integer输出 Token 数。input_tokens_details object输入 Token 的分项详情,包含 text_tokens(文本 Token 数)和 audio_tokens(音频 Token 数)。output_tokens_details object输出 Token 的分项详情,包含 text_tokens(文本 Token 数)和 audio_tokens(音频 Token 数)。plugins object(可选)插件使用计量信息。启用联网搜索(enable_search)时返回。
属性 search object联网搜索计量信息。
属性 count integer搜索次数。strategy string搜索策略。 |
response.text.delta
当输出模态仅包含文本,且模型增量生成新的文本时,服务端将返回此事件。
event_idstring本次事件唯一标识符。typestring事件类型,固定为response.text.delta。deltastring返回的增量文本。response_idstring回复的ID。item_idstring消息项ID,可以关联同一个消息项。output_indexinteger响应中输出项的索引, 目前固定为 0。content_indexinteger响应中输出项中内部部分的索引, 目前固定为 0。 |
response.text.done
当输出模态仅包含文本,且模型生成的文本结束时,服务端将返回此事件。
当响应中断、不完整或取消时,也会返回此事件。
event_idstring本次事件唯一标识符。typestring事件类型,固定为response.text.done。response_idstring响应的ID。item_idstring消息项ID。output_indexinteger响应输出项的索引。content_indexinteger响应输出项的索引。text string模型输出的完整文本。 |
response.audio.delta
当输出模态包含音频,且模型增量生成新的音频数据时,服务端将返回此事件。
event_idstring本次事件唯一标识符。typestring事件类型,固定为response.audio.delta。response_idstring响应的ID。item_idstring消息项ID。output_indexinteger响应输出项的索引。content_indexinteger响应输出项的索引。delta string模型增量输出的音频数据,使用Base64编码。 |
response.audio.done
当输出模态包含音频,且模型完成生成音频数据时,服务端将返回此事件。
当响应中断、不完整或取消时,也会返回此事件。
event_idstring本次事件唯一标识符。typestring事件类型,固定为response.audio.done。response_idstring响应的ID。item_idstring消息项ID。output_indexinteger响应输出项的索引。content_indexinteger响应输出项的索引。 |
response.audio_transcript.delta
当输出模态包含音频,且模型增量生成新的音频对应的文本时,服务端将返回 response.audio_transcript.delta 事件。
event_idstring本次事件唯一标识符。typestring事件类型,固定为response.audio_transcript.delta。response_idstring响应的ID。item_idstring消息项ID。output_indexinteger响应输出项的索引。content_indexinteger响应输出项的索引。deltastring增量文本。 |
response.audio_transcript.done
当输出模态包含音频,且模型完成音频转录后,服务端将返回 response.audio_transcript.done 事件。
event_idstring本次事件唯一标识符。typestring事件类型,固定为response.audio_transcript.done。response_idstring响应的ID。item_idstring消息项ID。output_indexinteger响应输出项的索引。content_indexinteger响应输出项的索引。transcriptstring完整文本。 |
response.function_call_arguments.delta
当模型以流式方式生成函数调用的参数字符串时,每产生一段新内容,服务端推送一次本事件。客户端应按接收顺序将各事件中的 delta 字段拼接,得到与当前进度一致的参数文本;完整内容以随后的 response.function_call_arguments.done 为准。
event_idstring本次事件唯一标识符。typestring事件类型,固定为response.function_call_arguments.delta。response_idstring响应的ID。item_idstring消息项ID。output_indexinteger该响应中输出项的索引。call_idstring本次函数调用的唯一 ID,与同一轮中的 done 事件保持一致。deltastring本段新增的参数字符串片段(增量)。需按顺序拼接。 |
response.function_call_arguments.done
函数调用参数已全部生成完毕。本事件中的 arguments 为完整的参数字符串。客户端可在收到本事件后解析参数并调用本地工具函数;应以本事件中的完整 arguments 为准,而非 delta 拼接结果。
event_idstring本次事件唯一标识符。typestring事件类型,固定为response.function_call_arguments.done。response_idstring响应的ID。item_idstring消息项ID。output_indexinteger该响应中输出项的索引。call_idstring本次函数调用的唯一 ID。namestring被调用的函数名称。argumentsstring函数调用的完整参数,一般以 JSON 字符串形式表示。 |
response.output_item.added
在响应生成过程中创建新项目时,服务端返回此事件。项目类型可以是 message(常规消息)或 function_call(工具调用)。
event_idstring本次事件唯一标识符。typestring事件类型,固定为response.output_item.added。response_idstring响应的ID。output_indexinteger响应输出项的索引。itemobject输出项信息。
属性 id string输出项的唯一ID。objectstring始终为 realtime.item 。statusstring输出项的状态。rolestring发送消息的角色。contentstring消息的内容。当 type 为 message 时存在。typestring输出项的类型。可选值为 message(常规消息)或 function_call(工具调用)。namestring当 type 为 function_call 时,被调用的函数名称。call_idstring当 type 为 function_call 时,本次函数调用的唯一 ID。argumentsstring当 type 为 function_call 时,函数调用的参数(JSON 字符串)。在 added 事件中初始为空字符串。 |
response.output_item.done
当新的项目输出完成时,服务端返回此事件。
event_idstring本次事件唯一标识符。typestring事件类型,固定为response.output_item.done。response_idstring响应的ID。output_indexinteger响应输出项的索引。itemobject输出项信息。
属性 id string输出项的唯一ID。objectstring始终为 realtime.item 。statusstring输出项的状态。rolestring发送消息的角色。contentstring消息的内容。当 type 为 message 时存在。typestring输出项的类型。可选值为 message(常规消息)或 function_call(工具调用)。namestring当 type 为 function_call 时,被调用的函数名称。call_idstring当 type 为 function_call 时,本次函数调用的唯一 ID。argumentsstring当 type 为 function_call 时,函数调用的完整参数(JSON 字符串)。 |
response.content_part.added
在响应生成过程中,向助手消息项中添加新内容部分时,服务端返回此事件。
event_idstring本次事件唯一标识符。typestring事件类型,固定为response.content_part.added。response_idstring响应的ID。item_idstring消息项ID。output_indexinteger响应输出项的索引,目前固定为 0。content_indexinteger响应输出项中内部部分的索引, 目前固定为 0。partobject输出项信息。
属性 type string内容部分的类型。textstring内容部分的文本。 |
response.content_part.done
在助手消息项中的内容部分完成流式传输时,服务端返回此事件。
event_idstring本次事件唯一标识符。typestring事件类型,固定为response.content_part.done。response_idstring响应的ID。item_idstring消息项ID。output_indexinteger响应输出项的索引,目前固定为 0。content_indexinteger该项内容数组中内容部分的索引,目前固定为 0。partobject输出项信息。
属性 type string内容部分的类型。textstring内容部分的文本。 |