更新 readme

This commit is contained in:
2026-04-18 11:42:08 +08:00
parent 1ad70525c1
commit 3f84c111d9
4 changed files with 730 additions and 833 deletions
+100
View File
@@ -0,0 +1,100 @@
本文介绍 Qwen-Omni-Realtime API 的客户端事件。
> 相关文档:[实时(Qwen-Omni-Realtime)](https://help.aliyun.com/zh/model-studio/realtime)。
## **session.update**
客户端建立 WebSocket 连接后,需首先发送该事件,用于更新会话的默认配置。服务端收到 `session.update` 事件后会校验参数。如果参数不合法,则返回错误;如果参数合法,则更新并返回完整的配置。
| **type** `*string*` **(必选)** 事件类型,固定为`session.update`。 | ``` { "event_id": "event_ToPZqeobitzUJnt3QqtWg", "type": "session.update", "session": { "modalities": [ "text", "audio" ], "voice": "Chelsie", "input_audio_format": "pcm", "output_audio_format": "pcm", "instructions": "你是某五星级酒店的AI客服专员,请准确且友好地解答客户关于房型、设施、价格、预订政策的咨询。请始终以专业和乐于助人的态度回应,杜绝提供未经证实或超出酒店服务范围的信息。", "turn_detection": { "type": "server_vad", "threshold": 0.5, "silence_duration_ms": 800 }, "enable_search": true, "search_options": { "enable_source": true }, "tools": [ { "type": "function", "function": { "name": "get_current_weather", "description": "当你想查询指定城市的天气时非常有用。", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "城市或县区,比如北京市、杭州市、余杭区等。" } }, "required": ["location"] } } } ], "seed": 1314, "max_tokens": 16384, "repetition_penalty": 1.05, "presence_penalty": 0.0, "top_k": 50, "top_p": 1.0, "temperature": 0.9 } } ``` |
| --- | --- |
| **session** `*object*` (可选) 会话配置。 **属性** **modalities** `*array*` (可选) 模型输出模态设置,可选值: - \\["text"\\] 仅输出文本。 - \\["text","audio"\\](默认值) 输出文本与音频。 **voice** `*string*` (可选) 模型生成音频的音色,支持的音色参见[音色列表](https://help.aliyun.com/zh/model-studio/realtime#f9c68d860a3rs)。 默认音色: - Qwen3.5-Omni-Realtime系列:`Tina` - Qwen3-Omni-Flash-Realtime:`Cherry` - Qwen-Omni-Turbo-Realtime:`Chelsie` **input\\_audio\\_format** `*string*` (可选) 用户输入音频格式,当前仅支持设为`pcm`。 **output\\_audio\\_format** `*string*` (可选) 模型输出音频的格式,当前仅支持设为`pcm`。 **instructions** `*string*` (可选) 系统消息,用于设定模型的目标或角色。 **turn\\_detection** `*object*` (可选) 语音活动检测(VAD)的配置。设置为 `null` 表示禁用 VAD,由用户手动触发模型响应。若未提供本字段,系统将使用以下默认参数启用 VAD。 **属性** **type** `*string*` (可选) VAD类型,取值如下: - `server_vad`(默认值):基于声学特征检测用户语音结束。 - `semantic_vad`:基于语义有效性检测用户语音结束,可过滤无意义语音(如回应语、背景音)。仅`qwen3.5-omni-realtime`模型支持。 **threshold** `*float*` (可选) VAD的灵敏度。值越低,VAD越敏感,更容易将微弱声音(包括背景噪音)识别为语音;值越高,越不敏感,需要更清晰、音量更大的语音才能触发。 取值范围在`[-1.0, 1.0]`,默认值为 0.5。 **silence\\_duration\\_ms** `*integer*` (可选) 语音结束后需保持静音的最短时间,超时即触发模型响应。值越低,响应越快,但可能在语音短暂停顿时误触发模型响应。 默认值为800,参数范围\\[200, 6000\\]。 **enable\\_search** `*boolean*` (可选) **仅在使用 Qwen3.5-Omni-Realtime 模型时生效。** 是否启用联网搜索功能。设置为 `true` 启用,默认为 `false`。启用后,模型可自主判断是否需要搜索来回应用户的即时问题。 > 工具调用(tools)和联网搜索(enable\\_search)不兼容,不可同时开启。 **search\\_options** `*object*` (可选) 联网搜索选项配置。需启用 `enable_search` 后才生效。 **属性** **enable\\_source** `*boolean*` (可选) 是否返回搜索结果来源列表。设置为 `true` 启用。 **tools** `*array*` (可选) 工具定义列表。配置后模型可根据用户输入自主决定是否调用工具。 **属性** **type** `*string*`(必选) 固定为 `function`。 **function.name** `*string*`(必选) 自定义的工具函数名称,建议使用与函数相同的名称,如`get_current_weather`或`get_current_time`。 **function.description** `*string*`(可选) 对工具函数功能的描述,大模型会参考该字段来选择是否使用该工具函数。 **function.parameters** `*object*`(可选) 对工具函数入参的描述,大模型会参考该字段来进行入参的提取。如果工具函数不需要输入参数,则无需指定。 **属性** **type** `*string*`(必选) 固定为 `object`。 **properties** `*object*`(可选) 描述各入参的名称、数据类型与描述。Key 值为入参的名称,Value 值为包含数据类型(`type`)与描述(`description`)的对象。 **required** `*array*`(可选) 指定哪些入参为必填项。 |
| **temperature** `*float*` (可选) 采样温度,控制模型生成内容的多样性。 temperature越高,生成的内容更多样,反之,生成的内容更确定。 取值范围: \\[0, 2) 由于temperature与top\\_p均可以控制生成内容的多样性,因此建议您只设置其中一个值。 temperature默认值: - `qwen3.5-omni-realtime`系列:0.7 - `qwen3-omni-flash-realtime`系列:0.9 - `qwen-omni-turbo-realtime`系列:1.0 > `qwen-omni-turbo` 系列模型**不支持修改**。 |
| **top\\_p** `*float*` (可选) 核采样的概率阈值,控制模型生成内容的多样性。 top\\_p越高,生成的内容更多样。反之,生成的内容更确定。 取值范围:(0,1.0\\] 由于temperature与top\\_p均可以控制生成内容的多样性,因此建议您只设置其中一个值。 top\\_p默认值: - `qwen3.5-omni-realtime`系列:0.8 - `qwen3-omni-flash-realtime`系列:1.0 - `qwen-omni-turbo-realtime`系列:0.01 > `qwen-omni-turbo` 系列模型**不支持修改**。 |
| **top\\_k** `*integer*` (可选) 生成过程中采样候选集的大小。例如,取值为50时,仅将单次生成中得分最高的50个Token组成随机采样的候选集。取值越大,生成的随机性越高;取值越小,生成的确定性越高。取值为`null`或当top\\_k大于100时,表示不启用`top_k`策略,此时仅有`top_p`策略生效。 取值需要大于或等于0。 top\\_k默认值: - `qwen3.5-omni-realtime`系列:20 - `qwen3-omni-flash-realtime`系列:50 - `qwen-omni-turbo-realtime`系列:20 > `qwen-omni-turbo` 系列模型**不支持修改**。 |
| **max\\_tokens** `*integer*` (可选) 本次请求返回的最大 Token 数。 > `max_tokens` 的设置不会影响大模型的生成过程,如果模型生成的 Token 数超过`max_tokens`,本次请求会返回截断后的内容。 默认值和最大值都是模型的最大输出长度。关于各模型的最大输出长度,请参见[模型列表](https://help.aliyun.com/zh/model-studio/models#9f8890ce29g5u)。 max\\_tokens参数适用于需要限制字数(如生成摘要、关键词)、控制成本或减少响应时间的场景。 > `qwen-omni-turbo` 系列模型**不支持修改**。 |
| **repetition\\_penalty** `*float*` (可选) 模型生成时连续序列中的重复度。提高repetition\\_penalty时可以降低模型生成的重复度,1.0表示不做惩罚。没有严格的取值范围,只要大于0即可。 repetition\\_penalty默认值: - `qwen3.5-omni-realtime`系列:1.0 - `qwen3-omni-flash-realtime`系列:1.05 - `qwen-omni-turbo-realtime`系列:1.05 > `qwen-omni-turbo` 系列模型**不支持修改**。 |
| **presence\\_penalty** `*float*` (可选) 控制模型生成内容时的重复度。 取值范围:\\[-2.0, 2.0\\]。正数会减少重复度,负数会增加重复度。 presence\\_penalty默认值: - `qwen3.5-omni-realtime`系列:1.5 - `qwen3-omni-flash-realtime`系列:0.0 - `qwen-omni-turbo-realtime`系列:0.0 适用场景: 较高的presence\\_penalty适用于要求多样性、趣味性或创造性的场景,如创意写作或头脑风暴。 较低的presence\\_penalty适用于要求一致性或专业术语的场景,如技术文档或其他正式文档。 > `qwen-omni-turbo` 系列模型**不支持修改**。 |
| **seed** `*integer*` (可选) 设置seed参数会使大模型的生成过程更具有确定性,通常用于使模型每次运行的结果一致。 在每次模型调用时传入相同的seed值(由您指定),并保持其他参数不变,模型将尽可能返回相同的结果。 取值范围:0到231−1,默认值-1。 > `qwen-omni-turbo` 系列模型**不支持修改**。 |
## **response.create**
`response.create` 事件用于指示服务端创建模型响应。在VAD模式下,服务端会自动创建模型响应,无需发送该事件。在工具调用场景中,客户端通过 `conversation.item.create` 回传工具结果后,需发送此事件触发模型生成最终响应。
服务端使用 `response.created` 事件、一个或多个项和内容事件(如 `conversation.item.created` 和 `response.content_part.added`)进行响应,最后用一个 `response.done` 事件表示响应已完成。
| **type** `*string*` **(必选)** 事件类型,固定为`response.create`。 | ``` { "type": "response.create", "event_id": "event_1718624400000" } ``` |
| --- | --- |
## **response.cancel**
客户端发送此事件用以取消正在进行的响应。如果没有任何响应可供取消,服务端将响应错误事件。
| **type** `*string*` **(必选)** 事件类型,固定为`response.cancel`。 | ``` { "event_id": "event_B4o9RHSTWobB5OQdEHLTo", "type": "response.cancel" } ``` |
| --- | --- |
## **input\_audio\_buffer.append**
用于将音频字节追加到输入音频缓冲区。
| **type** `*string*` **(必选)** 事件类型,固定为`input_audio_buffer.append`。 | ``` { "event_id": "event_B4o9RHSTWobB5OQdEHLTo", "type": "input_audio_buffer.append", "audio": "UklGR..." } ``` |
| --- | --- |
| **audio** `*string*` **(必选)** Base64 编码的音频数据。 |
## **input\_audio\_buffer.commit**
用于提交用户输入音频缓冲区,在对话中创建新的用户消息项。 如果输入的音频缓冲区为空,服务端会返回错误事件。
- [VAD 模式](https://help.aliyun.com/zh/model-studio/realtime#68d826b358q1r):客户端不需要发送此事件,服务端会自动提交音频缓冲区。
- [Manual 模式](https://help.aliyun.com/zh/model-studio/realtime#3dbb650fb3ird):客户端必须提交音频缓冲区才能创建用户消息项。
提交输入音频缓冲区不会从模型创建响应,服务端将使用 `input_audio_buffer.committed` 事件进行响应。
> 如果客户端发送过[input\_image\_buffer.append](#c28ed38410nfw)事件,input\_audio\_buffer.commit 事件会将图像缓冲区一起提交。
| **type** `*string*` **(必选)** 事件类型,固定为`input_audio_buffer.commit`。 | ``` { "event_id": "event_B4o9RHSTWobB5OQdEHLTo", "type": "input_audio_buffer.commit" } ``` |
| --- | --- |
## **input\_audio\_buffer.clear**
用于清除缓冲区中的音频字节。服务端发送`input_audio_buffer.cleared` 事件进行响应。
| **type** `*string*` **(必选)** 事件类型,固定为`input_audio_buffer.clear`。 | ``` { "event_id": "event_xxx", "type": "input_audio_buffer.clear" } ``` |
| --- | --- |
## **input\_image\_buffer.append**
用于将图像数据添加到图像缓冲区。图像可来自本地文件,或从视频流实时采集。
目前对图片输入有以下限制:
- 图像格式必须为 JPG 或 JPEG。建议分辨率为 480p 或 720p以获得最佳性能,最高不超过 1080p;
- 单张图片大小不大于500KB(Base64编码前);
- 图片数据需要经过Base64编码;
- 建议以 1张/秒 的频率向服务端发送图像;
- 发送 input\_image\_buffer.append 事件前,至少发送过一次 input\_audio\_buffer.append 事件。
> 图像缓冲区与音频缓冲区一起通过[input\_audio\_buffer.commit](#1cbea5fa7fkfl)事件提交。
| **type** `*string*` **(必选)** 事件类型,固定为`input_image_buffer.append`。 | ``` { "event_id": "event_xxx", "type": "input_image_buffer.append", "image": "xxx" } ``` |
| --- | --- |
| **image** `*string*` **(必选)** Base64 编码的图像数据。 |
## **conversation.item.create**
客户端发送此事件,将工具函数的执行结果回传给服务端。当模型触发工具调用后,客户端需在本地执行工具函数,然后通过此事件将结果发回,再发送 `response.create` 触发模型生成最终响应。
**说明**
当前仅支持 `function_call_output` 类型的 item。
| **type** `*string*` **(必选)** 事件类型,固定为`conversation.item.create`。 | ``` { "event_id": "event_55099cddb51b4f208cb95d1a994eef80", "type": "conversation.item.create", "item": { "id": "item_2a80d7682b4e473c9c2154da135041e9", "type": "function_call_output", "call_id": "call_62c24725afdb4c2680ac54", "output": "北京今天天气为霾转晴,气温4/-4℃,微风" } } ``` |
| --- | --- |
| **item** `*object*` **(必选)** 要创建的对话项,不能为空。 **属性** **id** `*string*`(可选) 对话项 ID。客户端可预先指定以便对齐本地状态;若未提供,由服务端生成。 **type** `*string*`(必选) 对话项类型。当前仅支持 `function_call_output`。 **call\\_id** `*string*`(必选) 对应 `response.function_call_arguments.done` 事件中返回的 `call_id`。 **output** `*string*`(必选) 工具函数的执行结果。 |
+283
View File
@@ -0,0 +1,283 @@
本文介绍 Qwen-Omni-Realtime API 的服务端事件,包括工具调用(Function Calling)相关事件。
> 相关文档:[实时(Qwen-Omni-Realtime)](https://help.aliyun.com/zh/model-studio/realtime)。
## **error**
服务端返回的错误信息。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_RoUu4T8yExPMI37GKwaOC", "type": "error", "error": { "type": "invalid_request_error", "code": "invalid_value", "message": "Invalid modalities: ['audio']. Supported combinations are: ['text'] and ['audio', 'text'].", "param": "session.modalities" } } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`error`。 |
| **error** `*object*` 错误的详细信息。 **属性** **type** `*string*` 错误类型。 **code** `*string*` 错误码。 **message** `*string*` 错误信息。 **param** `*string*` 与错误相关的参数,如`session.modalities`。 |
## **session.created**
客户端连接后,服务端返回的第一个事件,包含本次连接的默认配置信息。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_RdvlSpbBb2ssyBjYrDHjt", "type": "session.created", "session": { "object": "realtime.session", "model": "qwen3-omni-flash-realtime", "modalities": [ "text", "audio" ], "voice": "Cherry", "input_audio_format": "pcm", "output_audio_format": "pcm", "input_audio_transcription": { "model": "gummy-realtime-v1" }, "turn_detection": { // 取值为server_vad或semantic_vad(仅qwen3.5-omni-realtime支持) "type": "server_vad", "threshold": 0.5, "prefix_padding_ms": 300, "silence_duration_ms": 800, "create_response": true, "interrupt_response": true }, "enable_search": false, "search_options": {}, "tools": [], "temperature": 0.8, "id": "sess_Ov7GOXoNXhNjlxXtOGKQS" } } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`session.created`。 |
| **session** `*object*` 会话的配置信息。 **属性** **object** `*string*` 固定为`realtime.session`。 **model** `*string*` 使用的模型。 **modalities** `*array*` 模型输出模态设置。 **voice** `*string*` 模型生成音频的音色。 **input\\_audio\\_format** `*string*` 输入音频的格式,固定为`pcm`。 **output\\_audio\\_format** `*string*` 模型输出音频的格式,固定为`pcm`。 **input\\_audio\\_transcription** `*object*` 语音转录的配置。 **属性** **model** `*string*` 语音转录模型,固定为`gummy-realtime-v1`。 **turn\\_detection** `*object*` 语音活动检测(VAD)的配置。 **属性** **type** `*string*` VAD类型。取值:`server_vad`(默认值)或 `semantic_vad`。详情请参见[客户端事件](https://help.aliyun.com/zh/model-studio/client-events#7c8172272codm)。 **threshold** `*float*` VAD检测阈值。 **silence\\_duration\\_ms** `*integer*` 检测语音停止的静音持续时间。 **enable\\_search** `*boolean*` 是否启用联网搜索功能。仅 Qwen3.5-Omni-Realtime 模型支持。 **search\\_options** `*object*` 联网搜索选项配置。 **temperature** `*float*` 模型的温度参数。 |
## **session.updated**
收到用户的 `session.update` 请求后,若处理成功,则返回此事件;若出错,则返回 `error` 事件。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_X1HsXS4b4uptp6yo1LgKd", "type": "session.updated", "session": { "id": "sess_Aih6vAcY5Ddt6jwFx1tCa", "object": "realtime.session", "model": "qwen3-omni-flash-realtime", "modalities": [ "text", "audio" ], "instructions": "你是个人助理小云,请你准确且友好地解答用户的问题,始终以乐于助人的态度回应。", "voice": "Cherry", "input_audio_format": "pcm", "output_audio_format": "pcm", "input_audio_transcription": { "model": "gummy-realtime-v1" }, "turn_detection": { // 取值为server_vad或semantic_vad(仅qwen3.5-omni-realtime支持) "type": "server_vad", "threshold": 0.1, "prefix_padding_ms": 500, "silence_duration_ms": 900, "create_response": true, "interrupt_response": true }, "enable_search": true, "search_options": { "enable_source": true }, "tools": [ { "type": "function", "function": { "name": "get_current_weather", "description": "当你想查询指定城市的天气时非常有用。", "parameters": { "type": "object", "properties": { "location": {"type": "string", "description": "城市名称"} }, "required": ["location"] } } } ], "temperature": 0.8, "max_response_output_token": "inf", "max_tokens": 16384, "repetition_penalty": 1.05, "presence_penalty": 0.0, "top_k": 50, "top_p": 1.0, "seed":-1 } } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`session.updated`。 |
| **session** `*object*` 会话的配置信息。 **属性** **temperature** `*float*` 模型的温度参数。 **modalities** `*array*` 模型输出模态设置。 **voice** `*string*` 模型生成音频的音色。 **instructions** `*string*` 模型的目标与角色。 **input\\_audio\\_format** `*string*` 输入音频的格式,当前仅支持设置为`pcm`。 **output\\_audio\\_format** `*string*` 输出音频的格式,当前仅支持设置为`pcm`。 **input\\_audio\\_transcription** `*object*` 语音转录的配置。 **属性** **model** `*string*` 语音转录模型,固定为`gummy-realtime-v1`。 **turn\\_detection** `*object*` 语音活动检测(VAD)的配置。 **属性** **type** `*string*` VAD类型。取值:`server_vad`(默认值)或 `semantic_vad`。详情请参见[客户端事件](https://help.aliyun.com/zh/model-studio/client-events#7c8172272codm)。 **threshold** `*float*` VAD检测阈值。 **silence\\_duration\\_ms** `*integer*` 检测语音停止的静音持续时间。 **enable\\_search** `*boolean*`(可选) 是否启用联网搜索功能。仅 Qwen3.5-Omni-Realtime 模型支持。 **search\\_options** `*object*`(可选) 联网搜索选项配置。 **tools** `*array*`(可选) 工具定义列表。配置后模型可根据用户输入自主决定是否调用工具。 **属性** **type** `*string*`(必选) 固定为 `function`。 **function.name** `*string*`(必选) 自定义的工具函数名称,建议使用与函数相同的名称,如`get_current_weather`或`get_current_time`。 **function.description** `*string*`(可选) 对工具函数功能的描述,大模型会参考该字段来选择是否使用该工具函数。 **function.parameters** `*object*`(可选) 对工具函数入参的描述,大模型会参考该字段来进行入参的提取。如果工具函数不需要输入参数,则无需指定。 **属性** **type** `*string*`(必选) 固定为 `object`。 **properties** `*object*`(可选) 描述各入参的名称、数据类型与描述。Key 值为入参的名称,Value 值为包含数据类型(`type`)与描述(`description`)的对象。 **required** `*array*`(可选) 指定哪些入参为必填项。 **top\\_p**`*float*` 核采样的概率阈值。 **top\\_k** `*integer*` 模型生成过程中,采样候选集的大小。 **max\\_tokens** `*integer*` 模型在本次请求返回的最大 Token 数。 **repetition\\_penalty** `*float*` 控制模型生成时,连续序列中的重复度*。* **presence\\_penalty** `*float*` 控制模型在生成内容时的重复度。 **seed** `*integer*` 模型在每次请求时,运行结果一致性程度。 |
## **input\_audio\_buffer.speech\_started**
在 VAD 模式下,当服务端在音频缓冲区中检测到语音开始时,会返回此事件。
> 若服务端尚未检测到语音,则每次向缓冲区添加音频时都可能触发此事件。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_Pvp8nEhsQuGCQbFJ9x58n", "type": "input_audio_buffer.speech_started", "audio_start_ms": 3647, "item_id": "item_YbAiGvK2H7YaS34o4R6Ba" } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`input_audio_buffer.speech_started`。 |
| **audio\\_start\\_ms** `*integer*` 从音频开始写入缓冲区到首次检测到语音所经过的毫秒数。 |
| **item\\_id** `*string*` 语音停止时将创建的用户消息项的 ID。 > 用户消息项用于将用户输入追加到对话历史,供模型后续推理与生成使用。 |
## **input\_audio\_buffer.speech\_stopped**
在 VAD 模式下,当音频缓冲区中检测到语音结束时,服务端会返回此事件。
同时,服务端还会返回一个 `conversation.item.created` 事件,以创建对应的用户消息项。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_UhQiqNVRsgUiq4KUS5Xb5", "type": "input_audio_buffer.speech_stopped", "audio_end_ms": 4453, "item_id": "item_YbAiGvK2H7YaS34o4R6Ba" } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`input_audio_buffer.speech_stopped`。 |
| **audio\\_end\\_ms** `*integer*` 语音停止时刻距会话开始经过的毫秒数。 |
| **item\\_id** `*string*` 将创建的用户消息项的 ID。 |
## **input\_audio\_buffer.committed**
当输入音频缓冲区被提交时返回此事件。
- 在VAD模式下,当检测到用户说话结束时,服务端会自动提交音频缓冲区并返回此事件。
- 在 Manual 模式下,当客户端发送`input_audio_buffer.commit`事件后,服务端返回此事件。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_Iy6sUzL1nmdFgshFYxJEz", "type": "input_audio_buffer.committed", "item_id": "item_YbAiGvK2H7YaS34o4R6Ba" } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`input_audio_buffer.committed`。 |
| **item\\_id** `*string*` 将创建的用户消息项的 ID。 |
## **input\_audio\_buffer.cleared**
客户端发送`input_audio_buffer.clear`事件后,服务端将返回此事件。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_RoUu4T8yExPMI37GKwaOC", "type": "input_audio_buffer.cleared" } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`input_audio_buffer.cleared`。 |
## **conversation.item.created**
当对话项创建时返回此事件。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_JEfkrr9gO3Ny7Xcv9bGVd", "type": "conversation.item.created", "item": { "id": "item_YbAiGvK2H7YaS34o4R6Ba", "object": "realtime.item", "type": "message", "status": "in_progress", "role": "assistant", "content": [ { "type": "input_audio" } ] } } // 工具调用场景 { "event_id": "event_S1hkaIQgcuQD8OEdOpGHQ", "type": "conversation.item.created", "item": { "id": "item_FEG9qJGNkPcdf4et3p7BV", "object": "realtime.item", "type": "function_call", "status": "in_progress", "call_id": "call_bc0a7fb7235840f69ecfe4", "name": "get_current_weather", "arguments": "" } } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`conversation.item.created`。 |
| **item** `*object*` 要添加到对话中的项。 **属性** **id** `*string*` 对话项的唯一ID。 **object** `*string*` 始终为 `realtime.item` 。 **status** `*string*` 对话项的状态。 **role** `*string*` 消息的角色。 **content** `*string*` 消息的内容。当 type 为 `message` 时存在。 **type** `*string*` 对话项的类型。可选值为 `message`(常规消息)或 `function_call`(工具调用)。 **name** `*string*` 当 type 为 `function_call` 时,被调用的函数名称。 **call\\_id** `*string*` 当 type 为 `function_call` 时,本次函数调用的唯一 ID。 **arguments** `*string*` 当 type 为 `function_call` 时,函数调用的参数(JSON 字符串)。 |
## **conversation.item.input\_audio\_transcription.completed**
此事件表示用户音频写入缓冲区后生成的转录结果。其转录由独立的语音识别模型(当前固定为 `gummy-realtime-v1`)处理。
> 语音识别模型生成的转录文本可能与 Qwen-Omni-Realtime 模型的理解存在差异,仅供参考。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_FrrZcxiDfTB9LD9p4pVng", "type": "conversation.item.input_audio_transcription.completed", "item_id": "item_YbAiGvK2H7YaS34o4R6Ba", "content_index": 0, "transcript": "喂,你好。" } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`conversation.item.input_audio_transcription.completed`。 |
| **item\\_id** `*string*` 用户消息项的 ID。 |
| **content\\_index** *integer* 当前固定为0。 |
| **transcript** `*string*` 转录的文本内容。 |
## **conversation.item.input\_audio\_transcription.failed**
启用输入音频转录后,若用户音频转录失败,服务端会返回此事件。此事件独立于 `error` 事件,便于客户端识别。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "type": "conversation.item.input_audio_transcription.failed", "item_id": "<item_id>", "content_index": 0, "error": { "code": "<code>", "message": "<message>", "param": "<param>" } } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`conversation.item.input_audio_transcription.failed`。 |
| **item\\_id** `*string*` 用户消息项的 ID。 |
| **content\\_index** `*integer*` 当前固定为0。 |
| **error** `*object*` 错误信息。 **属性** **code** `*string*` 错误码。 **message** `*string*` 错误消息。 **param** `*string*` 错误相关的参数。 |
## **response.created**
当服务端生成新的模型响应时,会返回此事件。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_XuDavMzQN3KKepqGu3KRh", "type": "response.created", "response": { "id": "resp_HaVOPdbmX6vifiV5pAfJY", "object": "realtime.response", "conversation_id": "conv_FjJaccpnvwHNo9cPVuzGc", "status": "in_progress", "modalities": [ "text", "audio" ], "voice": "Cherry", "output_audio_format": "pcm", "output": [] } } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`response.created`。 |
| **response** `*object*` 响应对象。 **属性** **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\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_CSaxRRYLvbrfexDXAEuDG", "type": "response.done", "response": { "id": "resp_HaVOPdbmX6vifiV5pAfJY", "object": "realtime.response", "conversation_id": "conv_FjJaccpnvwHNo9cPVuzGc", "status": "completed", "modalities": [ "text", "audio" ], "voice": "Cherry", "output_audio_format": "pcm", "output": [ { "id": "item_Ls6MtCUWO7LM4E59QziNv", "object": "realtime.item", "type": "message", "status": "completed", "role": "assistant", "content": [ { "type": "audio", "transcript": "你好呀!有什么我可以帮你的吗?" } ] } ], "usage": { "total_tokens": 377, "input_tokens": 336, "output_tokens": 41, "input_tokens_details": { "text_tokens": 228, "audio_tokens": 108 }, "output_tokens_details": { "text_tokens": 9, "audio_tokens": 32 }, "plugins": { "search": { "count": 1, "strategy": "agent" } } } } } // 工具调用场景 { "event_id": "event_T1EFAJp43X2DWtDRmxTtx", "type": "response.done", "response": { "id": "resp_TucN5QgymL5MA8vkJvFlS", "object": "realtime.response", "conversation_id": "conv_SEDZESRlefT8WvLSmEn6E", "status": "completed", "modalities": ["text", "audio"], "voice": "Ethan", "output_audio_format": "pcm16", "output": [ { "id": "item_FEG9qJGNkPcdf4et3p7BV", "object": "realtime.item", "type": "function_call", "status": "completed", "call_id": "call_bc0a7fb7235840f69ecfe4", "name": "get_current_weather", "arguments": " {\\"location\\": \\"杭州\\"}" } ], "usage": { "total_tokens": 567, "input_tokens": 524, "output_tokens": 43, "input_tokens_details": { "text_tokens": 487, "audio_tokens": 37 }, "output_tokens_details": { "text_tokens": 43 } } } } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`response.done`。 |
| **response** `*object*` 响应对象。 **属性** **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*` 音频转录为文字后的内容。 **name** `*string*` 当 type 为 `function_call` 时,被调用的函数名称。 **call\\_id** `*string*` 当 type 为 `function_call` 时,函数调用的唯一 ID。 **arguments** `*string*` 当 type 为 `function_call` 时,函数调用的完整参数(JSON 字符串)。 **usage** `*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\\_id** `*string*` 本次事件唯一标识符。 | ``` { "delta": "喂", "event_id": "event_TH49MauuPmRo1RGaMSlP7", "type": "response.text.delta", "response_id": "resp_PrRSvPVpnCExdUOGHHLuP", "item_id": "item_L8IRm9kRXFpxoOjDqDC96", "output_index": 0, "content_index": 0 } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`response.text.delta`。 |
| **delta** `*string*` 返回的增量文本。 |
| **response\\_id** `*string*` 回复的ID。 |
| **item\\_id** `*string*` 消息项ID,可以关联同一个消息项。 |
| **output\\_index** `*integer*` 响应中输出项的索引, 目前固定为 0。 |
| **content\\_index** `*integer*` 响应中输出项中内部部分的索引, 目前固定为 0。 |
## **response.text.done**
当输出模态仅包含文本,且模型生成的文本结束时,服务端将返回此事件。
> 当响应中断、不完整或取消时,也会返回此事件。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_B1lIeE2Nac33zn5V7h2mm", "type": "response.text.done", "response_id": "resp_B1lIdtjF4Noqpn5NOjznj", "item_id": "item_B1lIdJsAJlJiFs8ztWpJt", "output_index": 0, "content_index": 0, "text": "How can I assist you today?" } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`response.text.done`。 |
| **response\\_id** `*string*` 响应的ID。 |
| **item\\_id** `*string*` 消息项ID。 |
| **output\\_index**`*integer*` 响应输出项的索引。 |
| **content\\_index**`*integer*` 响应输出项的索引。 |
| **text** `*string*` 模型输出的完整文本。 |
## **response.audio.delta**
当输出模态包含音频,且模型增量生成新的音频数据时,服务端将返回此事件。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_B1osWMZBtrEQbiIwW0qHQ", "type": "response.audio.delta", "response_id": "resp_P79OOMs8LnrXVpiIHUCKR", "item_id": "item_OFaPGtzfWCPyGzxnuEX9i", "output_index": 0, "content_index": 0, "delta": "{base64 audio}" } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`response.audio.delta`。 |
| **response\\_id** `*string*` 响应的ID。 |
| **item\\_id** `*string*` 消息项ID。 |
| **output\\_index**`*integer*` 响应输出项的索引。 |
| **content\\_index**`*integer*` 响应输出项的索引。 |
| **delta** `*string*` 模型增量输出的音频数据,使用Base64编码。 |
## **response.audio.done**
当输出模态包含音频,且模型完成生成音频数据时,服务端将返回此事件。
> 当响应中断、不完整或取消时,也会返回此事件。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_Le1TDl7VfyHQxl47DtGxI", "type": "response.audio.done", "response_id": "resp_HaVOPdbmX6vifiV5pAfJY", "item_id": "item_Ls6MtCUWO7LM4E59QziNv", "output_index": 0, "content_index": 0 } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`response.audio.done`。 |
| **response\\_id** `*string*` 响应的ID。 |
| **item\\_id** `*string*` 消息项ID。 |
| **output\\_index**`*integer*` 响应输出项的索引。 |
| **content\\_index**`*integer*` 响应输出项的索引。 |
## **response.audio\_transcript.delta**
当输出模态包含音频,且模型增量生成新的音频对应的文本时,服务端将返回 `response.audio_transcript.delta` 事件。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_BksW7fOwnyavZdDxIzZYM", "type": "response.audio_transcript.delta", "response_id": "resp_HaVOPdbmX6vifiV5pAfJY", "item_id": "item_Ls6MtCUWO7LM4E59QziNv", "output_index": 0, "content_index": 0, "delta": "有什么" } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`response.audio_transcript.delta`。 |
| **response\\_id** `*string*` 响应的ID。 |
| **item\\_id** `*string*` 消息项ID。 |
| **output\\_index**`*integer*` 响应输出项的索引。 |
| **content\\_index**`*integer*` 响应输出项的索引。 |
| **delta** `*string*` 增量文本。 |
## **response.audio\_transcript.done**
当输出模态包含音频,且模型完成音频转录后,服务端将返回 `response.audio_transcript.done` 事件。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_X49tL2WerT4WjxcmH16lS", "type": "response.audio_transcript.done", "response_id": "resp_HaVOPdbmX6vifiV5pAfJY", "item_id": "item_Ls6MtCUWO7LM4E59QziNv", "output_index": 0, "content_index": 0, "transcript": "你好呀!有什么我可以帮你的吗?" } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`response.audio_transcript.done`。 |
| **response\\_id** `*string*` 响应的ID。 |
| **item\\_id** `*string*` 消息项ID。 |
| **output\\_index**`*integer*` 响应输出项的索引。 |
| **content\\_index**`*integer*` 响应输出项的索引。 |
| **transcript** `*string*` 完整文本。 |
## **response.function\_call\_arguments.delta**
当模型以流式方式生成函数调用的参数字符串时,每产生一段新内容,服务端推送一次本事件。客户端应按接收顺序将各事件中的 `delta` 字段拼接,得到与当前进度一致的参数文本;完整内容以随后的 `response.function_call_arguments.done` 为准。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_SlKoJyEbPEqLq14DSM1u5", "type": "response.function_call_arguments.delta", "response_id": "resp_JnTOsWXlFhKcFohZbtfz6", "item_id": "item_Rhcms7CauTNsQprV5S4Hr", "output_index": 0, "call_id": "call_2be200f4cafe419b9530dd", "delta": " {\\"location\\": \\"北京\\"}" } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`response.function_call_arguments.delta`。 |
| **response\\_id** `*string*` 响应的ID。 |
| **item\\_id** `*string*` 消息项ID。 |
| **output\\_index**`*integer*` 该响应中输出项的索引。 |
| **call\\_id** `*string*` 本次函数调用的唯一 ID,与同一轮中的 `done` 事件保持一致。 |
| **delta** `*string*` 本段新增的参数字符串片段(增量)。需按顺序拼接。 |
## **response.function\_call\_arguments.done**
函数调用参数已全部生成完毕。本事件中的 `arguments` 为完整的参数字符串。客户端可在收到本事件后解析参数并调用本地工具函数;应以本事件中的完整 `arguments` 为准,而非 `delta` 拼接结果。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_X6suLyuL5agdH7r6koesM", "type": "response.function_call_arguments.done", "response_id": "resp_JnTOsWXlFhKcFohZbtfz6", "item_id": "item_Rhcms7CauTNsQprV5S4Hr", "output_index": 0, "name": "get_current_weather", "call_id": "call_2be200f4cafe419b9530dd", "arguments": " {\\"location\\": \\"北京\\"}" } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`response.function_call_arguments.done`。 |
| **response\\_id** `*string*` 响应的ID。 |
| **item\\_id** `*string*` 消息项ID。 |
| **output\\_index**`*integer*` 该响应中输出项的索引。 |
| **call\\_id** `*string*` 本次函数调用的唯一 ID。 |
| **name** `*string*` 被调用的函数名称。 |
| **arguments** `*string*` 函数调用的完整参数,一般以 JSON 字符串形式表示。 |
## **response.output\_item.added**
在响应生成过程中创建新项目时,服务端返回此事件。项目类型可以是 `message`(常规消息)或 `function_call`(工具调用)。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_DsCO341DEVtiATtCB6BUY", "type": "response.output_item.added", "response_id": "resp_HaVOPdbmX6vifiV5pAfJY", "output_index": 0, "item": { "id": "item_Ls6MtCUWO7LM4E59QziNv", "object": "realtime.item", "type": "message", "status": "in_progress", "role": "assistant", "content": [] } } // 工具调用场景 { "event_id": "event_HXmKt5pGoiRtXx7Hq7zpN", "type": "response.output_item.added", "response_id": "resp_TucN5QgymL5MA8vkJvFlS", "output_index": 0, "item": { "id": "item_FEG9qJGNkPcdf4et3p7BV", "object": "realtime.item", "type": "function_call", "status": "in_progress", "call_id": "call_bc0a7fb7235840f69ecfe4", "name": "get_current_weather", "arguments": "" } } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`response.output_item.added`。 |
| **response\\_id** `*string*` 响应的ID。 |
| **output\\_index**`*integer*` 响应输出项的索引。 |
| **item**`*object*` 输出项信息。 **属性** **id** `*string*` 输出项的唯一ID。 **object** `*string*` 始终为 `realtime.item` 。 **status** `*string*` 输出项的状态。 **role** `*string*` 发送消息的角色。 **content** `*string*` 消息的内容。当 type 为 `message` 时存在。 **type** `*string*` 输出项的类型。可选值为 `message`(常规消息)或 `function_call`(工具调用)。 **name** `*string*` 当 type 为 `function_call` 时,被调用的函数名称。 **call\\_id** `*string*` 当 type 为 `function_call` 时,本次函数调用的唯一 ID。 **arguments** `*string*` 当 type 为 `function_call` 时,函数调用的参数(JSON 字符串)。在 added 事件中初始为空字符串。 |
## **response.output\_item.done**
当新的项目输出完成时,服务端返回此事件。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_MEu5nlLw1LsOguHiehIP8", "type": "response.output_item.done", "response_id": "resp_HaVOPdbmX6vifiV5pAfJY", "output_index": 0, "item": { "id": "item_Ls6MtCUWO7LM4E59QziNv", "object": "realtime.item", "type": "message", "status": "completed", "role": "assistant", "content": [ { "type": "audio", "text": "你好呀!有什么我可以帮你的吗?" } ] } } // 工具调用场景 { "event_id": "event_FHspdfAnCyjuME3mmAwSY", "type": "response.output_item.done", "response_id": "resp_TucN5QgymL5MA8vkJvFlS", "output_index": 0, "item": { "id": "item_FEG9qJGNkPcdf4et3p7BV", "object": "realtime.item", "type": "function_call", "status": "completed", "call_id": "call_bc0a7fb7235840f69ecfe4", "name": "get_current_weather", "arguments": " {\\"location\\": \\"杭州\\"}" } } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`response.output_item.done`。 |
| **response\\_id** `*string*` 响应的ID。 |
| **output\\_index**`*integer*` 响应输出项的索引。 |
| **item**`*object*` 输出项信息。 **属性** **id** `*string*` 输出项的唯一ID。 **object** `*string*` 始终为 `realtime.item` 。 **status** `*string*` 输出项的状态。 **role** `*string*` 发送消息的角色。 **content** `*string*` 消息的内容。当 type 为 `message` 时存在。 **type** `*string*` 输出项的类型。可选值为 `message`(常规消息)或 `function_call`(工具调用)。 **name** `*string*` 当 type 为 `function_call` 时,被调用的函数名称。 **call\\_id** `*string*` 当 type 为 `function_call` 时,本次函数调用的唯一 ID。 **arguments** `*string*` 当 type 为 `function_call` 时,函数调用的完整参数(JSON 字符串)。 |
## **response.content\_part.added**
在响应生成过程中,向助手消息项中添加新内容部分时,服务端返回此事件。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_AVBOmrgY3C8bjlRajfSUT", "type": "response.content_part.added", "response_id": "resp_HaVOPdbmX6vifiV5pAfJY", "item_id": "item_Ls6MtCUWO7LM4E59QziNv", "output_index": 0, "content_index": 0, "part": { "type": "audio", "text": "" } } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`response.content_part.added`。 |
| **response\\_id** `*string*` 响应的ID。 |
| **item\\_id** `*string*` 消息项ID。 |
| **output\\_index**`*integer*` 响应输出项的索引,目前固定为 0。 |
| **content\\_index**`*integer*` 响应输出项中内部部分的索引, 目前固定为 0。 |
| **part**`*object*` 输出项信息。 **属性** **type** `*string*` 内容部分的类型。 **text** `*string*` 内容部分的文本。 |
## **response.content\_part.done**
在助手消息项中的内容部分完成流式传输时,服务端返回此事件。
| **event\\_id** `*string*` 本次事件唯一标识符。 | ``` { "event_id": "event_Il8HD19v58Qr5IBkw7LtN", "type": "response.content_part.done", "response_id": "resp_HaVOPdbmX6vifiV5pAfJY", "item_id": "item_Ls6MtCUWO7LM4E59QziNv", "output_index": 0, "content_index": 0, "part": { "type": "audio", "text": "你好呀!有什么我可以帮你的吗?" } } ``` |
| --- | --- |
| **type** `*string*` 事件类型,固定为`response.content_part.done`。 |
| **response\\_id** `*string*` 响应的ID。 |
| **item\\_id** `*string*` 消息项ID。 |
| **output\\_index**`*integer*` 响应输出项的索引,目前固定为 0。 |
| **content\\_index**`*integer*` 该项内容数组中内容部分的索引,目前固定为 0。 |
| **part**`*object*` 输出项信息。 **属性** **type** `*string*` 内容部分的类型。 **text** `*string*` 内容部分的文本。 |