Skip to main content
OpenAI相容-Responses

擷取輸入項列表

擷取產生指定 Response 時所使用的輸入項列表。在多輪對話(使用 previous_response_id 串聯)中,會一併返回歷史輪次的使用者輸入和模型回複。僅當原建立請求中 store=true 時,返回的 Response ID 才支援查詢。

調用時請將{WorkspaceId}替換為真實的業務空間ID
  • 华北2(北京)
SDK 調用配置的base_urlhttps://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1HTTP 要求地址:GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/responses/{response_id}/input_items

路徑參數

response_idstring(必選)要查詢輸入項的 Response ID,格式為 resp_xxx。僅當原建立請求中 store=true 時,返回的 Response ID 才支援查詢。

查詢參數

afterstring(可選)以指定的 item ID(格式為 msg_xxx)作為起點,返回排在該 ID 之後的資料,順序由 order 決定。item ID 來源建立響應返回的 output[].id;或本介面返回的 data[].idfirst_idlast_id。常用於翻頁:把上一次返回的 last_id 作為本次的 after 傳入,即可繼續擷取後續資料。limitinteger(可選)返回的最大條數,取值範圍 [1, 100],預設值為 20。orderstring(可選)排序方式,支援 asc(升序)和 desc(降序),預設值為 desc
  • 預設查詢
  • 按條件查詢
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.input_items.list("resp_xxx")
print(response.data)

返回結果

data array輸入項列表。每個元素是一個訊息對象,包含 idrolecontenttypestatus 欄位。role 取值為 userassistantcontent 中元素的 type 取值為 input_text(使用者輸入)或 output_text(模型回複)。多輪對話(使用 previous_response_id 串聯)中,會按發生順序包含歷史使用者訊息與歷史模型回複。first_id string列表中第一個元素的 ID。last_id string列表中最後一個元素的 ID。has_more boolean是否還有未返回的資料。當為 true 時,把本次返回的 last_id 作為下一次請求的 after 參數,可繼續擷取後續資料。id string對應的 Response ID。model string產生該 Response 時使用的模型名稱。created_at integerResponse 建立時間的 Unix 時間戳記(毫秒)。注意:與"建立響應/檢索響應"介面返回的 created_at(秒)單位不同。previous_response_id string多輪對話(使用 previous_response_id 串聯)時返回,值為上一輪的 Response ID。
{
    "created_at": 1778674066000,
    "data": [
        {
            "content": [
                {
                    "text": "你好",
                    "type": "input_text"
                }
            ],
            "id": "msg_8dac4972-fdba-42b5-bed9-280441ced8ea",
            "role": "user",
            "status": "completed",
            "type": "message"
        }
    ],
    "first_id": "msg_8dac4972-fdba-42b5-bed9-280441ced8ea",
    "has_more": false,
    "id": "resp_4ca7fa5e-6ff5-9787-bc18-af6ca5eff36c",
    "last_id": "msg_8dac4972-fdba-42b5-bed9-280441ced8ea",
    "model": "qwen3.8-max"
}

錯誤響應

當指定的 Response ID 不存在時,返回以下錯誤:
{
    "request_id": "339b771548c7fbb15717316b49627681",
    "code": "InvalidParameter",
    "message": "Response with id 'resp_xxx' not found."
}