Question recognition API

Updated at:

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

https://cloud-iqs.aliyuncs.com/document/process

Request format

application/json

Authentication method

X-API-Key request header

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

engineType

string

Yes

The value is fixed to RecognizeQuestion and is case-sensitive.

dataUrl

string or null

Either this or dataBase64 is required.

A downloadable image URL. We recommend using a public HTTPS URL.

dataBase64

string or null

Either this or dataUrl is required.

The standard Base64 encoding of a single original image, without the data: prefix. The size of the original image cannot exceed 10 MiB (10,485,760 bytes).

  1. Exactly one of dataUrl and dataBase64 must be a non-empty image source. The unused field can be omitted or set to null, an empty string, or a string containing only ASCII whitespace.

  2. The dataBase64 string 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.

  3. 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

requestId

string

Always

The unique request ID. Provide this ID for troubleshooting.

searchInformation

object

Always

Contains information about the document processing latency.

searchInformation.searchTime

int64

Always

The processing latency in milliseconds.

functionOption

string

Always

Always RecognizeQuestion, matching the engineType in the request.

resultData

string

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

StructureInfo

array<object>

Optional

A list of question blocks.

StructureInfo[i].Position

array<array<number>>

Optional

A numerical matrix representing the position of the question block. The shape is not guaranteed to be a four-vertex polygon.

StructureInfo[i].Detail

array<object>

Optional

Details of the question block content.

StructureInfo[i].Detail[j].InGraph

boolean

Optional

A flag related to graphics.

StructureInfo[i].Detail[j].Type

string

Optional

An identifier for the content type. Process this based on the actual returned value.

StructureInfo[i].Detail[j].Confidence

number

Optional

The confidence score. The API does not guarantee a fixed range for this value.

StructureInfo[i].Detail[j].Position

array<array<number>>

Optional

A numerical matrix representing the position of the detailed element. The shape is not guaranteed to be a four-vertex polygon.

StructureInfo[i].Detail[j].Value

string

Optional

The recognized content of the detailed element.

ImageInfo

array<object>

Optional

The list of recognized image information is located in the parsed resultData.

ImageInfo[i].Angle

number

Optional

The angle of the image.

ImageInfo[i].Height

number

Optional

The height of the image in pixels.

ImageInfo[i].Width

number

Optional

The width of the image in pixels.

ImageInfo[i].ImageBase64

string

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 engineType and provide one non-empty image source.

400

InvalidParameter

A parameter is invalid or the image is too large.

Verify the case of engineType, the mutual exclusion rule for image sources, the Base64 encoding, and the image size. Remove unsupported fields such as inputConfig.

403

Retrieval.InvalidAPIKey

The API key is invalid.

Check the X-API-Key request header and your credential.

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 Content-Type: application/json.

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.

If engineType has an incorrect case (for example, RecognizeQuestion is specified as recognizequestion) or the JSON request body is truncated, a non-JSON text may be returned. Do not directly perform JSON parsing on all error responses.

Related documents