全部產品
Search
文件中心

Alibaba Cloud Model Studio:擷取響應

更新時間:Jun 29, 2026

根據 Response ID 擷取一個已完成的模型響應。

华北2(北京)

SDK 調用配置的base_urlhttps://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1

HTTP 要求地址:GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/responses/{response_id}

調用時請將{WorkspaceId}替換為真實的業務空間ID

路徑參數

response_id string (必選)

要擷取的 Response ID,格式為 resp_xxx。可從建立響應介面的響應中擷取。僅當原建立請求中 store=true 時返回的 Response ID 可被檢索。

Python

import os
from openai import OpenAI

client = OpenAI(
    # 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

response = client.responses.retrieve("resp_xxx")
print(response)

Node.js

import OpenAI from "openai";

const openai = new OpenAI({
    // 若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey: "sk-xxx"
    apiKey: process.env.DASHSCOPE_API_KEY,
    baseURL: "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1"
});

async function main() {
    const response = await openai.responses.retrieve("resp_xxx");
    console.log(response);
}

main();

curl

curl https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/responses/resp_xxx \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY"

返回結果

返回與建立響應相同的 Response 對象。各欄位含義如下:

{
    "background": false,
    "completed_at": 1778676420,
    "created_at": 1778676418,
    "frequency_penalty": 0.0,
    "id": "resp_801bc2c4-93d9-910f-b35d-5274f5a737c1",
    "metadata": {},
    "model": "qwen-plus",
    "object": "response",
    "output": [
        {
            "content": [
                {
                    "annotations": [],
                    "text": "你好!很高興見到你。有什麼我可以協助你的嗎?",
                    "type": "output_text"
                }
            ],
            "id": "msg_8c54756c-9b65-4a95-81d7-4276d91406db",
            "role": "assistant",
            "status": "completed",
            "type": "message"
        }
    ],
    "parallel_tool_calls": true,
    "presence_penalty": 0.0,
    "service_tier": "default",
    "status": "completed",
    "store": true,
    "temperature": 1.0,
    "tool_choice": "auto",
    "tools": [],
    "top_logprobs": 0,
    "top_p": 1.0,
    "usage": {
        "input_tokens": 45,
        "input_tokens_details": {
            "cached_tokens": 0
        },
        "output_tokens": 63,
        "output_tokens_details": {
            "reasoning_tokens": 0
        },
        "total_tokens": 108,
        "x_details": [
            {
                "input_tokens": 45,
                "output_tokens": 63,
                "prompt_tokens_details": {
                    "cached_tokens": 0
                },
                "total_tokens": 108,
                "x_billing_type": "response_api"
            }
        ]
    }
}

id string

本次響應的唯一識別碼,格式為 resp_xxx

object string

物件類型,固定為 response

status string

響應狀態。枚舉值:completed(完成)、failed(失敗)、in_progress(產生中)、cancelled(已取消)、queued(排隊中)、incomplete(不完整)。

created_at integer

響應建立時的 Unix 時間戳記(秒)。

completed_at integer

響應產生完成時的 Unix 時間戳記(秒)。響應未完成時為 null

error object

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

model string

用於產生響應的模型 ID。

output array

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

數組元素屬性

type string

輸出項類型。枚舉值:

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

  • reasoning:推理類型,設定 reasoning.effort(非 none)或開啟思考模式時返回。推理 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 不為reasoning時存在。

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 array

計費明細數組。

屬性

input_tokens integer

本計費類型的輸入 Token 數。

output_tokens integer

本計費類型的輸出 Token 數。

total_tokens integer

本計費類型的總 Token 數。

x_billing_type string

固定為response_api

prompt_tokens_details object

啟用 Session 緩衝後返回。包含 cached_tokens(命中緩衝的 Token 數)欄位。

x_tools object

工具使用統計資訊。當使用內建工具時,包含各工具的調用次數。樣本:{"web_search": {"count": 1}}

tools array

回顯原建立響應請求中 tools 參數的完整內容。結構與請求體中的 tools 參數相同。無工具時為空白數組 []

tool_choice string

回顯原建立響應請求中 tool_choice 參數的值。枚舉值:autononerequired

parallel_tool_calls boolean

回顯原建立響應請求中 parallel_tool_calls 參數的值,表示是否允許模型並行調用多個工具。

temperature float

回顯原建立響應請求中 temperature 參數的值。採樣溫度,控制模型產生文本的多樣性,取值範圍 [0, 2)。未設定時返回模型預設值。

top_p float

回顯原建立響應請求中 top_p 參數的值。核採樣的機率閾值,取值範圍 (0, 1.0]。未設定時返回模型預設值。

frequency_penalty float

回顯原建立響應請求中 frequency_penalty 參數的值。頻率懲罰係數,正值降低重複用詞的機率。

presence_penalty float

回顯原建立響應請求中 presence_penalty 參數的值。存在懲罰係數,正值增加產生新主題的機率。

top_logprobs integer

回顯原建立響應請求中 top_logprobs 參數的值。每個位置返回的最可能 Token 數量。未啟用時為 0

store boolean

回顯原建立響應請求中 store 參數的值。true 表示該響應已儲存,可被 previous_response_id 引用;false 表示未儲存。

service_tier string

服務等級,固定為 default

background boolean

是否為後台非同步執行的響應。當前百鍊僅支援同步調用,固定為 false

metadata object

回顯原建立響應請求中 metadata 參數的內容。可用於附加自訂索引值對的對象,無設定時為空白對象 {}

錯誤響應

當指定的 Response ID 不存在時,返回以下錯誤:

{
    "error": {
        "message": "Response with id 'resp_xxx' not found.",
        "type": "InvalidParameter"
    }
}