本文介紹 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內容部分的文本。 |