Face · eKYC Core

Search faces

POST/v1/search_faces_sync

Searches one or more collections for faces similar to the face in an image, and returns each match with a similarity score and the metadata indexed with it.

Request

MethodPOST
Path/v1/search_faces_sync
Content-Typeapplication/json
Auth requiredYes — HMAC signing

Clients can provide image data to the TrustVision API by specifying the ID the image by using upload API, or by sending the image data as base64-encoded text.

NameTypeRequiredDescription
imageImageDataRequiredimage to index face. Should use image has the face. if use TS SDK, use last frontal image
collectionstringOptionalsearch faces in this collection. If empty, the default collection will be used. case-sensitive
collections[]stringOptionalsearch faces in these collections. Omit collection param if using this param. case-sensitive
typeintOptionaltype of collection
max_facesintOptionalmaximum face results. Default is 10
special_id_typestringOptionalid string (provided by admin) to identify special use-case. Omit this param to use the default.
  • If you use base64, label and metadata, omit parameter id.
  • If you use id (result id is returned from Upload Image API), omit parameter base64, label and metadata.
  • If not set collection, default collection will be used.
  • If you specify collections not empty, we will search in list collections. otherwise, we use collection.
  • If the portrait sanity check is enabled for your client, the image is checked before it is searched; see The portrait sanity check.
JSON
{
    "image": {
        "id": string,
        "base64": string,
        "label": string,
        "metadata": string_json,
    },
    "collection": string,
    "collections": []string,
    "type": int,
    "special_id_type": string,
    "max_faces": int
}

Which type's parameter contains value:

valuedescription
3Matching Selfie vs Selfie

The portrait sanity check

When TrustVision has enabled the portrait sanity check of search faces for your client or access key (setting api.search_faces.enable_sanity), the image goes through the same check as Verify portrait before anything is searched. The request does not change. Contact your TrustVision Account Manager to enable it.

  • Only an image whose portrait sanity verdict is good is searched. The response is then the usual search response.
  • Any other verdict stops the call: nothing is searched, and the response is a failure that carries the portrait sanity error code, with data.request_id set to the id of the check. See Response and Failure codes.
  • If the check itself could not run, the failure carries internal_server_error (with the same detail.sanity: portrait) and says nothing about the image: nothing is searched, and the call can be retried later.
  • The check runs in the same call, before the search, so the call takes longer by the time the check takes.
  • This setting is separate from the one of Index faces: each one covers its own endpoint.

Sample request

curl -X POST \
'<BASE_URL>/v1/search_faces_sync' \
-H 'Authorization: TV <YOUR ACCESS KEY>:<CREATED SIGNATURE>' \
-H 'X-TV-Timestamp: 2019-04-21T18:00:15+07:00' \
-H 'Content-Type: application/json' \
-d \
'
{
    "image": {
        "id": "a4facba3-334b-41fb-97e3-4766cb70ae29"
    }
}
'

Response

data.faces holds one array of matches per face found in the input image when a single collection was searched; data.faces_in_collection holds the same, keyed by collection name, when several were. In case the request processing has been finished, the HTTP status code will be 200, and the data.status is either "success" or "failure" depending on whether the request has been successfully processed or not.

