Document processing - Table recognition API
API overview
The processDocument API operation processes a single image to recognize its table text and structure. The response can include details such as the row and column index and span. This operation always uses the RecognizeTable engine.
Item | Description |
request method | POST |
endpoint |
|
request format |
|
authentication method | Request header |
This feature is billed as Vertical Search and charges per successful call. For pricing details, see Vertical Search pricing.
API reference
Request parameters
Parameter | Type | Required | Description |
|
| Yes | The value must be |
|
| Required if | A downloadable image URL. We recommend using a public HTTPS URL. |
|
| Required if | The Base64 encoding of an image, without the |
You must provide exactly one non-empty image source: either
dataUrlordataBase64. You can omit unused fields or set them tonull, an empty string, or a string of only ASCII whitespace.The
dataBase64string can contain ASCII whitespace. After removing the whitespace, the length of the string must be a multiple of 4, and the standard Base64 padding at the end must be preserved. The size limit applies to the decoded source image bytes, not the length of the encoded string.This operation does not support
inputConfig. The request must only contain the fields defined in the table above. Do not include extra fields.
Response parameters
The following are the top-level fields in a successful response.
Field | Type | Returned | Description |
|
| Always | The unique identifier for the request. Provide this ID when you contact technical support. |
|
| Always | Information about the document processing time. |
|
| Always | The document processing time, in milliseconds. |
|
| Always | The value is always |
|
| Always | A JSON-formatted string, not a nested object within the parent response. To access the data, parse the main API response, and then parse this string as a second JSON object. |
resultData fields
Field names are case-sensitive. All fields listed below are optional and their presence depends on the image content. The response may include additional fields not listed here; your client should handle them gracefully. A missing field is not equivalent to a successful recognition. The OcrInfo field can also be null. This operation defines the row and column index and the span, but their presence in the response is not guaranteed for every item.
In the table, [i], [j], and [k] represent the index of an arbitrary element in each level of the array. They are used to illustrate field paths and are not fixed indexes or actual field names in the response.
Field | Type | Returned | Description |
|
| Optional | A list of table text and content blocks, or |
|
| Optional | The recognized text. |
|
| Optional | Details of the recognized content. |
|
| Optional | A flag related to graphics. |
|
| Optional | An identifier for the content type. Handle the returned value accordingly. |
|
| Optional | The column span in the table. |
|
| Optional | The column index in the table. The starting index (0 or 1) is not defined by the API. |
|
| Optional | The row index in the table. The starting index (0 or 1) is not defined by the API. |
|
| Optional | The confidence score. The API does not define a specific range for this value. |
|
| Optional | A matrix of numerical values representing the position. It is not guaranteed to be four vertices. |
|
| Optional | The recognized value of the detail item. |
|
| Optional | The row span in the table. |
|
| Optional | A list of objects containing information about the recognized image. This field is located within 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 encoding of the image. |
Examples
The following examples illustrate the data structure of the request, response, and table details. The image URL is a placeholder; replace it with an actual downloadable image before making a call. The recognition results may vary. The indexes in the example are for demonstration purposes only and do not represent the starting index defined by the API.
Request JSON:
{
"engineType": "RecognizeTable",
"dataUrl": "https://example.com/images/RecognizeTable.png"
}Response JSON:
{
"requestId": "example-request-id",
"searchInformation": {
"searchTime": 120
},
"functionOption": "RecognizeTable",
"resultData": "{\"OcrInfo\":[{\"Text\":\"Order A01\",\"Detail\":[{\"Value\":\"Order A01\",\"ColumnSpan\":1,\"ColumnIndex\":0,\"RowIndex\":0,\"RowSpan\":1}]}],\"ImageInfo\":[ ]}"
}Result of the second JSON parsing of resultData:
{
"OcrInfo": [
{
"Text": "Order A01",
"Detail": [
{
"Value": "Order A01",
"ColumnSpan": 1,
"ColumnIndex": 0,
"RowIndex": 0,
"RowSpan": 1
}
]
}
],
"ImageInfo": [ ]
}API call
Your API Key must have this API enabled. Read the credential from the API_KEY environment variable and pass it in the X-API-Key request header. Do not expose your real credential in front-end web pages or public code. The following curl example uses the same operation 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": "RecognizeTable",
"dataUrl": "https://example.com/images/RecognizeTable.png"
}'When using Base64, replace dataUrl with dataBase64 and pass the complete encoded string. Follow the rules for mutual exclusion of image sources, Base64 padding, and image size limits. The request is still sent as a POST request with a JSON body.
Error codes
First, check the HTTP status code and the format of the response body before reading the error message. A JSON response for a document processing error includes errorCode and errorMessage. The optional code and message fields have the same meaning. For a 403 response related to permissions or quotas, these fields might not all be present. Prioritize reading the actual returned errorCode and errorMessage. If they are missing, fall back to code and message. The requestId is not guaranteed to be returned in all error responses, and the response body might 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 | The image source or a required parameter is missing. | Check the |
400 | InvalidParameter | A parameter is invalid or the image is too large. | Verify the case sensitivity of |
403 | Retrieval.InvalidAPIKey | The API Key is invalid. | Check the |
403 | Varies based on the response | Insufficient permissions or quota. | Verify the API activation status, call permissions, and available quota. |
415 | Varies based on the response | The request format is not supported. The response body may be non-JSON or empty. | Use |
429 | Retrieval.Throttling.scan (common) | Requests are too frequent. | Reduce the call frequency and implement a backoff and retry strategy. |
502 | Varies based on the response | Failed to process the image or retrieve the result. | Check if the image can be downloaded and inspect its content. If the issue persists, provide the request ID to technical support. |
503 | Varies based on the response | The service is temporarily unavailable. | Retry later. If the issue persists, contact technical support. |
500 | Varies based on the response | The service encountered an exception during processing. | Provide the request ID and the error response body to technical support. |
A non-JSON text response may be returned if theengineTypehas a case error (for example, writingRecognizeTableasrecognizetable) or if the JSON request body is truncated. Therefore, do not assume all error responses are JSON; validate the response format before parsing.