全部產品
Search
文件中心

Alibaba Cloud Model Studio:OpenAI Responses API 參考

更新時間:Feb 25, 2026

本文介紹如何通過相容 OpenAI 格式的 Responses API 呼叫通義千問模型,包括輸入輸出參數說明及調用樣本。

相較於OpenAI Chat Completions API 的優勢:

  • 內建工具:內建連網搜尋、網頁抓取、代碼解譯器、文搜圖、圖搜圖、知識庫搜尋等工具,可在處理複雜任務時獲得更優效果,詳情參考工具調用

  • 更靈活的輸入:支援直接傳入字串作為模型輸入,也相容 Chat 格式的訊息數組。

  • 簡化上下文管理:通過傳遞上一輪響應的 previous_response_id,無需手動構建完整的訊息歷史數組。

相容性說明與限制

本 API 在介面設計上相容 OpenAI,以降低開發人員遷移成本,但在參數、功能和具體行為上存在差異。

核心原則:請求將僅處理本文檔明確列出的參數,任何未提及的 OpenAI 參數都會被忽略。

以下是幾個關鍵的差異點,以協助您快速適配:

  • 部分參數不支援:不支援部分 OpenAI Responses API 參數,例如系統訊息指令instructions、非同步執行參數background(當前僅支援同步調用)等。

  • 額外支援的參數:本 API 還額外支援 enable_thinking 等參數,具體用法請參考相應參數的說明。

新加坡

SDK 調用配置的base_urlhttps://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1

HTTP 要求地址:POST https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/responses

华北2(北京)

SDK 調用配置的base_urlhttps://dashscope.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1

HTTP 要求地址:POST https://dashscope.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/responses

請求體

基礎調用

Python

import os
from openai import OpenAI

client = OpenAI(
    # If environment variable is not set, replace with: api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1",
)

response = client.responses.create(
    model="qwen3.5-plus",
    input="What can you do?"
)

# Get model response
print(response.output_text)

Node.js

import OpenAI from "openai";

const openai = new OpenAI({
    // If environment variable is not set, replace with: apiKey: "sk-xxx"
    apiKey: process.env.DASHSCOPE_API_KEY,
    baseURL: "https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
});

async function main() {
    const response = await openai.responses.create({
        model: "qwen3.5-plus",
        input: "What can you do?"
    });

    // Get model response
    console.log(response.output_text);
}

main();

curl

curl -X POST https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/responses \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen3.5-plus",
    "input": "What can you do?"
}'

流式輸出

Python

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1",
)

stream = client.responses.create(
    model="qwen3.5-plus",
    input="Please briefly introduce artificial intelligence.",
    stream=True
)

print("Receiving stream output:")
for event in stream:
    if event.type == 'response.output_text.delta':
        print(event.delta, end='', flush=True)
    elif event.type == 'response.completed':
        print("\nStream completed")
        print(f"Total tokens: {event.response.usage.total_tokens}")

Node.js

import OpenAI from "openai";

const openai = new OpenAI({
    apiKey: process.env.DASHSCOPE_API_KEY,
    baseURL: "https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
});

async function main() {
    const stream = await openai.responses.create({
        model: "qwen3.5-plus",
        input: "Please briefly introduce artificial intelligence.",
        stream: true
    });

    console.log("Receiving stream output:");
    for await (const event of stream) {
        if (event.type === 'response.output_text.delta') {
            process.stdout.write(event.delta);
        } else if (event.type === 'response.completed') {
            console.log("\nStream completed");
            console.log(`Total tokens: ${event.response.usage.total_tokens}`);
        }
    }
}

main();

curl

curl -X POST https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/responses \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
--no-buffer \
-d '{
    "model": "qwen3.5-plus",
    "input": "Please briefly introduce artificial intelligence.",
    "stream": true
}'

多輪對話

Python

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1",
)

# First round
response1 = client.responses.create(
    model="qwen3.5-plus",
    input="My name is John, please remember it."
)
print(f"First response: {response1.output_text}")

# Second round - use previous_response_id to link context
# The response id expires in 7 days
response2 = client.responses.create(
    model="qwen3.5-plus",
    input="Do you remember my name?",
    previous_response_id=response1.id
)
print(f"Second response: {response2.output_text}")

Node.js

import OpenAI from "openai";

const openai = new OpenAI({
    apiKey: process.env.DASHSCOPE_API_KEY,
    baseURL: "https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
});

async function main() {
    // First round
    const response1 = await openai.responses.create({
        model: "qwen3.5-plus",
        input: "My name is John, please remember it."
    });
    console.log(`First response: ${response1.output_text}`);

    // Second round - use previous_response_id to link context
    // The response id expires in 7 days
    const response2 = await openai.responses.create({
        model: "qwen3.5-plus",
        input: "Do you remember my name?",
        previous_response_id: response1.id
    });
    console.log(`Second response: ${response2.output_text}`);
}

main();

調用內建工具

Python

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1",
)

response = client.responses.create(
    model="qwen3.5-plus",
    input="Find the Alibaba Cloud website and extract key information",
    # For best results, enable the built-in tools
    tools=[
        {"type": "web_search"},
        {"type": "code_interpreter"},
        {"type": "web_extractor"}
    ],
    extra_body={"enable_thinking": True}
)

# Uncomment the line below to see the intermediate output
# print(response.output)
print(response.output_text)

Node.js

import OpenAI from "openai";

const openai = new OpenAI({
    apiKey: process.env.DASHSCOPE_API_KEY,
    baseURL: "https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
});

