Synchronous detection
This topic describes the API operations and parameters for submitting synchronous image detection tasks to perform liveness detection. You can use this information to build HTTP requests in your program.
Usage notes
API operation: /green/image/scan
Call this operation to submit a synchronous image detection task. The task performs liveness detection to determine whether a live object, such as a face, in an image is from a direct shot or a screen replay. To learn how to construct an HTTP request, see Request structure. You can also use a pre-constructed HTTP request. For more information, see SDK overview.
This is a paid API operation. For more information about billing, see Content Moderation Pricing.
Detection time limit
The maximum detection time for a synchronous call is 6 seconds. If the detection does not complete within this time, the system returns a timeout error. If real-time results are not critical, use asynchronous detection. Otherwise, use synchronous detection, which is simpler to call. For synchronous calls, set the timeout period to 6 seconds.
-
The image URL must use the HTTP or HTTPS protocol.
-
Supported image formats: PNG, JPG, JPEG, BMP, GIF, and WEBP.
-
The image size cannot exceed 20 MB for both synchronous and asynchronous calls. The height or width cannot exceed 30,000 pixels (px), and the total number of pixels cannot exceed 250 million (px).
NoteFor GIF images, the total number of pixels cannot exceed 4,194,304 (px), and the height or width cannot exceed 30,000 pixels (px).
-
The image must be downloaded within 3 seconds. If the download time exceeds 3 seconds, a download timeout error is returned.
-
For optimal performance, we recommend that the image resolution be at least 256x256 pixels. A lower resolution may affect the detection accuracy.
-
The response time of the image detection API depends on the image download time. Ensure that the storage service where the image is stored is stable and reliable. For best performance, use Alibaba Cloud Object Storage Service (OSS) or a Content Delivery Network (CDN).
QPS limit
The queries per second (QPS) limit for this API is 50 per user. Exceeding this limit triggers throttling, which can impact your business. Plan your calls accordingly.
Request parameters
For more information about the common request parameters that must be included in a request, see Common parameters.
| Name | Type | Required | Example | Description |
| bizType | String | No | default | This field identifies your business scenario. You can create a business scenario in the Content Moderation console. For more information, see Customize moderation rules. |
| scenes | StringArray | Yes | ["liveness"] | The application scenario for image detection. The only valid value is liveness. |
| tasks | JSONArray | Yes | The detection objects. Each element in this JSON array is a detection task struct. You can specify up to 100 elements. To submit 100 elements at a time, you must set the number of concurrent tasks to more than 100. For more information about the structure of each element, see task. |
| Name | Type | Required | Example | Description |
| dataId | String | No | test2NInmO$tAON6qYUrtCRgLo-1mwxdi | The data ID. Ensure that all IDs in a single request are unique. |
| url | String | Yes | https://example.com/tfs/TB1urBOQFXXXXbMXFXXXXXXXXXX-1442-257.png | The URL of the image to detect. |
Returned data
For more information about the response, see Response parameters.
| Name | Type | Example | Description |
| code | Integer | 200 | The error code. It is the same as the HTTP status code. For more information, see Common error codes. |
| msg | String | OK | The response message for the request. |
| dataId | String | test2NInmO$tAON6qYUrtCRgLo-1mwxdi | Corresponds to the dataId in the request. |
| taskId | String | img2hsbmQeA4CU7l78$s8q5mW-1pnn7Z | The ID of the detection task. |
| url | String | https://example.com/tfs/TB1urBOQFXXXXbMXFXXXXXXXXXX-1442-257.png | Corresponds to the URL in the request. |
| extras | Map | xxx | Additional information. This value is subject to change. Do not create a business dependency on it. |
| results | JSONArray | The detection results. When the call is successful (code=200), the results contain one or more elements. Each element is a struct. For a description of the structure, see result. |
| Name | Type | Example | Description |
| scene | String | liveness | The risk scenario. The only valid value is liveness. |
| label | String | liveness | The classification of the detection result. Valid values:
|
| suggestion | String | review | The recommended action. Valid values:
|
| rate | Float | 97.0 | The probability that the result belongs to this classification. The value ranges from 0.00 to 100.00. A higher value indicates a higher probability. |
| livenessData | JSONObject | The liveness detection information returned when the result is a replay (label=liveness). For a description of the structure, see livenessData. |
| Name | Type | Example | Description |
| rate | Float | 97.0 | The probability that the liveness photo is a recaptured photo. A higher score indicates a higher probability. |
Examples
http(s)://[Endpoint]/green/image/scan
&<Common request parameters>
{
"scenes": ["liveness"],
"tasks": [
{
"dataId": "test2NInmO$tAON6qYUrtCRgLo-1mwxdi",
"url": "https://example.com/tfs/TB1urBOQFXXXXbMXFXXXXXXXXXX-1442-257.png"
}
]
}{
"code": 200,
"msg": "OK",
"requestId": "9EEF894F-A933-4830-97B1-EC1A9630A9D6",
"data": [{
"code": 200,
"dataId": "test2NInmO$tAON6qYUrtCRgLo-1mwxdi",
"taskId": "img2hsbmQeA4CU7l78$s8q5mW-1pnn7Z",
"url": "https://example.com/tfs/TB1urBOQFXXXXbMXFXXXXXXXXXX-1442-257.png",
"msg": "OK",
"results": {
"label": "liveness",
"rate": 97.0,
"scene": "liveness",
"suggestion": "review",
"livenessData": {
"rate": 97.0
}
}
}]
}