Age Estimation API
The Age Estimation API allows you to estimate a person's age based on facial analysis. This API can be used for age verification, demographic analysis, or personalized user experiences. Additionally, we perform a passive liveness test to ensure the submitted image is of a real person and not a spoof attempt.
- Base URL:
https://verification.didit.me
- Endpoint:
/v2/age-estimation/
- Authentication:
Client Token (Bearer Token)
The authentication endpoint uses a different base URL than the API endpoints. Ensure you use the correct URLs to avoid connectivity issues.
This API requires a Pro Plan subscription and has an associated cost per call. Results won't be saved in your console. For pricing details, visit our API Pricing page (opens in a new tab).
Process Overview
Follow these steps to submit a face image for age estimation:
Step 1: Authenticate
Obtain a valid access_token
by following the Authentication documentation. This token is required in the Authorization
header of your request.
The access_token
is valid for 24 hours. You only need to re-authenticate once it expires.
Step 2: Prepare Request Parameters
Parameter | Type | Required? | Description | Example Value |
---|---|---|---|---|
|
| Yes | User's face image (JPEG, PNG, or WebP) | Binary image file |
|
| No | Customization options for age estimation and liveness verification | See options details below |
Options Object
The options
parameter allows you to customize the age estimation and liveness verification thresholds:
Option | Type | Required? | Description | Default Value |
---|---|---|---|---|
|
| No | Results with liveness score below this will be declined. Must be between 0-100. | 30 |
|
| No | Results with estimated age below this will be declined. Must be between 1-120. | 18 |
Image Requirements
- Images must be in JPEG, PNG, or WebP format
- Minimum resolution: 480x480 pixels
- Maximum file size: 5MB
- Face must be clearly visible, well-lit, and unobstructed
- Only one face should be present in the image
Step 3: Send the Request
Make a POST
request to /v2/age-estimation/
with the prepared parameters and include the access_token obtained in step 1 in the header.
Example Request
POST /v2/age-estimation/ HTTP/1.1
Host: verification.didit.me
Content-Type: multipart/form-data
Authorization: Bearer {access_token}
--boundary
Content-Disposition: form-data; name="user_image"; filename="user.jpg"
Content-Type: image/jpeg
[Binary image data]
--boundary
Content-Disposition: form-data; name="options"
Content-Type: application/json
{
"face_liveness_score_decline_threshold": 35,
"age_estimation_decline_threshold": 21,
}
--boundary--
Response
The response provides detailed information about the age estimation results, including the estimated age and confidence score.
Example Response
{
"request_id": "11111111-2222-3333-4444-555555555555",
"liveness": {
"status": "Approved",
"method": "PASSIVE",
"score": 89.92,
"reference_image": "https://example.com/reference.jpg",
"video_url": "https://example.com/video.mp4",
"age_estimation": 24.3,
"warnings": [
{
"risk": "LOW_LIVENESS_SCORE",
"additional_data": null,
"log_type": "information",
"short_description": "Low liveness score",
"long_description": "The liveness check resulted in a low score, indicating potential use of non-live facial representations or poor-quality biometric data."
}
]
},
"created_at": "2024-07-24T08:54:25.443172Z"
}
Response Fields
Field | Type | Description |
---|---|---|
|
| Unique identifier for the API request |
|
| Liveness check status (Approved, Declined) |
|
| Method used for liveness detection (PASSIVE) |
|
| Confidence score for the liveness check (0-100) |
|
| URL to the reference image used |
|
| URL to the video if applicable |
|
| Estimated age in years (decimal value) |
|
| Array of warning objects with risk levels and descriptions |
|
| Timestamp when the request was created |
The image URL in the response is temporary and will expire after 60 minutes.
Error Handling
Status Code | Error | Description |
---|---|---|
400 | Bad Request | Invalid parameters or missing required files |
401 | Unauthorized | Invalid or missing access_token |
403 | Forbidden | Not authorized to access this API or insufficient subscription plan |
Example Error Response
{
"error": {
"code": "INVALID_IMAGE",
"message": "No face detected in the image"
}
}
Common Error Codes
Error Code | Description |
---|---|
INVALID_IMAGE | No face or multiple faces detected in the image |
PROCESSING_ERROR | Error processing the image |
INSUFFICIENT_QUALITY | Image quality is too low for accurate analysis |
Code Examples
async function submitAgeEstimation(accessToken, userImageFile, options = null) {
const url = `https://verification.didit.me/v2/age-estimation/`;
// Create a FormData instance
const formData = new FormData();
formData.append('user_image', userImageFile);
// Add options if provided
if (options) {
formData.append('options', JSON.stringify(options));
}
const requestOptions = {
method: 'POST',
headers: {
'Authorization': `Bearer ${accessToken}`
},
body: formData
};
try {
const response = await fetch(url, requestOptions);
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error?.message || errorData.detail || 'Unknown error occurred');
}
return await response.json();
} catch (error) {
console.error('Error in age estimation:', error);
throw error;
}
}
// Example usage
async function performAgeEstimation() {
try {
// 1. Get client token (implement based on auth documentation)
const token = await getClientToken();
// 2. Get image file (from file input or other source)
const userImageFile = document.getElementById('user-image-input').files[0];
// 3. Custom options (optional)
const options = {
face_liveness_score_decline_threshold: 35,
age_estimation_decline_threshold: 21,
};
// 4. Submit age estimation
const result = await submitAgeEstimation(
token.access_token,
userImageFile,
options
);
console.log('Age estimation result:', result);
console.log(`Estimated age: ${result.liveness.age_estimation} years`);
return result;
} catch (error) {
console.error('Error:', error);
throw error;
}
}
Best Practices
- Image Quality: Use high-quality, well-lit images for more accurate results.
- Face Positioning: Ensure the face is clearly visible and centered in the frame.
- Face Coverage: Face should occupy at least 20% of the image area.
- Error Handling: Implement proper error handling to manage cases where face detection fails.
- Threshold Configuration: Use the
options
parameter to customize verification thresholds:- Set
face_liveness_score_decline_threshold
to balance security and user experience. - Configure
age_estimation_decline_threshold
based on your specific age verification requirements. - Adjust thresholds based on the level of strictness required for your application.
- Set
Accuracy Considerations
- Age estimation is typically accurate within ±3.5 years for most age ranges.
- Accuracy is best for ages 16-60.
- Extreme lighting conditions, unusual angles, or facial coverings may affect accuracy.
- Consider setting wider age boundaries for edge cases.