設定會話、傳送音訊並回傳工作結果。
透過控制 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,前台模型使用內建指令。設定 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 模式下為必要欄位。
查看子欄位
modelstring必要欄位處理委派工作的後台 Responses 模式模型 ID,例如 qwen4-max。
instructionsstring選填欄位Responses 模式下的後台任務指令由您設定。省略時,Model Studio 不提供內建的後台指令。
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_idstringfunction_call_output 的函數呼叫 ID。請使用後台事件回傳的 call_id。
outputstringfunction_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"
}