async function main() {
    const response = await openai.responses.create({
        model: "qwen3.5-plus",
        input: "Find the Alibaba Cloud website and extract key information",
        tools: [
            { type: "web_search" },
            { type: "code_interpreter" },
            { type: "web_extractor" }
        ],
        enable_thinking: true
    });

    for (const item of response.output) {
        if (item.type === "reasoning") {
            console.log("Model is thinking...");
        } else if (item.type === "web_search_call") {
            console.log(`Search query: ${item.action.query}`);
        } else if (item.type === "web_extractor_call") {
            console.log("Extracting web content...");
        } else if (item.type === "message") {
            console.log(`Response: ${item.content[0].text}`);
        }
    }
}

main();

curl

curl -X POST https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/responses \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen3.5-plus",
    "input": "Find the Alibaba Cloud website and extract key information",
    "tools": [
        {
            "type": "web_search"
        },
        {
            "type": "code_interpreter"
        },
        {
            "type": "web_extractor"
        }
    ],
    "enable_thinking": true
}'

model string (必選)

模型名稱。當前支援 qwen3-maxqwen3-max-2026-01-23qwen3.5-plusqwen3.5-plus-2026-02-15qwen3.5-flashqwen3.5-flash-2026-02-23qwen3.5-397b-a17bqwen3.5-122b-a10bqwen3.5-27bqwen3.5-35b-a3b

input string 或 array (必選)

模型輸入,支援以下格式:

  • string:純文字輸入,如 "你好"

  • array:訊息數組,按對話順序排列。

array訊息類型

System Message object (可選)

系統訊息,用於設定模型的角色、語氣、任務目標或約束條件等。如需使用,必須作為訊息數組的第一個元素。

屬性

role string (必選)

訊息角色,固定為 system

content string (必選)

系統指令內容,用於明確模型的角色、行為規範、回答風格和任務約束等。

User Message object (必選)

使用者訊息,用於向模型傳遞問題、指令或上下文等。

屬性

role string (必選)

訊息角色,固定為 user

content string 或 array (必選)

訊息內容。若輸入只有文本,則為 string 類型;若輸入包含映像或啟用顯式緩衝,則為 array 類型。

當前Responses API暫不支援傳入的視訊或語音,您可以通過Chat Completions APIDashScope API傳入。

屬性

type string (必選)

可選值:

  • text

    輸入文本時需設為text

  • image_url

    輸入圖片時需設為image_url

text string

輸入的文本。當typetext時,是必選參數。

image_url string

輸入圖片的公網 URL或Base64編碼資料。當typeimage_url時是必選參數。傳入本地檔案請參考映像與視頻理解

Assistant Message object (可選)

助手訊息,包含模型之前的回複。在多輪對話中用於提供上下文。

屬性

role string (必選)

訊息角色,固定為 assistant

content string (必選)

助手回複的常值內容。

previous_response_id string (可選)

上一個響應的唯一 ID,當前響應id有效期間為7天。使用此參數可建立多輪對話,服務端會自動檢索並組合該輪次的輸入與輸出作為上下文。當同時提供 input 訊息數組和 previous_response_id 時,input 中的新訊息會追加到歷史上下文之後。

stream boolean (可選)預設值為 false

是否開啟流式輸出。設定為 true 時,模型響應資料將即時資料流式返回給用戶端。

tools array (可選)

模型在產生響應時可調用的工具數組。支援內建工具和自訂 function 工具,可混合使用。

為了獲得最佳回複效果,建議同時開啟 code_interpreterweb_searchweb_extractor 工具。

屬性

web_search

連網搜尋工具,允許模型搜尋互連網上的最新資訊。相關文檔:連網搜尋

屬性

type string (必選)

固定為web_search

使用樣本:[{"type": "web_search"}]

web_extractor

網頁抽取工具,允許模型訪問並提取網頁內容。當前必須配合web_search工具一起使用。qwen3-maxqwen3-max-2026-01-23需要同時開啟思考模式。相關文檔:網頁抓取

屬性

type string (必選)

固定為web_extractor

使用樣本:[{"type": "web_search"}, {"type": "web_extractor"}]

code_interpreter

代碼解譯器工具,允許模型執行代碼並返回結果,支援資料分析。qwen3-maxqwen3-max-2026-01-23需要同時開啟思考模式。相關文檔:代碼解譯器

屬性

type string (必選)

固定為code_interpreter

使用樣本:[{"type": "code_interpreter"}]

web_search_image

根據文本描述搜尋圖片。相關文檔:文搜圖

屬性

type string (必選)

固定為web_search_image

使用樣本:[{"type": "web_search_image"}]

image_search

根據圖片搜尋相似或相關圖片,輸入中需要包含圖片的URL。相關文檔:圖搜圖

屬性

type string (必選)

固定為image_search

使用樣本:[{"type": "image_search"}]

file_search

在已上傳或關聯的知識庫中搜尋。相關文檔:知識檢索

屬性

type string (必選)

固定為file_search

vector_store_ids array (必選)

要檢索的知識庫 ID。當前僅支援傳入一個知識庫 ID

使用樣本:[{"type": "file_search", "vector_store_ids": ["your_knowledge_base_id"]}]

MCP調用

通過 MCP(Model Context Protocol)調用外部服務,相關文檔:MCP

屬性

type string (必選)

固定為mcp

server_protocol string (必選)

與 MCP 服務的通訊協定,如 "sse"

server_label string (必選)

服務標籤,用於標識該 MCP 服務。

server_description string (可選)

服務描述,協助模型理解其功能與適用情境。

server_url string (必選)

MCP 服務端點的 URL。

headers object (可選)

要求標頭,用於攜帶身分識別驗證等資訊,如 Authorization

使用樣本:

mcp_tool = {
    "type": "mcp",
    "server_protocol": "sse",
    "server_label": "amap-maps",
    "server_description": "高德地圖MCP Server現已覆蓋15大核心介面,提供全情境覆蓋的地理資訊服務,包括產生專屬地圖、導航到目的地、打車、地理編碼、逆地理編碼、IP定位、天氣查詢、騎行路徑規劃、步行路徑規劃、駕車路徑規劃、公交路徑規劃、距離測量、關鍵詞搜尋、周邊搜尋、詳情搜尋等。",
    "server_url": "https://dashscope.aliyuncs.com/api/v1/mcps/amap-maps/sse",
    "headers": {
        "Authorization": "Bearer <your-mcp-server-token>"
    }
}

