This topic describes how to integrate the DocOcr API operation on the server side. You can call this operation to automatically extract information from ID document images and check for spoofing threats.
API description
API operation name: DocOcr
Request method: HTTPS POST
Description: Call the DocOcr API operation to automatically extract information from various ID documents, such as passports and ID cards, and perform anti-spoofing checks using Optical Character Recognition (OCR) technology.
QPS limit: The API has a dedicated queries per second (QPS) limit. For more information, see QPS limits for ID Verification server-side API operations.
Endpoint:
NoteThe internal network is used for communication between Alibaba Cloud products in the same region. If your server is deployed in an Alibaba Cloud region, you can use the internal endpoint to access the ID Verification service. This provides more secure and stable network communication.
China (Hong Kong)
Internet:
cloudauth-intl.cn-hongkong.aliyuncs.comInternal:
cloudauth-intl-vpc.cn-hongkong.aliyuncs.com
Online debugging and integration
Before you start debugging and integration, ensure that you read the Use OpenAPI Explorer to debug and integrate server-side APIs document to understand how to call APIs in OpenAPI Explorer and obtain SDKs and their code.
You can debug this API operation in OpenAPI Explorer and generate SDK sample code for it.
Image format requirements
To ensure stable model performance, make sure that the uploaded images meet all the following requirements:
Image format: JPG, JPEG, or PNG.
Image size: The recommended size is 50 KB to 100 KB. The maximum size is 1 MB.
NoteAfter an image is converted to the base64 format, its data size typically increases. To pass parameters in base64 format, ensure that the original image size does not exceed 0.6 MB to meet the maximum data transmission limit of 1 MB.
Image resolution: The height and width of the image must be greater than 200 pixels and less than 8192 pixels. A resolution of 480 × 640 pixels (H × W) is recommended.
Image quality recommendations:
The four corners of the ID card image must be complete. Do not hold the ID card in a way that obstructs the corners. Obstructing the corners can affect detection.
The content of the ID card image must be clear, unobstructed, and free of overexposure. The ID card image must be oriented correctly. Do not tilt or invert it.
The ID card image should occupy more than 60% of the total image area. Using images where the card face is too small can affect recognition.
We recommend that you take photos of real ID documents.
Request parameters
You can provide the photo using one of the following two parameters.
IdOcrPictureBase64
IdOcrPictureUrl
Name | Type | Required | Description | Example |
ProductCode | String | Yes | The product plan to use. Set the value to ID_OCR_MIN to use the ID document OCR API. | ID_OCR_MIN |
SceneCode | String | No | A custom ID for the authentication scenario. You can use this ID to query related records in the console. The ID can be up to 10 characters in length and can contain letters, digits, and underscores (_). | 1234567890 |
MerchantBizId | String | Yes | A custom unique business ID used to track and troubleshoot issues. The ID can be up to 32 characters in length and can contain letters and digits. Make sure that the ID is unique. Note Alibaba Cloud servers do not check the uniqueness of this value. For better tracking, we strongly recommend that you ensure the uniqueness of this field. | e0c34a77f5ac40a5aa5e6ed20c35**** |
MerchantUserId | String | Yes | A custom user ID or another identifier for a specific user, such as a mobile phone number or email address. We strongly recommend that you desensitize this value in advance, for example, by hashing it. | 123456789 |
IdOcrPictureBase64 | String | Yes | The base64-encoded image of the portrait side of the ID document. If you choose to provide the ID document photo using IdOcrPictureBase64 (base64-encoded photo), check the photo size. Do not provide an oversized photo. | base64 |
IdOcrPictureUrl | String | Yes | The URL of the image of the portrait side of the ID document. The URL must be an HTTP or HTTPS link that is accessible over the Internet. | https://*** |
DocType | String | Yes | The type of the ID document. It is a unique identifier composed of 8 digits. For more information, see List of document types. | F |
Ocr | String | Yes | Specifies whether to enable the OCR feature to automatically extract document information.
| T |
IdFaceQuality | String | No | Specifies whether to return the quality score of the face on the ID document. This feature is disabled by default. Note This parameter is valid only for the portrait side of the ID document.
| F |
Spoof | String | No | Specifies whether to enable the anti-spoofing feature for the ID document. This feature is disabled by default. Note This parameter is valid only for the portrait side of the ID document.
| F |
IdThreshold | String | No | The custom OCR quality detection threshold mode:
| 3 |
CardSide | String | No | Specifies the side of the ID document. If you do not pass this parameter, the portrait side is used by default.
Important This parameter applies only to resident identity cards of the People's Republic of China. | OCR_ID_NATIONAL_EMBLEM |
List of document types
DocType | Corresponding document |
01000000 | Global passport |
00000006 | Hong Kong identity card (2003 edition) |
00000008 | Hong Kong identity card (2018 edition) |
00000007 | Exit-Entry Permit for Travelling to and from Hong Kong and Macao |
00000009 | Mainland Travel Permits for Hong Kong and Macao Residents |
000000011 | Macao identity card |
000000012 | Mainland Travel Permit for Taiwan Residents |
00000001 | Second-generation resident identity card of the Chinese mainland |
Response parameters
Name | Type | Description | Example | |
HTTP Status Code | Integer | The HTTP status code. | 200 | |
HTTP Body | RequestId | String | The request ID. | 130A2C10-B9EE-4D84-88E3-5384FF039**** |
Result.TransactionId | String | The unique ID for the entire authentication process. | hksb7ba1b28130d24e015d694361b**** | |
Code | String | Success | ||
Message | String | A detailed description of the response code. | success | |
Result.Passed | String | The authentication result. Valid values:
| Y | |
Result.SubCode | String | A description of the authentication result. For more information, see ResultObject.SubCode error codes. | 200 | |
Result.ExtIdInfo | String | Information about the ID document recognition result. For the JSON format, see the example on the right. For more information, see ExtIdInfo. | | |
ExtIdInfo
Name | Type | Description | Example |
ocrIdInfo | String | The OCR fields of the ID document. For more information, see OCR recognition response fields. Note If the ID document OCR process fails, this field is empty. | |
idFaceQualityScore | Double | The quality score of the face in the uploaded ID document image. The value ranges from 0 to 100. | 99.95 |
spoofInfo | String | The result of anti-counterfeiting detection, including the risk identification result and risk type: Note Card detection is enabled only when you set IdSpoof = Y in the Initialize operation. Otherwise, spoofResult returns N by default, and spoofType is empty.
| |
Status codes
HTTP status code | Code | Message description |
200 | Success | Request successful. |
400 | MissingParameter | Parameter cannot be empty. |
InvalidParameter | Invalid parameter. | |
401 | UnqualifiedPhoto | The uploaded image is unreadable or the image resolution does not meet requirements. We recommend changing the image. Ensure the photo is clear, has normal exposure, is complete without occlusion, and has no significant angle deviation. |
DataDuplication | Both Base64-encoded image and URL image address are provided. Choose only one of these parameters. | |
ToolargeImage | The image size is too large. We recommend compressing the image or changing the upload method. | |
DownloadTimeout | URL image download timeout. | |
403 | Forbidden.RAMUserAccessDenied | You need to grant the RAM user the AliyunAntCloudAuthFullAccess permission. For more information, see Authorize RAM users to access the service. |
Forbidden.AccountAccessDenied | Ensure that you have activated ID verification and your account has no overdue payment. | |
Throttling.Api | API request is blocked due to throttling. | |
500 | InternalError | Internal system error. Provide feedback to engineers for troubleshooting. |
ResultObject.SubCode error codes
Subcode is returned based on different product solutions or integration methods. For details, refer to the following table.
Applicable solution | Error code | Is authentication record billed | Description and suggested reasons |
General | 200 | Yes | Authentication passed. |
| 211 | Yes | The quality or resolution of the certificate image does not meet requirements, or the image itself is incomplete. Ensure the photo of the certificate's portrait side is clear, has normal exposure, is complete without occlusion, and has no significant angle deviation. |
| 212 | Yes | Certificate anti-counterfeiting detection indicates risk. There may be high-risk operations such as rephotographing, tampering, or photocopying. |
| 213 | Yes | The specified certificate type was not detected (recognition mode) or the certificate type could not be identified (classification mode). We recommend uploading a clear, complete certificate image with normal angle. |
Field returned by document recognition
Hong Kong (China) Identity Card
Both the 2003 and 2018 versions of smart identity cards are supported.
Field | Type | Description |
name | String | The name. |
englishName | String | The name in English. |
nameCode | String | The Chinese name code. |
sex | String | The gender. Valid values:
|
birthDate | String | The date of birth. |
idNumber | String | The ID card number. |
currentIssueDate | String | The date of registration. |
firstIssueDate | String | The month and year of first registration. |
isPermanent | String | Indicates whether the identity card is a permanent resident identity card. Valid values:
|
symbols | String | The remarks. Example: "***AZ". |
Exit-Entry Permit for Traveling to and from Hong Kong and Macao
Field | Type | Description |
name | String | The name. |
englishName | String | The romanized name. |
sex | String | The gender. |
birthDate | String | The date of birth. |
idNumber | String | The ID card number. |
issueDate | String | The issuance date. |
expiryDate | String | The expiration date. |
placeOfIssue | String | The issuance place. |
originOfIssue | String | The issuance authority. |
Mainland Travel Permit for Hong Kong and Macao Residents
Field | Type | Description |
name | String | The name. |
englishName | String | The romanized name. |
sex | String | The gender. |
birthDate | String | The date of birth. |
idNumber | String | The ID card number. |
issueDate | String | The issuance date. |
expiryDate | String | The expiration date. |
originOfIssue | String | The issuance authority. |
Mainland Travel Permit for Taiwan Residents
Field | Type | Description |
name | String | The name. |
englishName | String | The romanized name. |
sex | String | The gender. |
birthDate | String | The date of birth. |
idNumber | String | The ID card number. |
issueDate | String | The issuance date. |
expiryDate | String | The expiration date. |
originOfIssue | String | The issuance authority. |
placeOfIssue | String | The issuance place. |
Global passport
Field | Type | Description |
surname | String | The surname. |
givenname | String | The given name. |
sex | String | The gender. |
birthDate | String | The date of birth. |
passportNo | String | The passport number. |
nationality | String | The nationality. |
expiryDate | String | The expiration date. |
countryCode | String | The country code. |
Macao (China) Resident Identity Card
Field | Type | Description |
surnameCN | String | The surname in Chinese. |
givennameCN | String | The given name in Chinese. |
surname | String | The surname in English. |
givenname | String | The given name in English. |
sex | String | The gender. |
birthDate | String | The date of birth. |
idNumber | String | The ID card number. |
expiryDate | String | The expiration date. |
placeOfBirth | String | The code of the birthplace. Example: "AS". |
People's Republic of China Resident Identity Card
Field | Type | Description |
name | String | The name. |
sex | String | The gender. |
ethnicity | String | The ethnicity. |
birthDate | String | The date of birth. |
idNumber | String | The ID card number. |
address | String | The address. |
province | String | The province of residence. Note This is a reserved field and is empty by default. |
city | String | The city of residence. Note This is a reserved field and is empty by default. |
originOfIssue | String | The issuance authority. |
issueDate | String | The issuance date. |
expiryDate | String | The expiration date. |