Skip to content

Compare Faces ​

Compares the faces in two images and returns whether they belong to the same person — matched, unmatched or unsure — with a similarity score from 0 to 1. This is the 1:1 check that ties a selfie to an ID card portrait.

Endpoint ​

http
POST /v1/compare_faces_sync
Content-Type: application/json
json
{
  "image1": {
    "id": "7db00808-0416-45cf-a5cb-3b6dfbd7bb74",
    "base64": "",
    "label": "portrait",
    "metadata": "{}"
  },
  "image2": {
    "id": "a4facba3-334b-41fb-97e3-4766cb70ae29",
    "base64": "",
    "label": "id_card.vn.national_id.front",
    "metadata": "{}"
  },
  "type": ""
}

Parameters:

ParamTypeRequiredDefaultDescription
image1ImageDataYes—The first image containing a face to compare with image2.
image2ImageDataYes—The second image containing a face to compare with image1.
typestringNodefaultSpecifies the type of face comparison for special cases. Omit to use the default.

ImageData ​

ParamTypeRequiredDefaultDescription
idstringNo—ID of the image returned by Upload Image.
base64stringNo—Base64-encoded text of the image data.
labelstringNo—Label of the image, as described in Usage Recommendations.
metadatastring_jsonNo—Key/value JSON string. Example: {"id":"<ID>","type":1}

Supply either id or base64 per image, never both.

Sample Request ​

bash
curl -X POST \
  '<BASE_URL>/v1/compare_faces_sync' \
  -H 'Authorization: ATV <ACCESS_ID>:<SIGNATURE>' \
  -H 'X-TV-Timestamp: <TIMESTAMP>' \
  -H 'Content-Type: application/json' \
  -d '{
    "image1": { "id": "7db00808-0416-45cf-a5cb-3b6dfbd7bb74" },
    "image2": { "id": "a4facba3-334b-41fb-97e3-4766cb70ae29" }
  }'

Response ​

json
{
  "success": true,
  "code": 0,
  "message": "success",
  "data": {
    "status": "success",
    "compare_faces": [
      {
        "face1_id": "abdba678-b680-4b62-bc4b-d9b8fb37e8e4",
        "face2_id": "d43bf504-f1a3-4799-9bda-e5709ae7aa69",
        "result": "matched",
        "score": 0.95
      },
      {
        "face1_id": "ae7a6cd2-4f5b-45b3-955f-844b1bc6d95a",
        "face2_id": "d43bf504-f1a3-4799-9bda-e5709ae7aa69",
        "result": "unmatched",
        "score": 0.1
      }
    ],
    "image1": {
      "id": "f3f6f8b5-2ac0-4734-a4b5-836c6c300b0b",
      "transformed_image_id": "",
      "faces": [
        {
          "id": "abdba678-b680-4b62-bc4b-d9b8fb37e8e4",
          "bounding_box": { "top": 172, "right": 550, "bottom": 446, "left": 357, "angle": 0 }
        }
      ]
    },
    "image2": {
      "id": "639058a6-0631-4bfd-a718-bc72c2695daf",
      "transformed_image_id": "",
      "faces": [
        {
          "id": "d43bf504-f1a3-4799-9bda-e5709ae7aa69",
          "bounding_box": { "top": 296, "right": 559, "bottom": 369, "left": 504, "angle": 0 }
        }
      ]
    },
    "request_id": "b6e90aa2-a2d2-44bb-b4d5-cd4b92d0cdae"
  },
  "errors": []
}
FieldTypeDescription
data.statusstringsuccess or failure.
data.compare_facesComparePair[]Every face pair evaluated, largest pair first.
data.image1ImageResultFaces detected in the first image.
data.image2ImageResultFaces detected in the second image.
data.request_idstringRequest ID; quote it to CAKE Support when checking logs.

ComparePair ​

FieldTypeDescription
face1_idstringID of the face in image1.
face2_idstringID of the face in image2.
scorefloatHow likely the two faces are the same person, range 0–1. 0 means no similarity at all.
resultstringmatched, unmatched or unsure. See Verdict Definitions.

ImageResult ​

FieldTypeDescription
idstringID of the image.
transformed_image_idstringID of the transformed image, present only when the image was transformed.
facesFace[]Faces detected in the image, each with id and bounding_box (top, right, bottom, left, angle).

The largest pair of faces is sorted first. When the selfie contains multiple faces, use the first pair in compare_faces.

INFO

unsure is a real outcome, not a soft matched. Route unsure results to manual review rather than folding them into either branch of an automated decision.

Errors ​

CodeMessage
2001003Image sent to the server has no faces.
2001010Access ID not found.
2001026Images sent to server are duplicated.
401100You are not authorized to perform the action.
4001000Input parameter violates a constraint.
4001001The X-TV-Timestamp header is expired, need a newer one.
4041000The image ID is not found in DB.
4131000The input image size exceeds the allowed limit (15MB).
4151000The provided image format is not supported (JPG/PNG).
4291000The number of requests exceeded your throughput limit.
5001000Some unexpected error occurs while processing the request.
CodeDescription
access_id_not_foundAccess ID not found.
access_denied_exceptionYou are not authorized to perform the action.
invalid_parameter_exceptionInput parameter violates a constraint.
request_time_too_skewedThe X-TV-Timestamp header is expired, need a newer one.
image_not_found_exceptionThe image ID is not found in DB.
image_too_large_exceptionThe input image size exceeds the allowed limit (15MB).
invalid_image_format_exceptionThe provided image format is not supported (JPG/PNG).
duplicated_imageImages sent to server are duplicated.
image_has_no_facesImage sent to the server has no faces.
rate_limit_exceptionThe number of requests exceeded your throughput limit.
internal_server_errorSome unexpected error occurs while processing the request.

Next Steps ​

Developers