自訂工具 function

自訂函數工具,允許模型調用您定義的函數。當模型判斷需要調用工具時,響應會返回 function_call 類型的輸出。相關文檔:Function Calling

屬性

type string (必選)

必須設定為function

name string (必選)

工具名稱。僅允許字母、數字、底線(_)和短劃線(-),最長 64 個 Token。

description string (必選)

工具描述資訊,協助模型判斷何時以及如何調用該工具。

parameters object (可選)

工具的參數描述,需要是一個合法的 JSON Schema。若parameters參數為空白,表示該工具沒有入參(如時間查詢工具)。

為提高工具調用的準確性,建議傳入 parameters

使用樣本:

[{
  "type": "function",
  "name": "get_weather",
  "description": "擷取指定城市的天氣資訊",
  "parameters": {
    "type": "object",
    "properties": {
      "city": {
        "type": "string",
        "description": "城市名稱"
      }
    },
    "required": ["city"]
  }
}]

tool_choice string or object (可選)預設值為 auto

控制模型如何選擇和調用工具。此參數支援兩種賦值格式:字串模式對象模式

字串模式

  • auto:模型自動決定是否調用工具。

  • none:禁止模型調用任何工具。

  • required:強制模型調用工具(僅當 tools 列表中只有一個工具時可用)。

對象模式

為模型設定可用的工具範圍,僅限在預定義的工具列表中進行選擇和調用。

屬性

mode string (必選)

  • auto:模型自動決定是否調用工具。

  • required:強制模型調用工具(僅當 tools 列表中只有一個工具時可用)。

tools array(必選)

一個包含工具定義的列表,模型將被允許調用這些工具。

[
  { "type": "function", "name": "get_weather" }
]

type string (必選)

允許的工具配置類型,固定為 allowed_tools

temperature float (可選)

採樣溫度,控制模型產生文本的多樣性。

temperature越高,產生的文本更多樣,反之,產生的文本更確定。

取值範圍: [0, 2)

temperature與top_p均可以控制產生文本的多樣性,建議只設定其中一個值。更多說明,請參見文本產生模型概述

top_p float (可選)

核採樣的機率閾值,控制模型產生文本的多樣性。

top_p越高,產生的文本更多樣。反之,產生的文本更確定。

取值範圍:(0,1.0]

temperature與top_p均可以控制產生文本的多樣性,建議只設定其中一個值。更多說明,請參見文本產生模型概述

enable_thinking boolean (可選)

是否開啟思考模式。開啟後,模型會在回複前進行思考,思考內容將通過 reasoning 類型的輸出項返回。開啟思考模式時,建議開啟內建工具,以在處理複雜任務時獲得最佳的模型效果。

可選值:

  • true:開啟

  • false:不開啟

不同模型的預設值:支援的模型

該參數非OpenAI標準參數。Python SDK 通過 extra_body={"enable_thinking": True} 傳遞;Node.js SDK 和 curl 直接使用 enable_thinking: true 作為頂層參數。

Response 響應對象(非流式輸出)

{
    "created_at": 1771165900.0,
    "id": "f75c28fb-4064-48ed-90da-4d2cc4362xxx",
    "model": "qwen3.5-plus",
    "object": "response",
    "output": [
        {
            "content": [
                {
                    "annotations": [],
                    "text": "Hello! I am Qwen3.5, a large language model developed by Alibaba Cloud with knowledge up to 2026, designed to assist you with complex reasoning, creative tasks, and multilingual conversations.",
                    "type": "output_text"
                }
            ],
            "id": "msg_89ad23e6-f128-4d4c-b7a1-a786e7880xxx",
            "role": "assistant",
            "status": "completed",
            "type": "message"
        }
    ],
    "parallel_tool_calls": false,
    "status": "completed",
    "tool_choice": "auto",
    "tools": [],
    "usage": {
        "input_tokens": 57,
        "input_tokens_details": {
            "cached_tokens": 0
        },
        "output_tokens": 44,
        "output_tokens_details": {
            "reasoning_tokens": 0
        },
        "total_tokens": 101,
        "x_details": [
            {
                "input_tokens": 57,
                "output_tokens": 44,
                "total_tokens": 101,
                "x_billing_type": "response_api"
            }
        ]
    }
}

id string

本次響應的唯一識別碼,為 UUID 格式的字串,有效期間為7天。可用於 previous_response_id 參數以建立多輪對話。

created_at integer

本次請求的 Unix 時間戳記(秒)。

object string

物件類型,固定為 response

status string

響應產生的狀態。枚舉值:

  • completed:產生完成

  • failed:產生失敗

  • in_progress:產生中

  • cancelled:已取消

  • queued:請求排隊中

  • incomplete:產生不完整

model string

用於產生響應的模型 ID。

output array

模型產生的輸出項數組。數組中的元素類型和順序取決於模型的響應。

數組元素屬性

type string

輸出項類型。枚舉值:

  • message:訊息類型,包含模型最終產生的回複內容。

  • reasoning:推理類型,開啟思考模式(enable_thinking: true)時返回。推理 Token 會被計入 output_tokens_details.reasoning_tokens 中,按推理 Token 計費。

  • function_call:函數調用類型,使用自訂 function 工具時返回。需要處理函數調用並返回結果。

  • web_search_call:搜尋調用類型,使用 web_search 工具時返回。

  • code_interpreter_call:代碼執行類型,使用 code_interpreter 工具時返回。

  • web_extractor_call:網頁抽取類型,使用 web_extractor 工具時返回。需要配合 web_search 工具一起使用。

  • web_search_image_call:文搜圖調用類型,使用 web_search_image 工具時返回。包含搜尋到的圖片列表。

  • image_search_call:圖搜圖調用類型,使用 image_search 工具時返回。包含搜尋到的相似圖片列表。

  • mcp_call:MCP 調用類型,使用 mcp 工具時返回。包含 MCP 服務的調用結果。

  • file_search_call:知識庫搜尋調用類型,使用 file_search 工具時返回。包含知識庫的檢索查詢和結果。

