Question recognition API
API
The processDocument API recognizes questions and their corresponding question blocks within an image, which allows for per-question processing. This capability uses the fixed engineType value RecognizeQuestion. The response contains the locations and content details of the question blocks, not their solutions.
Item | Description |
Request method | POST |
Endpoint |
|
Request format |
|
Authentication method |
|
This API is billed under Vertical Search, and you are charged for each successful call. For pricing, see Vertical Search Billing Details.
API reference
Request parameters
Parameter | Type | Required | Description |
|
| Yes | The value is fixed to |
|
| Either this or | A downloadable image URL. We recommend using a public HTTPS URL. |
|
| Either this or | The standard Base64 encoding of a single original image, without the |
Exactly one of
dataUrlanddataBase64must be a non-empty image source. The unused field can be omitted or set tonull, an empty string, or a string containing only ASCII whitespace.The
dataBase64string can contain ASCII whitespace. After removing ASCII whitespace, its length must be a multiple of 4, and it must retain the trailing padding required for standard Base64. The size limit applies to the decoded original image bytes, not the length of the encoded string.This capability does not support
inputConfig. The request must only contain the fields defined in the table above. Do not include any extra fields.
Response parameters
A successful response contains the following top-level fields.
Parameter | Type | Returned | Description |
|
| Always | The unique request ID. Provide this ID for troubleshooting. |
|
| Always | Contains information about the document processing latency. |
|
| Always | The processing latency in milliseconds. |
|
| Always | Always |
|
| Always | A JSON-formatted string. To access the data, parse this string as a separate JSON object after parsing the main API response. |
Parsed resultData fields
Field names are case-sensitive. All fields listed below are optional; the actual fields returned depend on the image content. Your client must handle any unlisted fields. A missing field indicates neither a successful recognition nor an empty value. Each item in the StructureInfo array directly contains the Position and Detail objects, without being wrapped in a parent field.
In the table, [i], [j], and [k] represent the index of any element in each array layer. They are used only to illustrate the field path and are not fixed indexes or actual returned field names.
Parameter | Type | Returned | Description |
|
| Optional | A list of question blocks. |
|
| Optional | A numerical matrix representing the position of the question block. The shape is not guaranteed to be a four-vertex polygon. |
|
| Optional | Details of the question block content. |
|
| Optional | A flag related to graphics. |
|
| Optional | An identifier for the content type. Process this based on the actual returned value. |
|
| Optional | The confidence score. The API does not guarantee a fixed range for this value. |
|
| Optional | A numerical matrix representing the position of the detailed element. The shape is not guaranteed to be a four-vertex polygon. |
|
| Optional | The recognized content of the detailed element. |
|
| Optional | The list of recognized image information is located in the parsed |
|
| Optional | The angle of the image. |
|
| Optional | The height of the image in pixels. |
|
| Optional | The width of the image in pixels. |
|
| Optional | The Base64-encoded string of the image. |
Examples
The following examples illustrate the data structures of the request, the response, and the question block position and detail. The image URL is a placeholder and must be replaced with a downloadable URL before making a call. Recognition results may vary. The positions in the example are for demonstration only and do not imply a fixed number of vertices.
Request JSON:
{
"engineType": "RecognizeQuestion",
"dataUrl": "https://example.com/images/RecognizeQuestion.png"
}Response JSON:
{
"requestId": "example-request-id",
"searchInformation": {
"searchTime": 120
},
"functionOption": "RecognizeQuestion",
"resultData": "{\"StructureInfo\":[{\"Position\":[[20,30],[300,30],[300,80],[20,80]],\"Detail\":[{\"Value\":\"1. Calculate 1 + 1.\",\"Position\":[[25,35],[280,35],[280,65],[25,65]]}]}],\"ImageInfo\":[ ]}"
}Result after parsing the resultData string:
{
"StructureInfo": [
{
"Position": [[20, 30], [300, 30], [300, 80], [20, 80]],
"Detail": [
{
"Value": "1. Calculate 1 + 1.",
"Position": [[25, 35], [280, 35], [280, 65], [25, 65]]
}
]
}
],
"ImageInfo": [ ]
}Call the API
Use an API key that is enabled for this API by reading the credential from the API_KEY environment variable and passing it in the X-API-Key request header. Do not write the actual credential in frontend web pages or public code. The following curl command uses the same capability and image URL as the request example. Replace the placeholder image URL before making an actual call.
curl -X POST 'https://cloud-iqs.aliyuncs.com/document/process' \
--header "X-API-Key: $API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"engineType": "RecognizeQuestion",
"dataUrl": "https://example.com/images/RecognizeQuestion.png"
}'When using Base64, replace dataUrl with dataBase64, pass the full encoded string, and follow the image source exclusivity, padding, and original image size limits. The request method is still POST with a JSON body.
Error codes
Check the HTTP status code and the response body format before you read the error information. A JSON response for a document processing service error contains errorCode and errorMessage. The optional code and message fields have the same meaning as errorCode and errorMessage. For 403 responses caused by issues such as permissions or quotas, the presence of these fields is not guaranteed. First, read the returned errorCode and errorMessage. If they are missing, read code and message. The requestId is not guaranteed to be returned in all error responses, and the response body may be non-JSON or empty.
Example of a parameter error:
{
"errorCode": "InvalidParameter",
"errorMessage": "Image too large",
"code": "InvalidParameter",
"message": "Image too large"
}HTTP status | Error code | Description | Solution |
400 | MissingParameter | A required parameter or an image source is missing. | Check the |
400 | InvalidParameter | A parameter is invalid or the image is too large. | Verify the case of |
403 | Retrieval.InvalidAPIKey | The API key is invalid. | Check the |
403 | See response body | Insufficient permissions or quota. | Verify that the API is enabled, your permissions are correct, and you have sufficient quota. |
415 | See response body | The request format is not supported. The body may be empty or not in JSON format. | Use |
429 | Retrieval.Throttling.scan (common) | The request rate is too high. | Reduce your call frequency and implement a backoff and retry strategy. |
502 | See response body | Failed to process the image or retrieve the result. | Check if the image is downloadable and inspect its content. If the issue persists, contact technical support and provide the request ID if available. |
503 | See response body | The service is temporarily unavailable. | Try again later. If the issue persists, contact technical support. |
500 | See response body | The service encountered an internal error. | Contact technical support and provide the request ID and the error response body. |
IfengineTypehas an incorrect case (for example,RecognizeQuestionis specified asrecognizequestion) or the JSON request body is truncated, a non-JSON text may be returned. Do not directly perform JSON parsing on all error responses.