REST API: working with faces

Detect faces on images

Detect faces and read their position, angle and features.

Purpose

Use this call when you need the faces on an image without any identity decision: where each face is, how it is turned, and optionally features such as age or gender. The call does not store anything.

Request

POST <API_BASE_URL>/face/detect. 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 to process. An image can contain several faces; see multi.
multibooleannoProcess every face found. When false, only the largest face of each image is processed.
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.
check_blurbooleannoAlso return blur scores for each face.
thumbbooleannoReturn a pre-processed crop of each face, base64 encoded.
bboxbooleannoReturn the top-left and bottom-right corners of each face rectangle. On this operation it is on by default.
bbox_probooleannoReturn four [x, y] corner points of each face rectangle.
bbox_realbooleannoReturn the four corner points in the coordinate space of the uploaded image.

Response

A body that cannot be processed arrives with status of error. See response format and errors.

HTTP 200. Detection finished. Read results per uploaded image.

FieldTypeDescription
statusstringAlways ok on this body.
spentintegerProcessing time in milliseconds.
resultsarray of array of object or objectOne entry per uploaded image, in upload order. An image with no face contributes an entry that carries message only. Otherwise the entry lists the faces of that image, highest detection score first.
results[].confidencestringThe detector confidence that this is a face, as a percentage string.
results[].yawnumberHead rotation left or right, in degrees.
results[].pitchnumberHead tilt up or down, in degrees.
results[].featuresarray of objectThe results of the checks named in feature_check, one entry per feature, each with name, result and spent.
results[].bboxarray of numberThe face rectangle as [x1, y1, x2, y2].
results[].thumbstring (base64)The cropped face, base64 encoded. Present only when thumb was requested.
results[].origin_shapearray of integerThe size of the processed image, as [width, height].

Errors

  • 400: The body failed validation. The answer has status of error and a details list with one entry per offending field (path, expected, actual).
  • 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/detect" \
  -F "token=<your permanent API token>" \
  -F "images=@photo.jpg" \
  -F "multi=false"

Response:

{
  "status": "ok",
  "spent": 412,
  "results": [
    [
      {
        "confidence": "99%",
        "yaw": 4,
        "pitch": -2,
        "features": [],
        "bbox": [
          120,
          84,
          232,
          196
        ],
        "origin_shape": [
          640,
          480
        ]
      }
    ]
  ]
}

Questions about the face API?

Write to us and we will help.

Talk to us