id string

輸出項的唯一識別碼。所有類型的輸出項都包含此欄位。

role string

訊息角色,固定為 assistant。僅當 typemessage 時存在。

status string

輸出項狀態。可選值:completed(完成)、in_progress(產生中)。當 type bu時存在。

name string

工具或函數名稱。當 typefunction_callweb_search_image_callimage_search_callmcp_call 時存在。

對於 web_search_image_callimage_search_call,值分別固定為 "web_search_image""image_search"

對於 mcp_call,值為 MCP 服務中被調用的具體函數名(如 amap-maps-maps_geo)。

arguments string

工具調用的參數,JSON 字串格式。當 typefunction_callweb_search_image_callimage_search_callmcp_call 時存在。使用前需要通過 JSON.parse() 解析。不同工具類型的 arguments 內容:

  • web_search_image_call{"queries": ["搜尋關鍵詞1", "搜尋關鍵詞2"]},其中 queries 為模型根據使用者輸入自動產生的搜尋關鍵詞列表。

  • image_search_call{"img_idx": 0, "bbox": [0, 0, 1000, 1000]},其中 img_idx 為輸入圖片的索引(從 0 開始),bbox 為搜尋地區的邊界框座標 [x1, y1, x2, y2],座標範圍 0-1000。

  • function_call:按使用者定義的函數參數 schema 產生的參數對象。

  • mcp_call:MCP 服務中被調用函數的參數對象。

call_id string

函數調用的唯一識別碼。僅當 typefunction_call 時存在。在返回函數調用結果時,需要通過此 ID 關聯請求與響應。

content array

訊息內容數組。僅當 typemessage 時存在。

數組元素屬性

type string

內容類型,固定為 output_text

text string

模型產生的常值內容。

annotations array

文本注釋數組。通常為空白數組。

summary array

推理摘要數組。僅當 typereasoning 時存在。每個元素包含 type(值為 summary_text)和 text(摘要文本)欄位。

action object

搜尋動作資訊。僅當 typeweb_search_call 時存在。

屬性

query string

搜尋查詢關鍵詞。

type string

搜尋類型,固定為 search

sources array

搜尋來源列表。每個元素包含 typeurl欄位。

code string

模型產生並執行的代碼。僅當 typecode_interpreter_call 時存在。

outputs array

代碼執行輸出數組。僅當 typecode_interpreter_call 時存在。每個元素包含 type(值為 logs)和 logs(代碼執行日誌)欄位。

container_id string

代碼解譯器容器標識符。僅當 typecode_interpreter_call 時存在。用於關聯同一會話中的多次代碼執行。

goal string

抽取目標描述,說明需要從網頁中提取哪些資訊。僅當 typeweb_extractor_call 時存在。

output string

工具調用的輸出結果,字串格式。

  • typeweb_extractor_call 時為網頁抽取的內容摘要

  • typeweb_search_image_callimage_search_call 時為 JSON 字串,包含圖片搜尋結果數組,每個元素包含 title(圖片標題)、url(圖片 URL)和 index(序號)欄位

  • typemcp_call 時為 MCP 服務返回的 JSON 字串結果。

urls array

被抽取的網頁 URL 列表。僅當 typeweb_extractor_call 時存在。

server_label string

MCP 服務標籤。僅當 typemcp_call 時存在。標識本次調用所使用的 MCP 服務。

queries array

知識庫檢索使用的查詢列表。僅當 typefile_search_call 時存在。數組元素為字串,表示模型產生的搜尋查詢詞。

results array

知識庫檢索結果數組。僅當 typefile_search_call 時存在。

數組元素屬性

file_id string

匹配文檔的檔案 ID。

filename string

匹配文檔的檔案名稱。

score float

匹配相關度評分,取值範圍 0-1,值越大表示相關度越高。

text string

匹配到的文檔內容片段。

usage object

本次請求的 Token 消耗資訊。

屬性

input_tokens integer

輸入的 Token 數。

output_tokens integer

模型輸出的 Token 數。

total_tokens integer

消耗的總 Token 數,為 input_tokens 與 output_tokens 的總和。

input_tokens_details object

輸入 Token 的細粒度分類。

屬性

cached_tokens integer

命中緩衝的 Token 數。詳情請參見上下文緩衝

output_tokens_details object

輸出 Token 的細粒度分類。

屬性

reasoning_tokens integer

思考過程 Token 數。

x_details object

屬性

input_tokens integer

輸入的 Token 數。

output_tokens integer

模型輸出的 Token 數。

total_tokens integer

消耗的總 Token 數,為 input_tokens 與 output_tokens 的總和。

x_billing_type string

固定為response_api

x_tools object

工具使用統計資訊。當使用內建工具時,包含各工具的調用次數。

樣本:{"web_search": {"count": 1}}

error object

當模型產生響應失敗時返回的錯誤對象。成功時為 null

tools array

回應要求中 tools 參數的完整內容,結構與請求體中的 tools 參數相同。

tool_choice string

回應要求中 tool_choice 參數的值,枚舉值為 autononerequired

Response 響應 chunk 對象(流式輸出)

基礎調用

// response.created - 響應建立
{"response":{"id":"428c90e9-9cd6-90a6-9726-c02b08ebexxx","created_at":1769082930,"object":"response","status":"queued",...},"sequence_number":0,"type":"response.created"}

