Submit synchronous face comparison tasks

更新时间:
复制 MD 格式

Compares two face images and returns a similarity score, indicating whether the faces belong to the same person.

Operation: /green/image/scan

For request construction details, see Request structure. To use an SDK instead of raw HTTP, see SDK overview.

Billing

Passing two images for a single face comparison is billed once, not twice.

For pricing details, see the Content Moderation pricing page.

Limits

QPS limit

50 calls per second per account. Calls that exceed this limit are throttled.

Timeout

The maximum response time for a synchronous moderation request is 6 seconds. If moderation does not complete within 6 seconds, a timeout error is returned. For workloads without strict real-time requirements, use asynchronous moderation instead. Set your client timeout to 6 seconds when calling this operation.

Image requirements

RequirementLimit
URL schemeHTTP or HTTPS
FormatsPNG, JPG, JPEG, BMP, GIF, WEBP
Max file size20 MB
Download timeout3 seconds
Recommended minimum resolution256 x 256 pixels

If an image fails to download within 3 seconds, a timeout error is returned. For reliable download performance, store images in Object Storage Service (OSS) or a Content Delivery Network (CDN).

Request parameters

For common request parameters required by all Content Moderation API requests, see Common parameters.

The request body is a JSON object with the following fields:

ParameterTypeRequiredExampleDescription
bizTypeStringNodefaultThe business scenario. Create and manage business scenarios in the Content Moderation console. See Customize policies for machine-assisted moderation.
scenesStringArrayYes["sface-1"]The moderation scenario. Valid value: sface-1.
tasksJSONArrayYesThe list of moderation objects. Each element is a task object (see below). Maximum 100 elements per request. To submit 100 tasks in a single request, raise the concurrency limit to more than 100.

task object

ParameterTypeRequiredExampleDescription
dataIdStringNoe6b080a8-a91a-11e8-bac4-6c96cfde2af9A unique identifier for the task within the request.
urlStringYeshttp://www.aliyundoc.com/2015/0826/2015082612403321.jpgThe URL of the first image to compare. Must be an HTTP or HTTPS URL accessible over the internet. Maximum 2,048 characters.
extrasMapNo{"faceUrl":"http://xxx.jpg"}The second image to compare, passed as {"faceUrl": "<second-image-url>"}.
The two images use different parameters: the first image goes in url, and the second goes in extras.faceUrl. Both must be publicly accessible HTTP or HTTPS URLs.

Response parameters

For common response fields, see Common response parameters.

The data field is a JSON array. Each element contains:

ParameterTypeExampleDescription
codeInteger200The HTTP status code. See Common error codes.
msgStringOKThe status message for the request.
dataIdStringe6b080a8-a91a-11e8-bac4-6c96cfde2af9The dataId value from the corresponding request.
taskIdStringimg2hsbmQeA4CU7l78$s8q5mW-1pnn7ZThe moderation task ID.
urlStringhttp://www.aliyundoc.com/2015/0826/2015082612403321.jpgThe URL of the first image from the request.
extrasMapThe extra parameters from the request. This field may change; always use the latest value.
resultsJSONArrayThe moderation results. Contains one or more result objects when code is 200.

result object

ParameterTypeExampleDescription
sceneStringsface-1The moderation scenario. Value: sface-1.
labelStringsface-1The comparison result category. Valid values: normal (low similarity) or sface-1 (high similarity).
suggestionStringreviewThe recommended action. Valid values: pass (low similarity, no further action needed) or review (high similarity, manual review recommended).
rateFloat97.0The face similarity score. Range: 0–100. A higher value indicates greater similarity.

Examples

Request

http(s)://[Endpoint]/green/image/scan
<Common request parameters>

{
  "scenes": ["sface-1"],
  "tasks": [
    {
      "dataId": "e6b080a8-a91a-11e8-bac4-6c96cfde2af9",
      "url": "http://www.aliyundoc.com/2015/0826/2015082612403321.jpg",
      "extras": {
        "faceUrl": "http://www.aliyundoc.com/c/u/2013/0313/1363136852136.jpg"
      }
    }
  ]
}

Response

{
  "code": 200,
  "msg": "OK",
  "requestId": "9EEF894F-A933-4830-97B1-EC1A9630A9D6",
  "data": [
    {
      "code": 200,
      "dataId": "e6b080a8-a91a-11e8-bac4-6c96cfde2af9",
      "taskId": "img2hsbmQeA4CU7l78$s8q5mW-1pnn7Z",
      "url": "http://www.aliyundoc.com/2015/0826/2015082612403321.jpg",
      "extras": {},
      "msg": "OK",
      "results": {
        "label": "sface-1",
        "rate": 97,
        "scene": "sface-1",
        "suggestion": "review"
      }
    }
  ]
}

In this example, suggestion: review and rate: 97 indicate that the two face images have high similarity and likely belong to the same person.

What's next