Age estimation v2
Once you've set up your organisation account on the Yoti Hub, you’re ready to start integrating with the Age estimation and anti-spoofing API.
There is one step to follow to integrate the Age estimation and anti-spoofing API:
- Create a request
Face Capture
For optimal results, Yoti provides and recommends to use the Yoti Face Capture modules, which are designed to capture optimal images meeting the requirements of the API. This is available as a Native package, and Web implementation.
Create a request
After completing the Yoti onboarding, you will need to complete authentication for the API by using the Yoti SDK to simplify the process. The Yoti SDKs are available via popular dependency management systems.
npm install -S -E yoti
You can create two types of requests using the API:
Endpoint | Description |
---|---|
https://api.yoti.com/ai/v1/age | Use Yoti's age estimation service. |
https://api.yoti.com/ai/v1/age-antispoofing | Use Yoti's age estimation service and the Anti-spoofing check. |
Once you have added the Yoti SDK dependency to your project, you can use it to build and send your request. See the code snippets below for examples.
const PATHS = {
AGE: '/age',
LIVENESS: '/antispoofing',
AGE_LIVENESS: '/age-antispoofing',
};
const data = {
img: 'base64img',
};
const request = new RequestBuilder()
.withBaseUrl('https://api.yoti.com/ai/v1')
.withPemFilePath('<YOTI_KEY_FILE_PATH>')
.withEndpoint(PATHS.AGE_LIVENESS) // optionally PATHS.AGE or PATHS.LIVENESS
.withPayload(new Payload(data))
.withMethod('POST')
.withHeader('X-Yoti-Auth-Id', '<YOTI_CLIENT_SDK_ID>')
.build();
This endpoint will return an anti-spoofing result alongside an Age Estimation.
This JSON string must be sent in the img
parameter in withPayload
.
{
"img": "/9j/4AAQSkZJRgABAgAAAQABAAD/2wAcHNXCKigjEaYH51Me1Zy1Za0P/Z...."
}
{
"antispoofing": {
"prediction": "real|fake|undetermined"
},
"age": {
"st_dev": float,
"age": float
}
}
If integrating into a non-browser client, we recommend you contact us through our support form for additional support.
Terminal integrations
Optionally, additional headers may be provided to the request to allow Yoti to track error responses coming from a particular machine. This would typically be used in a non-browser client scenario, such as an ePOS terminal where each individual machine must be registered by the business.
In order to do this, the following headers should be applied:
Header | Description |
---|---|
Terminal-Id | Unique ID per machine. Mandatory for non-browser integrations. |
Session-Id | May be provided to demonstrate multiple attempts are from a single user transaction. |
Example response
The response received from the API will be below:
{
"antispoofing": {
"prediction": "real"
},
"age": {
"age": 25.1,
"st_dev": 3.5
}
}
Response | Explained |
---|---|
Prediction - real | Yoti has detected a real user. |
Prediction - fake | Yoti has detected a spoof attempt. |
Prediction - undetermined | Yoti is unable to determine if the user is real or not. |
Age - age | The age estimation of the user. |
Age - st_dev | The st_dev value is a confidence score. Yoti recommends rejecting any response with an uncertainty greater than 6.0. Typically this indicates a problem with image capture. This should only be treated as a quality score. |
Error codes
Error code | Error | Description |
---|---|---|
404 | APP_NOT_FOUND | Application app_id not found. |
401 | INVALID_X_YOTI_AUTH_ID |
|
400 | INVALID_APP_ID | Application id cannot be empty. |
400 | INVALID_PUBLIC_KEY | Application public key cannot be empty. |
403 | DISABLED_APP_STATE | Application must be enabled. |
400 | INVALID_ORG_ID | Organisation id cannot be empty. |
400 | INVALID_BILLING_SOURCE_ID | Application billing source id cannot be empty. |
404 | ORG_NOT_FOUND | Organisation org_id not found. |
401 | INVALID_YOTI_AUTH_DIGEST |
|
401 | INVALID_NONCE |
|
401 | INVALID_TIMESTAMP |
|
401 | INVALID_PUBLIC_KEY_ENCODING | Failed to load public key. key is not der encoded. |
401 | UNSUPPORTED_ALGORITHM | Serialised key is of a type that is not supported by the backend. |
401 | INVALID_SIGNATURE | Failed to verify signature. |
403 | INVALID_ORG_STATUS | Organisation has an invalid status. |
404 | INVALID_METADATA_DEVICE | Invalid device metadata provided. |
400 | INVALID_BODY_ENCODING | Request body should be a valid JSON. |
404 | INVALID_ENDPOINT | The endpoint request is invalid. |
413 | PAYLOAD_TOO_LARGE | Payload too large. |
400 | IMAGE_NOT_PROVIDED | Image has not been provided. |
400 | INVALID_B64_IMAGE |
|
400 | UNSUPPORTED_IMAGE_FORMAT | Image format not supported. Please use JPEGs (95 to 100 quality) and PNGs. |
400 | IMAGE_SIZE_TOO_BIG | Image size too big, the maximum size is 2MB. |
400 | IMAGE_SIZE_TOO_SMALL | Image size too small, the minimum size is 50KB. |
400 | MIN_HEIGHT | The image height is incorrect. Image minimum height required is 300 pixels. |
400 | MAX_HEIGHT | The image height is incorrect. Image maximum height required is 2000 pixels. |
400 | MIN_WIDTH | The image width is incorrect. Image minimum width required is 300 pixels. |
400 | MAX_WIDTH | The image width is incorrect. Image maximum width required is 2000 pixels. |
400 | MIN_PIXELS | To process the image the minimum number of pixels required is 90,000 pixels. |
400 | MAX_PIXELS | To process the image the maximum number of pixels required is 2,100,000 pixels. |
400 | IMAGE_WRONG_CHANNELS | Missing colour channel, the input image must be RGB or RGBA. |
400 | IMAGE_GRAYSCALE_NOT_SUPPORTED | Grayscale images not supported. |
503 | SERVICE_UNAVAILABLE | The service is temporarily unavailable. |
400 | FACE_NOT_FOUND | Face not found. |
400 | MULTIPLE_FACES | Multiple faces in the image provided. |
400 | FACE_BOX_TOO_SMALL | The face in the image provided is too small. |
400 | FACE_TO_IMAGE_RATIO_TOO_LOW | Face ratio is lower than the minimum ratio. |
400 | FACE_TO_IMAGE_RATIO_TOO_HIGH | Face ratio is bigger than the maximum ratio. |
400 | INSUFFICIENT_AREA_AROUND_THE_FACE | Insufficient area around the face in the image provided. |
400 | IMAGE_TOO_BRIGHT | Image too bright.. |
400 | IMAGE_TOO_DARK | Image too dark. |
500 | FAIL_PREDICTION |
|
500 | UNSPECIFIED_ERROR | An internal server error occurred. |