// response.in_progress - 響應進行中
{"response":{"id":"428c90e9-9cd6-90a6-9726-c02b08ebexxx","status":"in_progress",...},"sequence_number":1,"type":"response.in_progress"}

// response.output_item.added - 新增輸出項
{"item":{"id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8exxx","content":[],"role":"assistant","status":"in_progress","type":"message"},"output_index":0,"sequence_number":2,"type":"response.output_item.added"}

// response.content_part.added - 新增內容塊
{"content_index":0,"item_id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8exxx","output_index":0,"part":{"annotations":[],"text":"","type":"output_text","logprobs":null},"sequence_number":3,"type":"response.content_part.added"}

// response.output_text.delta - 增量文本(多次觸發)
{"content_index":0,"delta":"人工智慧","item_id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8exxx","logprobs":[],"output_index":0,"sequence_number":4,"type":"response.output_text.delta"}
{"content_index":0,"delta":"(Artificial Intelligence,","item_id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8exxx","logprobs":[],"output_index":0,"sequence_number":6,"type":"response.output_text.delta"}

// response.output_text.done - 文本完成
{"content_index":0,"item_id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8exxx","logprobs":[],"output_index":0,"sequence_number":53,"text":"人工智慧(Artificial Intelligence,簡稱 AI)是指由電腦系統類比人類智能行為的技術和科學...","type":"response.output_text.done"}

// response.content_part.done - 內容塊完成
{"content_index":0,"item_id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8exxx","output_index":0,"part":{"annotations":[],"text":"...完整文本...","type":"output_text","logprobs":null},"sequence_number":54,"type":"response.content_part.done"}

// response.output_item.done - 輸出項完成
{"item":{"id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8exxx","content":[{"annotations":[],"text":"...完整文本...","type":"output_text","logprobs":null}],"role":"assistant","status":"completed","type":"message"},"output_index":0,"sequence_number":55,"type":"response.output_item.done"}

// response.completed - 響應完成(包含完整響應和 usage)
{"response":{"id":"428c90e9-9cd6-90a6-9726-c02b08ebexxx","created_at":1769082930,"model":"qwen3-max-2026-01-23","object":"response","output":[...],"status":"completed","usage":{"input_tokens":37,"output_tokens":243,"total_tokens":280,...}},"sequence_number":56,"type":"response.completed"}

網頁抓取

id:1
event:response.created
:HTTP_STATUS/200
data:{"sequence_number":0,"type":"response.created","response":{"output":[],"parallel_tool_calls":false,"created_at":1769435906,"tool_choice":"auto","model":"","id":"863df8d9-cb29-4239-a54f-3e15a2427xxx","tools":[],"object":"response","status":"queued"}}

id:2
event:response.in_progress
:HTTP_STATUS/200
data:{"sequence_number":1,"type":"response.in_progress","response":{"output":[],"parallel_tool_calls":false,"created_at":1769435906,"tool_choice":"auto","model":"","id":"863df8d9-cb29-4239-a54f-3e15a2427xxx","tools":[],"object":"response","status":"in_progress"}}

id:3
event:response.output_item.added
:HTTP_STATUS/200
data:{"sequence_number":2,"item":{"summary":[],"type":"reasoning","id":"msg_5bd0c6df-19b8-4a04-bc00-8042a224exxx"},"output_index":0,"type":"response.output_item.added"}

id:4
event:response.reasoning_summary_text.delta
:HTTP_STATUS/200
data:{"delta":"使用者想要我:\n1. 搜尋阿里雲官網\n2. 提取官網首頁的關鍵資訊\n\n我需要先搜尋阿里雲官網的URL,然後使用web_extractor工具訪問官網並提取關鍵資訊。","sequence_number":3,"output_index":0,"type":"response.reasoning_summary_text.delta","item_id":"msg_5bd0c6df-19b8-4a04-bc00-8042a224exxx","summary_index":0}

id:14
event:response.reasoning_summary_text.done
:HTTP_STATUS/200
data:{"sequence_number":13,"text":"使用者想要我:\n1. 搜尋阿里雲官網\n2. 提取官網首頁的關鍵資訊\n\n我需要先搜尋阿里雲官網的URL,然後使用web_extractor工具訪問官網並提取關鍵資訊。","output_index":0,"type":"response.reasoning_summary_text.done","item_id":"msg_5bd0c6df-19b8-4a04-bc00-8042a224exxx","summary_index":0}

id:15
event:response.output_item.done
:HTTP_STATUS/200
data:{"sequence_number":14,"item":{"summary":[{"type":"summary_text","text":"使用者想要我:\n1. 搜尋阿里雲官網\n2. 提取官網首頁的關鍵資訊\n\n我需要先搜尋阿里雲官網的URL,然後使用web_extractor工具訪問官網並提取關鍵資訊。"}],"type":"reasoning","id":"msg_5bd0c6df-19b8-4a04-bc00-8042a224exxx"},"output_index":1,"type":"response.output_item.done"}

id:16
event:response.output_item.added
:HTTP_STATUS/200
data:{"sequence_number":15,"item":{"action":{"type":"search","query":"Web search"},"id":"msg_a8a686b1-0a57-40e1-bb55-049a89cd4xxx","type":"web_search_call","status":"in_progress"},"output_index":1,"type":"response.output_item.added"}

id:17
event:response.web_search_call.in_progress
:HTTP_STATUS/200
data:{"sequence_number":16,"output_index":1,"type":"response.web_search_call.in_progress","item_id":"msg_a8a686b1-0a57-40e1-bb55-049a89cd4xxx"}

id:19
event:response.web_search_call.completed
:HTTP_STATUS/200
data:{"sequence_number":18,"output_index":1,"type":"response.web_search_call.completed","item_id":"msg_a8a686b1-0a57-40e1-bb55-049a89cd4xxx"}

