import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
response = client.responses.retrieve("resp_xxx")
print(response){
"background": false,
"completed_at": 1778676420,
"created_at": 1778676418,
"frequency_penalty": 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,
"service_tier": "default",
"status": "completed",
"store": true,
"temperature": 1,
"tool_choice": "auto",
"tools": [],
"top_logprobs": 0,
"top_p": 1,
"usage": {
"input_tokens": 45,
"input_tokens_details": {
"cached_tokens": 0
},
"output_tokens": 63,
"output_tokens_details": {
"reasoning_tokens": 0
},
"total_tokens": 108
}
}鉴权
千问云 API Key。详见获取 API Key。
路径参数
要获取的 Response ID,格式为 resp_xxx。可从创建响应接口的响应中获取。仅当原创建请求中 store=true 时返回的 Response ID 可被检索。
响应
本次响应的唯一 ID,有效期为 7 天。可将此 ID 传入 previous_response_id 参数以实现多轮对话。
本次请求的 Unix 时间戳(秒)。
对象类型。值为 response。
响应生成的状态。
生成本次响应所使用的模型 ID。
模型生成的输出项数组。数组中元素的类型和顺序取决于模型的响应。
显示子属性
显示子属性
输出项的类型。
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 服务调用的结果。file_search_call:使用file_search工具时返回,包含搜索查询和知识库检索结果。
输出项的唯一标识符,所有类型的输出项均包含此字段。
消息角色。值为 assistant。仅当 type 为 message 时存在此字段。
输出项的生成状态。
工具或函数名称。当 type 为 function_call、web_search_image_call、image_search_call 或 mcp_call 时存在此字段。对于 web_search_image_call 和 image_search_call,值固定为 web_search_image 和 image_search。对于 mcp_call,值为 MCP 服务中调用的具体函数名,例如 amap-maps-maps_geo。
工具调用的参数,为 JSON 字符串格式。当 type 为 function_call、web_search_image_call、image_search_call 或 mcp_call 时存在此字段。使用前需通过 JSON.parse() 解析。
各工具类型的参数内容:
web_search_image_call:{"queries": ["search term 1", "search term 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 服务中调用的函数的参数对象。
函数调用的唯一标识符。仅当 type 为 function_call 时存在此字段。返回函数调用结果时,必须使用此 ID 关联请求与响应。
模型生成并执行的代码。仅当 type 为 code_interpreter_call 时存在此字段。
代码解释器容器的标识符。仅当 type 为 code_interpreter_call 时存在此字段。用于在同一会话中关联多次代码执行。
提取目标的描述,说明需要从网页中提取哪些信息。仅当 type 为 web_extractor_call 时存在此字段。
工具调用的输出结果,为字符串格式。
- 当 type 为
web_extractor_call时,为提取的网页内容摘要。 - 当 type 为
web_search_image_call或image_search_call时,为包含图片搜索结果数组的 JSON 字符串。每个元素包含title字段(图片标题)、url字段(图片 URL)和index字段(序号)。 - 当 type 为
mcp_call时,为 MCP 服务返回的 JSON 字符串结果。
已抓取网页的 URL 列表。仅当 type 为 web_extractor_call 时存在此字段。
MCP 服务标签。仅当 type 为 mcp_call 时存在此字段,用于标识本次调用使用的 MCP 服务。
用于知识库检索的查询列表。仅当 type 为 file_search_call 时存在此字段。数组元素为模型生成的搜索查询字符串。
是否启用了并行工具调用。
请求中 tool_choice 参数的回显值。有效值为 auto、none 和 required。
请求中 tools 参数的完整内容回显。结构与请求体中的 tools 参数相同。
本次请求的 Token 消耗信息。
显示子属性
显示子属性
输入 Token 数量。
模型输出的 Token 数量。
消耗的 Token 总数,即 input_tokens 与 output_tokens 之和。
工具使用的统计信息。如使用了内置工具,此字段包含每个工具的调用次数。示例:{"web_search": {"count": 1}}

