REST API: working with faces

Compare faces on images

Compare faces across images and read a verdict per pair.

Purpose

Use this call to check whether the faces on several images belong to the same person. Each face is compared against every face of every uploaded image.

Request

POST <API_BASE_URL>/face/compare. All calls are POST under your API address. Replace <API_BASE_URL> with the API address provided with your access.

Send a permanent API token in the token field of the body, or a user token in the token header. See authentication.

Content type: multipart/form-data. Send the fields as a multipart form.

FieldTypeRequiredDescription
tokenstring (uuid)if no headerYour permanent API token. Required unless you send a user token in the token header.
imagesarray of fileyesThe image files, 2 to 70 of them.
multibooleannoProcess every face found. When false, only the largest face of each image is processed.
thresholdstring or numbernoThe distance threshold that decides same_person.
feature_checkarray of object or stringnoA feature name or an array of names to detect on each found face, for example age, gender, mood, glasses, mask or quality. The schema lists the full set of names.
embeddingbooleannoAlso return the vector representation of each face, base64 encoded. The vector search and fusion operations take this value.
thumbbooleannoReturn a pre-processed crop of each face, base64 encoded.
bboxbooleannoReturn the top-left and bottom-right corners of each face rectangle.

Response

HTTP 200. Comparison finished.

FieldTypeDescription
statusstringAlways ok on this body. An upload in which no image carried a face arrives with status of failed.
spentintegerProcessing time in milliseconds.
resultsarray of array of object or stringOne entry per uploaded image, in upload order. An image on which no face was found contributes a plain string that says why, in place of the list of faces.
results[].comparearray of array of objectThis face against every face of every uploaded image, indexed the same way as results.
results[].compare[].same_personbooleanWhether the distance between the two faces is within threshold.
results[].compare[].confidencestringThe similarity as a percentage string, or the string self where a face is compared with itself.
results[].yawnumberHead rotation left or right, in degrees.
results[].pitchnumberHead tilt up or down, in degrees.

Errors

  • 400: The request failed validation.
  • 401: The token is missing, expired or unknown.

A refusal can also come before the operation runs: an address outside your IP allowlist, a token bound to another address, or a body that is not valid JSON. See response format and errors.

Example

Request:

curl -X POST "<API_BASE_URL>/face/compare" \
  -F "token=<your permanent API token>" \
  -F "images=@first.jpg" \
  -F "images=@second.jpg"

Response:

{
  "status": "ok",
  "spent": 1840,
  "results": [
    [
      {
        "compare": [
          [
            {
              "same_person": true,
              "confidence": "self"
            }
          ],
          [
            {
              "same_person": true,
              "confidence": "97.31%"
            }
          ]
        ],
        "yaw": 4,
        "pitch": -2
      }
    ],
    [
      {
        "compare": [
          [
            {
              "same_person": true,
              "confidence": "97.31%"
            }
          ],
          [
            {
              "same_person": true,
              "confidence": "self"
            }
          ]
        ],
        "yaw": 1,
        "pitch": 0
      }
    ]
  ]
}

Questions about the face API?

Write to us and we will help.

Talk to us