id:20
event:response.output_item.done
:HTTP_STATUS/200
data:{"sequence_number":19,"item":{"action":{"sources":[{"type":"url","url":"https://cn.aliyun.com/"},{"type":"url","url":"https://www.aliyun.com/"}],"type":"search","query":"Web search"},"id":"msg_a8a686b1-0a57-40e1-bb55-049a89cd4xxx","type":"web_search_call","status":"completed"},"output_index":1,"type":"response.output_item.done"}

id:33
event:response.output_item.added
:HTTP_STATUS/200
data:{"sequence_number":32,"item":{"urls":["https://cn.aliyun.com/"],"goal":"提取阿里雲官網首頁的關鍵資訊,包括:公司定位/簡介、核心產品與服務、主要業務板塊、特色功能/解決方案、最新動向/活動、免費試用/優惠資訊、導覽功能表結構等","id":"msg_8c2cf651-48a5-460c-aa7a-bea5b09b4xxx","type":"web_extractor_call","status":"in_progress"},"output_index":3,"type":"response.output_item.added"}

id:34
event:response.output_item.done
:HTTP_STATUS/200
data:{"sequence_number":33,"item":{"output":"The useful information in https://cn.aliyun.com/ for user goal 提取阿里雲官網首頁的關鍵資訊,包括:公司定位/簡介、核心產品與服務、主要業務板塊、特色功能/解決方案、最新動向/活動、免費試用/優惠資訊、導覽功能表結構等 as follows: \n\nEvidence in page: \n## 通義大模型,企業擁抱 AI 時代首選\n\n## 完整的產品體系,為企業打造技術創新的雲\n\n全部雲產品## 依託大模型與雲端運算協同發展,讓 AI 觸手可及\n\n全部 AI 解決方案\n\nSummary: \nAlibaba Cloud positions itself as a leading enterprise AI solution provider centered around the Tongyi large model...","urls":["https://cn.aliyun.com/"],"goal":"提取阿里雲官網首頁的關鍵資訊,包括:公司定位/簡介、核心產品與服務、主要業務板塊、特色功能/解決方案、最新動向/活動、免費試用/優惠資訊、導覽功能表結構等","id":"msg_8c2cf651-48a5-460c-aa7a-bea5b09b4xxx","type":"web_extractor_call","status":"completed"},"output_index":3,"type":"response.output_item.done"}

id:50
event:response.output_item.added
:HTTP_STATUS/200
data:{"sequence_number":50,"item":{"content":[{"type":"text","text":""}],"type":"message","id":"msg_final","role":"assistant"},"output_index":5,"type":"response.output_item.added"}

id:51
event:response.output_text.delta
:HTTP_STATUS/200
data:{"delta":"我已經找到阿里雲官網並提取了首頁的關鍵資訊:\n\n","sequence_number":51,"output_index":5,"type":"response.output_text.delta"}

id:60
event:response.completed
:HTTP_STATUS/200
data:{"type":"response.completed","response":{"id":"863df8d9-cb29-4239-a54f-3e15a2427xxx","status":"completed","usage":{"input_tokens":45,"output_tokens":320,"total_tokens":365}}}

文搜圖

// 1. response.created - 響應建立
id:1
event:response.created
data:{"sequence_number":0,"type":"response.created","response":{"output":[],"status":"queued",...}}

// 2. response.in_progress - 響應進行中
id:2
event:response.in_progress
data:{"sequence_number":1,"type":"response.in_progress","response":{"status":"in_progress",...}}

// 3. response.output_item.added - 推理開始(reasoning)
id:3
event:response.output_item.added
data:{"sequence_number":2,"item":{"summary":[],"type":"reasoning","id":"msg_xxx"},"output_index":0,"type":"response.output_item.added"}

// 4. response.reasoning_summary_text.delta - 推理摘要增量
id:4
event:response.reasoning_summary_text.delta
data:{"delta":"使用者想要找一張貓咪圖片。我需要使用web_search_image工具來搜尋...","sequence_number":3,"output_index":0,"type":"response.reasoning_summary_text.delta","item_id":"msg_xxx","summary_index":0}

// 5. response.reasoning_summary_text.done - 推理摘要完成
id:10
event:response.reasoning_summary_text.done
data:{"sequence_number":9,"text":"使用者想要找一張貓咪圖片。我需要使用web_search_image工具來搜尋貓咪圖片。","output_index":0,"type":"response.reasoning_summary_text.done","item_id":"msg_xxx","summary_index":0}

// 6. response.output_item.done - 推理項完成
id:11
event:response.output_item.done
data:{"sequence_number":10,"item":{"summary":[{"type":"summary_text","text":"..."}],"type":"reasoning","id":"msg_xxx"},"output_index":0,"type":"response.output_item.done"}

// 7. response.output_item.added - 文搜圖工具調用開始(status: in_progress,此時已包含 name 和 arguments)
id:12
event:response.output_item.added
data:{"sequence_number":11,"item":{"name":"web_search_image","arguments":"{\"queries\": [\"貓咪圖片\", \"cute cat\"]}","id":"msg_xxx","type":"web_search_image_call","status":"in_progress"},"output_index":1,"type":"response.output_item.added"}

// 8. response.output_item.done - 文搜圖工具調用完成(包含完整的 output 搜尋結果)
id:13
event:response.output_item.done
data:{"sequence_number":12,"item":{"name":"web_search_image","output":"[{\"title\": \"可愛的小貓咪...\", \"url\": \"https://example.com/cat.jpg\", \"index\": 1}, ...]","arguments":"{\"queries\": [\"貓咪圖片\", \"cute cat\"]}","id":"msg_xxx","type":"web_search_image_call","status":"completed"},"output_index":1,"type":"response.output_item.done"}

