Handwritten document recognition API
1. Overview
The processDocument operation recognizes text and content blocks from a single handwritten document image. For this operation, the engineType parameter must be set to RecognizeWritten.
Item | Description |
Request method | POST |
Service address |
|
Request format |
|
Authentication method | The |
Billing for this operation is based on Vertical Search. You are charged for each successful API call. For pricing, see Vertical Query - billing details.
This service requires activation. Contact your business manager for assistance. You can also apply for activation through the official Q&A channel: Q&A and consultation
2. API definition
Request parameters
Parameter | Type | Required | Description |
|
| Yes | Must be set to |
|
| Mutually exclusive with | A downloadable image URL. We recommend using a public HTTPS URL. |
|
| Mutually exclusive with | The standard Base64 encoding of a single original image, without the |
You must provide a value for exactly one of
dataUrlordataBase64as the image source. You can omit the unused field or set it tonull, an empty string, or a string that contains only ASCII whitespace.The
dataBase64string can contain ASCII whitespace. After removing the whitespace, the string's length must be a multiple of 4, and it must include the required standard Base64 trailing padding. The size limit applies to the decoded bytes of the original image, not the length of the encoded string.This operation does not support
inputConfig. The request must contain only the fields that are defined in the preceding table.
Response parameters
A successful response contains the following top-level fields.
Field | Type | Return rule | Description |
|
| Always returned | The request ID. Provide this ID when you submit a ticket for troubleshooting. |
|
| Always returned | Information about the document processing time. |
|
| Always returned | The document processing time, in milliseconds. |
|
| Always returned | Always returns |
|
| Always returned | A string that contains a JSON object, not a top-level JSON object. After parsing the API response, you must parse this string as a second JSON object. |
Fields in resultData
Field names are case-sensitive. All fields listed below are optional; the actual content depends on the image. Your client must be able to handle additional, unlisted fields. A missing field is not equivalent to an empty string or successful recognition. The OcrInfo field can also be null.
In the table, [i], [j], and [k] represent the indexes of arbitrary elements in each array layer and are used only to illustrate the field path, not as fixed indexes or actual returned field names.
Field | Type | Return rule | Description |
|
| Optional | A list of handwritten text and content blocks, or |
|
| Optional | The recognized text. |
|
| Optional | Detailed information about the recognized content. |
|
| Optional | A flag that indicates whether the content is related to a graphic. |
|
| Optional | A content type identifier. Handle this field based on its value. |
|
| Optional | The confidence score of the recognition result. |
|
| Optional | The position of the content, represented by the coordinates of its four vertices. This field is returned when the result includes a corrected image. |
|
| Optional | The recognized value of the detailed item. |
|
| Optional | A list of information about the recognized image. This field is located inside 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. |
3. Example
The following example shows the data structure of a request and response. The image URL is a placeholder. Replace it with a valid, downloadable image URL before making a call. The recognition results may vary.
Request JSON:
{
"engineType": "RecognizeWritten",
"dataUrl": "https://example.com/images/RecognizeWritten.png"
}Response JSON:
{
"requestId": "example-request-id",
"searchInformation": {
"searchTime": 120
},
"functionOption": "RecognizeWritten",
"resultData": "{\"OcrInfo\":[{\"Text\":\"Order A01\"}],\"ImageInfo\":[ ]}"
}Result after parsing the resultData string:
{
"OcrInfo": [
{
"Text": "Order A01"
}
],
"ImageInfo": [ ]
}4. API call
Use an API key that is enabled for this operation. Read the credential from the API_KEY environment variable and pass it in the X-API-Key request header. Do not hardcode real credentials 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 you make 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": "RecognizeWritten",
"dataUrl": "https://example.com/images/RecognizeWritten.png"
}'When you use Base64, replace dataUrl with dataBase64 and pass the complete encoded string. Adhere to the rules for mutually exclusive image sources, padding, and original image size limits. The call method is still POST with a JSON body.
5. Error codes
First, check the HTTP status code and the format of the response body, and then read the error information. A JSON response for a document processing business error includes errorCode and errorMessage. The optional code and message fields have the same meaning as the first two. A 403 response due to permission or quota issues does not guarantee that all these fields are present. You should prioritize reading the errorCode and errorMessage fields. If they are missing, read the code and message fields instead. The requestId is not guaranteed in all error responses, and the response body may be non-JSON or empty.
Parameter error example:
{
"errorCode": "InvalidParameter",
"errorMessage": "Image too large",
"code": "InvalidParameter",
"message": "Image too large"
}HTTP status | Error code | Description | Solution |
400 | MissingParameter | An image source or a required parameter is missing. | Check the |
400 | InvalidParameter | A parameter is invalid or the image is too large. | Check the case of |
403 | Retrieval.InvalidAPIKey | The API key is invalid. | Check the |
403 | Varies by response | Insufficient permissions or quota. | Verify the service activation status, call permissions, and available quota. |
415 | Varies by response | Unsupported request format. 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 retry. |
502 | Varies by response | Failed to process the image or retrieve the result. | Check whether the image is downloadable and inspect its content. If the issue persists, provide the request ID to technical support. |
503 | Varies by response | The service is temporarily unavailable. | Retry later. If the issue persists, contact technical support. |
500 | Varies by response | An internal service error occurred. | Provide the request ID and the error response body to technical support. |
If the case ofengineTypeis incorrect (for example,recognizewritteninstead ofRecognizeWritten) or the JSON request body is truncated, the service may return a non-JSON text response. Do not attempt to parse all error responses as JSON.