Document processing - Table recognition API

Updated at:

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

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

request format

application/json

authentication method

Request header X-API-Key

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

engineType

string

Yes

The value must be RecognizeTable. The parameter is case-sensitive.

dataUrl

string or null

Required if dataBase64 is not provided

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

dataBase64

string or null

Required if dataUrl is not provided

The Base64 encoding of an image, without the data: prefix. The maximum decoded image size is 10 MiB (10,485,760 bytes).

  1. You must provide exactly one non-empty image source: either dataUrl or dataBase64. You can omit unused fields or set them to null, an empty string, or a string of only ASCII whitespace.

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

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

requestId

string

Always

The unique identifier for the request. Provide this ID when you contact technical support.

searchInformation

object

Always

Information about the document processing time.

searchInformation.searchTime

int64

Always

The document processing time, in milliseconds.

functionOption

string

Always

The value is always RecognizeTable, which is identical to the engineType in the request.

resultData

string

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

OcrInfo

array<object> or null

Optional

A list of table text and content blocks, or null.

OcrInfo[i].Text

string

Optional

The recognized text.

OcrInfo[i].Detail

array<object>

Optional

Details of the recognized content.

OcrInfo[i].Detail[j].InGraph

boolean

Optional

A flag related to graphics.

OcrInfo[i].Detail[j].Type

string

Optional

An identifier for the content type. Handle the returned value accordingly.

OcrInfo[i].Detail[j].ColumnSpan

number

Optional

The column span in the table.

OcrInfo[i].Detail[j].ColumnIndex

number

Optional

The column index in the table. The starting index (0 or 1) is not defined by the API.

OcrInfo[i].Detail[j].RowIndex

number

Optional

The row index in the table. The starting index (0 or 1) is not defined by the API.

OcrInfo[i].Detail[j].Confidence

number

Optional

The confidence score. The API does not define a specific range for this value.

OcrInfo[i].Detail[j].Position

array<array<number>>

Optional

A matrix of numerical values representing the position. It is not guaranteed to be four vertices.

OcrInfo[i].Detail[j].Value

string

Optional

The recognized value of the detail item.

OcrInfo[i].Detail[j].RowSpan

number

Optional

The row span in the table.

ImageInfo

array<object>

Optional

A list of objects containing information about the recognized image. This field is located within 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 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 engineType and provide one non-empty image source.

400

InvalidParameter

A parameter is invalid or the image is too large.

Verify the case sensitivity of engineType, the mutual exclusion rule for image sources, the Base64 encoding, and the image size. Remove unsupported fields like inputConfig or other extra fields.

403

Retrieval.InvalidAPIKey

The API Key is invalid.

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

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

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 the engineType has a case error (for example, writing RecognizeTable as recognizetable) or if the JSON request body is truncated. Therefore, do not assume all error responses are JSON; validate the response format before parsing.

Related documentation