// 9-12. 第二輪推理 + 最終訊息輸出(與基礎調用相同)
// response.output_item.added (reasoning) → reasoning_summary_text.delta/done → response.output_item.done (reasoning)
// response.output_item.added (message) → response.content_part.added → response.output_text.delta → response.output_text.done → response.content_part.done → response.output_item.done (message)

// 13. response.completed - 響應完成
id:118
event:response.completed
data:{"sequence_number":117,"type":"response.completed","response":{"output":[...],"status":"completed","usage":{"input_tokens":7895,"output_tokens":318,"total_tokens":8213,"x_tools":{"web_search_image":{"count":1}}}}}

圖搜圖

// 1-6. 推理階段(與文搜圖相同)

// 7. response.output_item.added - 圖搜圖工具調用開始
// 注意 arguments 中包含 img_idx(圖片索引)和 bbox(搜尋地區邊界框)
id:29
event:response.output_item.added
data:{"sequence_number":29,"item":{"name":"image_search","arguments":"{\"img_idx\": 0, \"bbox\": [0, 0, 1000, 1000]}","id":"msg_xxx","type":"image_search_call","status":"in_progress"},"output_index":1,"type":"response.output_item.added"}

// 8. response.output_item.done - 圖搜圖工具調用完成
id:30
event:response.output_item.done
data:{"sequence_number":30,"item":{"name":"image_search","output":"[{\"title\": \"水墨山背景...\", \"url\": \"https://example.com/landscape.jpg\", \"index\": 1}, ...]","arguments":"{\"img_idx\": 0, \"bbox\": [0, 0, 1000, 1000]}","id":"msg_xxx","type":"image_search_call","status":"completed"},"output_index":1,"type":"response.output_item.done"}

// 9-12. 第二輪推理 + 最終訊息輸出(與基礎調用相同)

// 13. response.completed
id:408
event:response.completed
data:{"sequence_number":407,"type":"response.completed","response":{"output":[...],"status":"completed","usage":{"input_tokens":8371,"output_tokens":417,"total_tokens":8788,"x_tools":{"image_search":{"count":1}}}}}

MCP

// 1-6. 推理階段(與其他工具相同)

// 7. response.mcp_call_arguments.delta - MCP 參數增量(MCP 專屬事件)
id:27
event:response.mcp_call_arguments.delta
data:{"delta":"{\"city\": \"北京\"}","sequence_number":26,"output_index":1,"type":"response.mcp_call_arguments.delta","item_id":"msg_xxx"}

// 8. response.mcp_call_arguments.done - MCP 參數完成(MCP 專屬事件)
id:28
event:response.mcp_call_arguments.done
data:{"sequence_number":27,"arguments":"{\"city\": \"北京\"}","output_index":1,"type":"response.mcp_call_arguments.done","item_id":"msg_xxx"}

// 9. response.output_item.added - MCP 工具調用開始(包含 name、server_label、arguments)
id:29
event:response.output_item.added
data:{"sequence_number":28,"item":{"name":"amap-maps-maps_weather","server_label":"MCP Server","arguments":"{\"city\": \"北京\"}","id":"msg_xxx","type":"mcp_call","status":"in_progress"},"output_index":1,"type":"response.output_item.added"}

// 10. response.mcp_call.completed - MCP 調用完成(MCP 專屬事件)
id:30
event:response.mcp_call.completed
data:{"sequence_number":29,"output_index":1,"type":"response.mcp_call.completed","item_id":"msg_xxx"}

// 11. response.output_item.done - MCP 輸出項完成(包含完整 output)
id:31
event:response.output_item.done
data:{"sequence_number":30,"item":{"output":"{\"city\":\"北京市\",\"forecasts\":[...]}","name":"amap-maps-maps_weather","server_label":"MCP Server","arguments":"{\"city\": \"北京\"}","id":"msg_xxx","type":"mcp_call","status":"completed"},"output_index":1,"type":"response.output_item.done"}

// 12-15. 第二輪推理 + 最終訊息輸出

// 16. response.completed
id:172
event:response.completed
data:{"sequence_number":171,"type":"response.completed","response":{"output":[...],"status":"completed","usage":{"input_tokens":5019,"output_tokens":539,"total_tokens":5558}}}

知識庫搜尋

// 1-6. 推理階段(與其他工具相同)

// 7. response.output_item.added - 知識庫搜尋開始(包含 queries,無 results)
id:19
event:response.output_item.added
data:{"sequence_number":18,"item":{"id":"msg_xxx","type":"file_search_call","queries":["阿里雲百鍊X1手機","Alibaba Cloud Bailian X1 phone","百鍊X1"],"status":"in_progress"},"output_index":1,"type":"response.output_item.added"}

// 8. response.file_search_call.in_progress - 搜尋進行中(file_search 專屬事件)
id:20
event:response.file_search_call.in_progress
data:{"sequence_number":19,"output_index":1,"type":"response.file_search_call.in_progress","item_id":"msg_xxx"}

// 9. response.file_search_call.searching - 正在搜尋(file_search 專屬事件)
id:21
event:response.file_search_call.searching
data:{"sequence_number":20,"output_index":1,"type":"response.file_search_call.searching","item_id":"msg_xxx"}

// 10. response.file_search_call.completed - 搜尋完成(file_search 專屬事件)
id:22
event:response.file_search_call.completed
data:{"sequence_number":21,"output_index":1,"type":"response.file_search_call.completed","item_id":"msg_xxx"}

// 11. response.output_item.done - 輸出項完成(包含 queries + results)
id:23
event:response.output_item.done
data:{"sequence_number":22,"item":{"id":"msg_xxx","type":"file_search_call","queries":["阿里雲百鍊X1手機","Alibaba Cloud Bailian X1 phone","百鍊X1"],"results":[{"score":0.7519,"filename":"阿里雲百鍊系列手機產品介紹","text":"阿里雲百鍊 X1 ——暢享極致視界...","file_id":"file_xxx"}],"status":"completed"},"output_index":1,"type":"response.output_item.done"}

