Submit asynchronous face comparison tasks

更新时间:
复制 MD 格式

Submits a 1:1 face comparison task to /green/image/asyncscan and retrieves results from /green/image/results. Face comparison detects the similarity between two face images and returns a similarity score with a moderation suggestion.

Operation 1: Submit a face comparison task

Endpoint: POST /green/image/asyncscan

Submits asynchronous image moderation tasks for face comparison. To construct an HTTP request, see Request structure. Alternatively, use an existing SDK — see SDK overview.

Billing

Each face comparison counts as one billable call, regardless of the number of images passed in. Passing two images for a single comparison is billed once.

How it works

Submit a task with two image URLs — one in url and one in extras.faceUrl. Content Moderation processes the comparison asynchronously and holds results for up to 1 hour.

To retrieve results, either:

  • Callback (push): Specify the callback parameter in the request. Content Moderation pushes results to your endpoint automatically.

  • Polling: Omit callback. After submission, call /green/image/results to poll for results. Wait at least 30 seconds before your first poll.

Usage notes

Image requirements:

  • URLs must use HTTP or HTTPS.

  • Supported formats: PNG, JPG, JPEG, BMP, GIF, WEBP.

  • Maximum file size: 20 MB.

  • Download timeout: 3 seconds. Images that fail to download within 3 seconds return a timeout error.

  • Minimum recommended resolution: 256 × 256 pixels.

  • Store images on a reliable service such as Object Storage Service (OSS) or a Content Delivery Network (CDN) to avoid download failures.

Asynchronous behavior:

  • Results are not returned in the submission response. Use callback or polling to retrieve them.

  • Results are retained for up to 1 hour.

Response timeout for synchronous requests:

  • The maximum response time for a synchronous moderation request is 6 seconds. If moderation is not completed within 6 seconds, a timeout error is returned. We recommend setting the timeout period to 6 seconds when calling synchronous moderation operations.

QPS limit

50 calls per second per account. Exceeding this limit triggers throttling.

Request parameters

ParameterTypeRequiredExampleDescription
bizTypeStringNodefaultThe business scenario. Create and manage scenarios in the Content Moderation console. For details, see Customize policies for machine-assisted moderation.
scenesStringArrayYes["sface-1"]The detection scenario. Valid value: sface-1 (face comparison).
callbackStringNohttp://www.aliyundoc.com/xx.jsonThe callback URL for receiving asynchronous moderation results. Supports HTTP and HTTPS. If omitted, poll /green/image/results for results. The callback endpoint must support POST requests, UTF-8 encoding, and the checksum and content parameters. See Callback details below.
seedStringNoaabbcc123A random string used to generate the callback request signature. Maximum 64 characters; letters, digits, and underscores only. Required when callback is set.
cryptTypeStringNoSHA256The encryption algorithm for callback notifications. Valid values: SHA256 (HMAC-SHA256, default), SM3 (HMAC-SM3, returns a lowercase hexadecimal string).
tasksJSONArrayYesThe list of moderation tasks. Maximum 100 elements per request. To submit 100 images at a time, you must raise the relevant concurrency limit to a number greater than 100. Each element follows the task structure below.

task structure:

ParameterTypeRequiredExampleDescription
dataIdStringNoe6b080a8-a91a-11e8-bac4-6c96cfde2af9A unique identifier for the moderation object in your system. Maximum 128 characters; letters, digits, hyphens (-), underscores (_), and periods (.). Echoed in the response.
urlStringYeshttp://www.aliyundoc.com/2015/0826/2015082612403321.jpgThe URL of the first image. Must be publicly accessible via HTTP or HTTPS. Maximum 2,048 characters.
extrasJSONObjectNo{"faceUrl":"http://www.aliyundoc.com/c/u/2013/0313/1363136852136.jpg"}The second image for comparison. Format: {"faceUrl":"<image-url>"}.

Callback details

