Document processing - Test paper enhancement API

Updated at:

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

POST

Service address

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

Request format

application/json

Authentication method

Request header X-API-Key

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

engineType

string

Yes

None

Fixed to Enhance. The value is case-sensitive.

Enhance

dataUrl

string or null

Mutually exclusive with dataBase64

None

The URL of a downloadable image. We recommend using a public HTTPS URL.

See request example

dataBase64

string or null

Mutually exclusive with dataUrl.

None

The standard Base64 encoding of a single image, without the data: prefix. The size of the original image after decoding cannot exceed 10 MiB (10,485,760 bytes). This limit applies to the image size in bytes, not the length of the encoded string.

Full image Base64

inputConfig

object

No

See sub-fields

Specifies optional settings for cropping and rotation.

See request example

inputConfig.autoCrop

string

No

"true"

"true": Automatically determines whether to crop; "false": Disables cropping; "force": Forces cropping.

"true"

inputConfig.autoRotate

string

No

"true"

"true": Automatically determines whether to rotate. "false": Disables rotation. "force": Forces rotation.

"true"

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

requestId

string

Always returned

The unique request ID. Provide this ID when contacting technical support for troubleshooting.

searchInformation

object

Always returned

Contains information about the processing time.

searchInformation.searchTime

int64

Always returned

The time taken for document processing, in milliseconds.

functionOption

string

Always returned

Fixed to enhance.

imageBase64

string

Always returned

The Base64-encoded string of the enhanced test paper image.

imageInfo

object

Optional

Contains information about the output image.

imageInfo.angle

int32

Optional

The angle of the image.

imageInfo.width

int32

Optional

The width of the image in pixels.

imageInfo.height

int32

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

400

MissingParameter

The image source or a required parameter is missing.

Check engineType, and provide a non-empty image source.

400

InvalidParameter

A parameter is invalid, or the image is too large.

Verify the case of Enhance, the mutual exclusion of image sources, the Base64 encoding and original image size, and the string enumeration for inputConfig.

403

Retrieval.InvalidAPIKey

The API key is invalid.

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

403

See response body

Insufficient permissions or quota.

Verify that the service is activated, your key has the required permissions, and you have sufficient quota.

415

See response body

Unsupported request format. The response body may be empty.

Use Content-Type: application/json.

429

Retrieval.Throttling.scan (common)

The request rate is too high.

Reduce your call frequency and implement a retry mechanism with exponential backoff.

502

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.

503

See response body

The service is temporarily unavailable.

Try again later. If the issue persists, contact technical support.

500

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.

References