// 12-15. 第二輪推理 + 最終訊息輸出

// 16. response.completed
id:146
event:response.completed
data:{"sequence_number":145,"type":"response.completed","response":{"output":[...],"status":"completed","usage":{"input_tokens":1576,"output_tokens":722,"total_tokens":2298,"x_tools":{"file_search":{"count":1}}}}}

流式輸出返回一系列 JSON 對象。每個對象包含 type 欄位標識事件類型,sequence_number 欄位標識事件順序。response.completed 事件標誌著串流的結束。

type string

事件類型標識符。枚舉值:

  • response.created:響應建立時觸發,狀態為 queued

  • response.in_progress:響應開始處理時觸發,狀態變為 in_progress

  • response.output_item.added:新的輸出項(如 message、web_extractor_call)被添加到 output 數組時觸發。當 item.typeweb_extractor_call 時,表示網頁抽取工具調用開始。

  • response.content_part.added:輸出項的 content 數組中新增內容塊時觸發。

  • response.output_text.delta:增量文本產生時觸發,多次觸發,delta 欄位包含新增文本片段。

  • response.output_text.done:文本產生完成時觸發,text 欄位包含完整文本。

  • response.content_part.done:內容塊完成時觸發,part 對象包含完整內容塊。

  • response.output_item.done:輸出項產生完成時觸發,item 對象包含完整輸出項。當 item.typeweb_extractor_call 時,表示網頁抽取工具調用完成。

  • response.reasoning_summary_text.delta:(開啟思考模式時)推理摘要增量文本,delta 欄位包含新增摘要片段。

  • response.reasoning_summary_text.done:(開啟思考模式時)推理摘要完成,text 欄位包含完整摘要。

  • response.web_search_call.in_progress / searching / completed:(使用 web_search 工具時)搜尋狀態變化事件。

  • response.code_interpreter_call.in_progress / interpreting / completed:(使用 code_interpreter 工具時)代碼執行狀態變化事件。

  • 注意:使用 web_extractor 工具時,沒有專門的事件類型標識符。網頁抽取工具調用通過通用的 response.output_item.addedresponse.output_item.done 事件傳遞,通過 item.type 欄位(值為 web_extractor_call)來識別。

  • response.mcp_call_arguments.delta / response.mcp_call_arguments.done:(使用 mcp 工具時)MCP 調用參數的增量和完成事件。

  • response.mcp_call.completed:(使用 mcp 工具時)MCP 服務調用完成。

  • response.file_search_call.in_progress / searching / completed:(使用 file_search 工具時)知識庫搜尋狀態變化事件。

  • 注意:使用 web_search_imageimage_search 工具時,沒有專門的中間狀態事件。工具調用通過 response.output_item.added(調用開始)和 response.output_item.done(調用完成)事件傳遞。

  • response.completed:響應產生完成時觸發,response 對象包含完整響應(含 usage)。此事件標誌串流結束。

sequence_number integer

事件序號,從 0 開始遞增。用於確保用戶端按正確順序處理事件。

response object

響應對象。出現在 response.createdresponse.in_progressresponse.completed 事件中。在 response.completed 事件中包含完整的響應資料(包括 outputusage),其結構與非流式響應的 Response 對象一致。

item object

輸出項對象。出現在 response.output_item.addedresponse.output_item.done 事件中。在 added 事件中為初始骨架(content 為空白數組),在 done 事件中為完整對象。

屬性

id string

輸出項的唯一識別碼(如 msg_xxx)。

type string

輸出項類型。枚舉值:message(訊息)、reasoning(推理)、web_search_call(搜尋)、web_search_image_call(文搜圖)、image_search_call(圖搜圖)、mcp_call(MCP 調用)、file_search_call(知識庫搜尋)。

role string

訊息角色,固定為 assistant。僅當 type 為 message 時存在。

status string

產生狀態。在 added 事件中為 in_progress,在 done 事件中為 completed

content array

訊息內容數組。在 added 事件中為空白數組 [],在 done 事件中包含完整的內容塊對象(結構與 part 對象相同)。

part object

內容塊對象。出現在 response.content_part.addedresponse.content_part.done 事件中。

屬性

type string

內容塊類型,固定為 output_text

text string

常值內容。在 added 事件中為空白字串,在 done 事件中為完整文本。

annotations array

文本注釋數組。通常為空白數組。

logprobs object | null

Token 的對數機率資訊。當前固定返回 null

delta string

增量常值內容。出現在 response.output_text.delta 事件中,包含本次新增的文本片段。用戶端應將所有 delta 拼接以獲得完整文本。

text string

完整常值內容。出現在 response.output_text.done 事件中,包含該內容塊的完整文本,可用於校正 delta 拼接結果。

item_id string

輸出項的唯一識別碼。用於關聯同一輸出項的相關事件。

output_index integer

輸出項在 output 數組中的索引位置。

content_index integer

內容塊在 content 數組中的索引位置。

summary_index integer

摘要數組索引。出現在 response.reasoning_summary_text.deltaresponse.reasoning_summary_text.done 事件中。

常見問題

Q:如何傳遞多輪對話的上下文?

A:在發起新一輪對話請求時,請將上一輪模型響應成功返回的id作為 previous_response_id 參數傳入。

Q:為什麼響應樣本中的某些欄位未在本文說明?

A:如果使用OpenAI的官方SDK,它可能會根據其自身的模型結構輸出一些額外的欄位(通常為null)。這些欄位是OpenAI協議本身定義的,我們的服務當前不支援,所以它們為空白值。只需關注本文檔中描述的欄位即可。