import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"),
# Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
# API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
base_url="https://ap-southeast-1.maas.qwencloudapi.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": "Hello! Nice to meet you. How can I help you today?",
"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": [],
"tool_usage": {},
"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
}
}Authorizations
DashScope API key.
Path Parameters
The ID of the response to retrieve, in the format resp_xxx. You can obtain it from the create-response API. Only response IDs returned by requests created with store=true can be retrieved.
Response
The unique ID for this response. It is valid for 7 days. You can use this parameter in the previous_response_id parameter to create a multi-turn conversation.
The Unix timestamp in seconds for this request.
The object type. The value is response.
The status of the response generation.
The ID of the model that is used to generate the response.
An array of output items generated by the model. The type and order of elements in the array depend on the model's response.
Show child attributes
Show child attributes
The type of the output item.
message: Contains the final reply content generated by the model.reasoning: Returned when thinking mode (enable_thinking: true) is enabled. Reasoning tokens are counted inoutput_tokens_details.reasoning_tokensand are billed as reasoning tokens.function_call: Returned when a user-defined function tool is used. You need to handle the function call and return the result.web_search_call: Returned when theweb_searchtool is used.code_interpreter_call: Returned when thecode_interpretertool is used.web_extractor_call: Returned when theweb_extractortool is used. It must be used with theweb_searchtool.web_search_image_call: Returned when theweb_search_imagetool is used. It contains a list of searched images.image_search_call: Returned when theimage_searchtool is used. It contains a list of similar images.mcp_call: Returned when themcptool is used. It contains the result of the MCP service call.file_search_call: Returned when thefile_searchtool is used. It contains the search query and results from the knowledge base.
The unique identifier for the output item. This field is included in all types of output items.
The role of the message. The value is assistant. This field exists only when the type is message.
The status of the output item.
The tool or function name. This field exists when the type is function_call, web_search_image_call, image_search_call, or mcp_call. For web_search_image_call and image_search_call, the values are fixed as web_search_image and image_search, respectively. For mcp_call, the value is the specific function name called in the MCP service, such as amap-maps-maps_geo.
The arguments for the tool call, in JSON string format. This field exists when the type is function_call, web_search_image_call, image_search_call, or mcp_call. You need to parse it using JSON.parse() before use.
Arguments content by tool type:
web_search_image_call:{"queries": ["search term 1", "search term 2"]}, where queries is a list of search terms auto-generated by the model.image_search_call:{"img_idx": 0, "bbox": [0, 0, 1000, 1000]}, whereimg_idxis the index of the input image (starting from 0), andbboxis the bounding box coordinates[x1, y1, x2, y2]for the search area, with a range of 0-1000.function_call: An argument object generated according to the schema of the user-defined function parameters.mcp_call: An argument object for the function called in the MCP service.
The unique identifier for the function call. This field exists only when the type is function_call. When returning the function call result, you must use this ID to associate the request with the response.
An array of message content. This field exists only when the type is message.
The search action information. This field exists only when the type is web_search_call.
The code that is generated and executed by the model. This field exists only when the type is code_interpreter_call.
The identifier for the code interpreter container. This field exists only when the type is code_interpreter_call. It is used to associate multiple code executions within the same session.
A description of the extraction goal that explains what information needs to be extracted from the web page. This field exists only when the type is web_extractor_call.
The output result of the tool call, in string format.
- When type is
web_extractor_call, this is the summary of the extracted web content. - When type is
web_search_image_callorimage_search_call, this is a JSON string containing an array of image search results. Each element contains atitlefield (image title), aurlfield (image URL), and anindexfield (sequence number). - When type is
mcp_call, this is the JSON string result returned by the MCP service.
A list of URLs of the extracted web pages. This field exists only when the type is web_extractor_call.
The MCP service label. This field exists only when the type is mcp_call. It identifies the MCP service used for this call.
The list of queries used for knowledge base retrieval. This field exists only when the type is file_search_call. Array elements are strings representing search queries generated by the model.
An array of knowledge base retrieval results. This field exists only when the type is file_search_call.
Whether parallel tool calls are enabled.
The value of the tool_choice parameter from the echo request. Valid values are auto, none, and required.
The complete content of the tools parameter from the echo request. The structure is the same as the tools parameter in the request body.
Tool usage statistics for this request, recorded separately from model token usage in usage. When no tools are called, this field defaults to an empty object {}.
Show child attributes
Show child attributes
Usage of the code interpreter tool.
Show child attributes
Show child attributes
The number of code interpreter executions.
Usage of the web page extraction tool.
Show child attributes
Show child attributes
The number of web page content extraction requests.
Usage of the image-to-image search tool.
Show child attributes
Show child attributes
The number of image-to-image searches.
Usage of the text-to-image search tool.
Show child attributes
Show child attributes
The number of text-to-image searches.
The token consumption information for this request.
Show child attributes
Show child attributes
The number of input tokens.
The number of tokens that are output by the model.
The total number of tokens consumed. This is the sum of input_tokens and output_tokens.
The fine-grained categorization of input tokens.
Show child attributes
Show child attributes
The number of tokens that hit the cache.
The fine-grained categorization of output tokens.
Show child attributes
Show child attributes
The number of tokens in the thinking process.
Detailed token breakdown by billing type.
Show child attributes
Show child attributes
The number of input tokens.
The number of tokens output by the model.
The total number of tokens consumed, the sum of input_tokens and output_tokens.
Fixed as response_api.
The number of image input tokens. Returned when image input is included, equivalent to input_tokens_details.image_tokens.
Fine-grained classification and cache details of input tokens. Returned for multimodal input or when Session cache is enabled.
Show child attributes
Show child attributes
The number of text input tokens.
The number of image input tokens.
The number of cache-hit tokens.
The number of tokens for which a new cache entry was created in this request.
Cache creation details.
Show child attributes
Show child attributes
The number of tokens created for the 5-minute ephemeral cache.
The cache type. Fixed as ephemeral.
Statistical information about tool usage. If built-in tools are used, this field includes the number of calls for each tool. Example: {"web_search": {"count": 1}}