JSON
{
    "data": {
        "request_id": string,
        "status": string, // "success" or "failure"
        "image": {
          "id": string, // id of the image
          "transformed_image_id": string // optional, just in case the image is transformed
        },
        "faces": [   // Result for single collection. support search multiple faces. Each array is result of each face
            [
                {
                    "id": string, // id of the face in image
                    "image_id": string, // id of original image
                    "score": float, // score similar between 2 faces
                    "metadata": [ // list of meta data information of this face
                            {
                                "field": string, // application_id, national_id, ...
                                "value": primitive_type, // when index key=value then the value should a primitive type as string, int, float, boolean
                            },
                            ... // other fields
                },
                ... // other face matched of first face in image
            ],
            [
                ... // list face matches of another face in image
            ],
        ],
        "faces_in_collection": {
            "collection_name1":[   // Result for multiple collections. support search multiple faces. Each array is result of each face
                    [
                    {
                        "id": string, // id of the face in image
                        "image_id": string, // id of original image
                        "score": float, // score similar between 2 faces
                        "metadata": [ // list of meta data information of this face
                                {
                                    "field": string, // application_id, national_id, ...
                                    "value": primitive_type, // when index key=value then the value should a primitive type as string, int, float, boolean
                                },
                                ... // other fields
                    },
                    ... // other face matched of first face in image
                ],
                [
                    ... // list face matches of another face in image
                ],
            ],
                "collection_name2": ... // other result on collection_name2
        }
    },
    "errors": [
        {
            "code": string,
            "message": string,
            "detail": {
                "field": string, // optional, which parameter is invalid.
                ... // any other information that can be useful for client
            },
        },
        ... // other errors
    ]
}
  • The biggest faces were sorted on the top. We recommended using the first result in faces if the input image has multiple faces.

A search of the default collection that matched two indexed faces comes back like this:

JSON
{
    "data": {
        "status": "success",
        "image": {
          "id": "a4facba3-334b-41fb-97e3-4766cb70ae29"
        },
        "faces": [
            [
                {
                    "id": "e8cd85a1-e1aa-4750-a0c9-1525fb524eed",
                    "image_id": "91b2c846-b701-4cc2-8061-1f243c50cc52",
                    "score": 1,
                    "metadata": [
                        {
                            "field": "app_id",
                            "value": 3333
                        },
                        {
                            "field": "national_id",
                            "value": 4444
                        }
                    ]
                },
                {
                    "id": "b05ed8b6-5d29-47a1-a934-f59f0197cea0",
                    "image_id": "ddb80011-c861-4904-a25f-c000cb969b61",
                    "score": 1,
                    "metadata": null
                },
                ...
            ]
        ],

        "request_id": "426bef5c-77ff-49e5-b0cd-b66651ac6427"
    }
}

A call stopped by the portrait sanity check comes back like this. data.request_id is the id of the check, and there are no data.faces:

JSON
{
    "data": {
        "status": "failure",
        "request_id": "8c0e5b7d-3f2a-4c19-9e6b-2d4f7a1c0b93"
    },
    "errors": [
        {
            "code": "image_has_no_faces",
            "message": "There are no faces in the image. Please retake or upload it again.",
            "detail": {
                "sanity": "portrait"
            }
        }
    ]
}

Failure codes

If the data.status is "failure", the "errors" field will tell you why it failed.

When the portrait sanity check is enabled, an image that fails it is answered with a portrait sanity error code and detail.sanity set to portrait. Some of the codes:

Error codeDescription
image_too_blurthe input image is too blur
image_too_darkthe input image is too dark
image_too_brightthe input image is too bright (glare)
image_has_no_facesthe input image has no faces
image_has_multiple_facesthe input image has multiple faces

Full list of portrait sanity error codes: Please contact the administrator.

In case of any other errors, the data field will be empty, and the server sends one of the following HTTP status codes with an error code:

HTTP codeError codeDescription
400invalid_parameter_exceptionInput parameter violates a constraint.
400request_time_too_skewedThe X-TV-Timestamp header is expired, need a newer one.
401access_denied_exceptionYou are not authorized to perform the action.
404image_not_found_exceptionThe image ID is not found in DB.
404request_not_found_exceptionThe request ID is not found when polling result by id.
408request_timeout_exceptionRequest takes too long to process.
429rate_limit_exceptionThe number of requests exceeded your throughput limit.
500internal_server_errorSome unexpected error occurs while processing the request.

The codes above are the ones documented for this endpoint. Response errors lists the codes for the eKYC Core surface as a whole — the two lists do not match on every endpoint.