All asynchronous APIs use the same API, /rest/ai/task/queryTaskResult, to query results. After you submit an asynchronous task, you receive a TaskId. Use this API to poll the task status until the Status is COMPLETED or FAILED.
API
POST /rest/ai/task/queryTaskResult
All asynchronous SKUs (such as product material optimization, intelligent image generation, document translation, size chart extraction, and package dimension and weight verification) use this API to poll for results. We recommend a polling interval of at least 5 seconds.
For complete instructions on request signing, SDK examples in multiple languages including Java, Python, and Go, and online debugging, see the Alibaba Cloud OpenAPI Developer Portal: Asynchronous Result Query API (OpenAPI Portal).
Request parameters
|
Parameter |
Type |
Required |
Description |
|
|
String |
Yes |
The task ID returned by the asynchronous task submission API. Example: |
Request example
{
"TaskId": "b67f6089-085a-9402-93c6-bac0561b3a06"
}
Response parameters
|
Parameter |
Type |
Description |
|
|
String |
The response code. A value of |
|
|
Object |
The object containing the result data. |
|
Data. |
String |
The status of the task. Valid values are: |
|
Data. |
String |
Matches the task ID provided in the request. |
|
Data. |
String (JSON) |
The task result, returned as a JSON string. You must parse this string (for example, with |
|
Data. |
String / Object |
Contains usage data. The key in this object varies by SKU. Examples include |
|
|
String |
A unique identifier for the API request. Provide this request ID to technical support for troubleshooting. |
|
|
Boolean |
Indicates whether the request was successful. |
|
|
String |
The response message. If the request is successful, the value is |
Response examples
Success example (image services)
{
"Data": {
"Status": "COMPLETED",
"UsageMap": {
"ProcessedImageCount": "1"
},
"TaskId": "933fa07c-89a7-9607-a1be-37feaacb0e13",
"Result": "{\"message\": {\"Https://alidocs.oss-cn-zhangjiakou.aliyuncs.com/.../0a914347.png\": {\"SizeChart\": [{\"Size\": {\"value\": \"S\"}, \"Waist\": {\"unit\": \"CM\", \"value\": 58}}, {\"Size\": {\"value\": \"M\"}, \"Waist\": {\"unit\": \"CM\", \"value\": 59}}], \"SizeChartAttributes\": [\"Size\", \"SkirtLength\", \"WaistStretched\", \"RecommendedWeight\"], \"IntersectionAttributes\": [\"Size\", \"Waist\"]}}}"
},
"RequestId": "FCF68492-7CEB-1469-9AC9-0149A1F4416E",
"Message": "Success",
"Code": "success",
"Success": true
}
Success example (document services)
{
"Data": {
"Status": "COMPLETED",
"UsageMap": {
"ProcessedDocumentPageCount": "1"
},
"TaskId": "cd98a77e-dfb0-98e0-ba62-615657e8359d",
"Result": "{\"url\": \"https://aidge-bailian-oss.oss-cn-beijing.aliyuncs.com/.../translated_en.pdf?...\"}"
},
"RequestId": "6478F009-C44F-1FAB-BEF4-928E5DAD55B8",
"Message": "Success",
"Code": "success",
"Success": true
}
Failure example
{
"Data": {
"Status": "FAILED",
"TaskId": "7bcd2010-dd79-9b89-9d7f-8c256bf69456",
"Result": "\"usageMap parse error\""
},
"RequestId": "9923C1E4-BACD-1C93-A642-0D4921D374C2",
"Message": "Success",
"Code": "success",
"Success": true
}
Notes
-
A successful API response does not guarantee a successful task: Even if the task itself fails (i.e.,
Data.Statusis FAILED), the API still returnsCode: "success"andSuccess: true. You must check theData.Statusfield to determine the task's outcome. -
Resultmust be parsed: TheData.Resultfield is a JSON string, not a native JSON object. You must parse it (for example, usingJSON.parse) to access its contents. -
Polling interval: A polling interval of 5 seconds or more is recommended. While this query API has no rate limit, the submission APIs have rate limits that vary by SKU. For details, see Rate limits.
-
Troubleshooting: If a task fails, check the
Data.Resultfield for the failure reason and provide theRequestIdto support. For a complete list of error codes, see Error codes.