Document processing - Test paper enhancement API
API overview
API name: processDocument
Enhances the clarity and readability of exam paper images and returns the processed image. You can submit one image at a time. The engineType parameter must be set to Enhance and is case-sensitive. This feature supports optional cropping and rotation settings in the inputConfig parameter.
Item | Description |
Request method |
|
Service address |
|
Request format |
|
Authentication method | Request header |
This service is billed under the vertical search category. You are charged for each successful API call. For more information, see Vertical search billing.
API definition
Request parameters
Parameter | Type | Required | Default | Description | Example |
|
| Yes | None | Fixed to |
|
|
| Mutually exclusive with | None | The URL of a downloadable image. We recommend using a public HTTPS URL. | See request example |
|
| Mutually exclusive with | None | The standard Base64 encoding of a single image, without the | Full image Base64 |
|
| No | See sub-fields | Specifies optional settings for cropping and rotation. | See request example |
|
| No |
|
|
|
|
| No |
|
|
|
Image source and configuration rules
Response parameters
For a successful response, the functionOption field is fixed to enhance, and its naming format is different from that of the request capability name.
In the table, [i], [j], and [k] represent the indexes of arbitrary elements in different array layers, are used only to illustrate a field path, and are not fixed indexes or actual returned field names.
Field | Type | Condition | Description |
|
| Always returned | The unique request ID. Provide this ID when contacting technical support for troubleshooting. |
|
| Always returned | Contains information about the processing time. |
|
| Always returned | The time taken for document processing, in milliseconds. |
|
| Always returned | Fixed to |
|
| Always returned | The Base64-encoded string of the enhanced test paper image. |
|
| Optional | Contains information about the output image. |
|
| Optional | The angle of the image. |
|
| Optional | The width of the image in pixels. |
|
| Optional | The height of the image in pixels. |
Result processing: Parse the response JSON, decode the complete Base64 string returned in imageBase64 into binary image data, and then save the data or pass it to an image component for processing. The imageInfo field and its subfields may be omitted, so you should not assume that they are always returned.
Examples
The example image URL is a placeholder. When you make a call, you must replace it with an actual downloadable image URL. The response example illustrates the complete mandatory response structure. The optional imageInfo field is not shown. [Complete Image Base64] is a placeholder for the complete Base64-encoded image and cannot be decoded into an actual image.
Request parameters:
{
"engineType": "Enhance",
"dataUrl": "https://example.com/images/Enhance.png",
"inputConfig": {
"autoCrop": "true",
"autoRotate": "true"
}
}Response parameters:
{
"requestId": "example-request-id",
"searchInformation": {
"searchTime": 120
},
"functionOption": "enhance",
"imageBase64": "[Full_Image_Base64]"
}Calling the API
Use an authorized API Key to authenticate via the X-API-Key request header. The following curl command reads the credential from the API_KEY environment variable. Do not write your actual credentials into the web frontend or public code.
curl -X POST 'https://cloud-iqs.aliyuncs.com/document/process' \
--header "X-API-Key: $API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"engineType": "Enhance",
"dataUrl": "https://example.com/images/Enhance.png",
"inputConfig": {
"autoCrop": "true",
"autoRotate": "true"
}
}'When you use a Base64 image source, replace dataUrl in the request with dataBase64 and pass the complete encoding. Do not provide both non-empty image sources. The call method remains POST JSON.
Error codes
First, check the HTTP status code and the response body format, and then read the error message. A JSON response for a document processing service error contains errorCode and errorMessage. The optional code and message fields have the same meaning. For 403 responses caused by reasons such as permissions or quotas, the presence of these fields is not guaranteed. You should 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 also be non-JSON or empty.
Example of a parameter error:
{
"errorCode": "InvalidParameter",
"errorMessage": "Image too large",
"code": "InvalidParameter",
"message": "Image too large"
}HTTP status code | Error code | Description | Solution |
|
| The image source or a required parameter is missing. | Check |
|
| A parameter is invalid, or the image is too large. | Verify the case of |
|
| The API key is invalid. | Check the |
| See response body | Insufficient permissions or quota. | Verify that the service is activated, your key has the required permissions, and you have sufficient quota. |
| See response body | Unsupported request format. The response body may be empty. | Use |
|
| The request rate is too high. | Reduce your call frequency and implement a retry mechanism with exponential backoff. |
| See response body | Failed to process the image or retrieve the result. | Ensure the image is downloadable and check its content. If the error persists, contact technical support and provide the request ID. |
| See response body | The service is temporarily unavailable. | Try again later. If the issue persists, contact technical support. |
| See response body | An internal service error occurred. | Contact technical support with the request ID and the full error message from the response body. |
If the case of engineType is incorrect or the request body JSON is truncated, the response may be non-JSON text. Check the format of the response body before you read the error fields.