When Content Moderation pushes a callback notification, it includes two parameters:

  • `checksum`: A signature string generated as SHA-256(UID + Seed + Content). UID is your Alibaba Cloud account ID (not a RAM user ID), which you can find in the Alibaba Cloud Management Console. Verify this signature on your server to detect tampering.

  • `content`: A JSON-encoded string containing the moderation result. The format matches the response from /green/image/results.

If your server returns HTTP 200, Content Moderation considers the notification delivered. If your server returns any other status, Content Moderation retries delivery up to 16 times. After 16 failed attempts, delivery stops — check your callback endpoint if this occurs.

When cryptType is SM3, Content Moderation uses HMAC-SM3 and returns a lowercase hexadecimal string. For example, encrypting abc produces 66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0.

Response parameters

ParameterTypeExampleDescription
codeInteger200The HTTP status code. For a full list, see Common error codes.
msgStringOKThe status message.
dataIdStringe6b080a8-a91a-11e8-bac4-6c96cfde2af9The moderation object ID. Echoes the dataId from the request, if set.
taskIdStringfdd25f95-4892-4d6b-aca9-7939bc6e9baa-1486198766695The task ID. Use this ID to query results from /green/image/results.
urlStringhttp://www.aliyundoc.com/2015/0826/2015082612403321.jpgThe URL of the first image, echoed from the request.

Examples

Request:

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

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

Response:

{
    "code": 200,
    "msg": "OK",
    "requestId": "95AD868A-F5D2-4AEA-96D4-E0273B8E074C",
    "data": [
        {
            "code": 200,
            "msg": "OK",
            "dataId": "e6b080a8-a91a-11e8-bac4-6c96cfde2af9",
            "taskId": "fdd25f95-4892-4d6b-aca9-7939bc6e9baa-1486198766695",
            "url": "http://www.aliyundoc.com/2015/0826/2015082612403321.jpg"
        }
    ]
}

Operation 2: Query face comparison results

Endpoint: POST /green/image/results

Queries the results of asynchronous face comparison tasks submitted via /green/image/asyncscan. To construct an HTTP request, see Request structure. Alternatively, use an existing SDK — see SDK overview.

Billing

Free of charge.

Usage notes

  • Poll at least 30 seconds after submitting the task.

  • Results are retained for up to 4 hours. After that, they are deleted.

QPS limit

50 calls per second per account. Exceeding this limit triggers throttling.

Request parameters

ParameterTypeRequiredExampleDescription
bodyStringArrayYes["fdd25f95-4892-4d6b-aca9-7939bc6e9baa-1486198766695"]The list of task IDs to query. Maximum 100 elements. Obtain task IDs from the /green/image/asyncscan response.

Response parameters

ParameterTypeExampleDescription
codeInteger200The HTTP status code. For a full list, see Common error codes.
msgStringOKThe status message.
dataIdStringe6b080a8-a91a-11e8-bac4-6c96cfde2af9The moderation object ID. Echoes the dataId from the submission request, if set.
taskIdStringimg2hsbmQeA4CU7l78$s8q5mW-1pnn7ZThe task ID.
urlStringhttp://www.aliyundoc.com/2015/0826/2015082612403321.jpgThe URL of the moderated image (first image).
resultsJSONArrayThe moderation results. Each element follows the result structure below.
extrasJSONObjectAdditional parameters from the submission request. This field may change — always use the latest value.

result structure:

ParameterTypeExampleDescription
sceneStringsface-1The detection scenario. Valid value: sface-1 (face comparison).
labelStringsface-1The similarity category. Valid values: normal (low similarity), sface-1 (high similarity).
suggestionStringreviewThe moderation recommendation. Valid values: pass (low similarity, no action needed), review (high similarity, further review recommended).
rateFloat97.0The confidence score, from 0 to 100. Higher scores indicate higher reliability. Do not use this score directly in business logic.

Examples

Request:

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

[
    "fdd25f95-4892-4d6b-aca9-7939bc6e9baa-1486198766695"
]

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.0,
                "scene": "sface-1",
                "suggestion": "review"
            }
        }
    ]
}