Age Estimation
In FACIA, our Age Estimation service offers a nuanced understanding of an individual's age. This sophisticated feature utilizes advanced algorithms, analyzing facial features and patterns to provide precise age estimations. It stands as a dynamic tool within our system, contributing not only to insightful age assessments but also enhancing the overall versatility of FACIA's facial analysis capabilities.
Create Age Estimation Transaction
This endpoint initiates a transaction request and returns a reference_id if the request includes proper authentication and valid fields, as mentioned below in the request parameters, using the POST method:
Endpoint
POSThttps://api.facia.ai/age-estimation
Authorization:
Token Type: BearerDescription:
This API utilizes Access token or Client-Secret key in header for authentication.
You can use your client_id and client_secret key when using the "/request-access-token" endpoint to obtain a Bearer token for authorization while connecting to this API. For additional details on Authorization, click Here
Request Body Samples:
- HTTP
- Javascript
- Curl
- PHP
- Python
- Ruby
- java
- C#
- Go
//POST /age-estimation HTTP/1.1
//Host: api.facia.ai
//Content-Type: application/json
//Authorization: Bearer <access-token-here>
{
"type": "age_estimation",
"enroll_face": true,
"wait_for_result": 0,
"file": "data:image/png;base64,your_image_base64_here"
}
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer token");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"type": "age_estimation",
"enroll_face": true,
"wait_for_result": 0,
"file": "data:image/png;base64,your_image_base64_here"
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.facia.ai/age-estimation", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
curl --location 'https://api.facia.ai/age-estimation' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer token' \
--data '{
"type": "age_estimation",
"enroll_face": true,
"wait_for_result": 0,
"file": "data:image/png;base64,your_image_base64_here"
}'
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.facia.ai/age-estimation',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('type'=> 'age_estimation','enroll_face'=> true, 'wait_for_result' =>0, 'file'=> new CURLFILE('/321238932_678447270428202_3141578377253799698_n.jpeg')),
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer token'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
url = "https://api.facia.ai/age-estimation"
payload = {
'type': 'age_estimation',
'enroll_face': true,
'wait_for_result': 0,
'file': 'data:image/png;base64,your_image_base64_here'
}
files=[
('file',('321238932_678447270428202_3141578377253799698_n.jpeg',open('/321238932_678447270428202_3141578377253799698_n.jpeg','rb'),'image/jpeg'))
]
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer token'
}
response = requests.post(url, headers=headers, json=payload)
print(response.text)
require 'net/http'
require 'uri'
require 'json'
url = URI.parse('https://api.facia.ai/age-estimation')
token = 'your_token'
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url.path)
request['Authorization'] = "Bearer #{token}"
request['Content-Type'] = 'application/json'
request.body = {
'type' => 'age_estimation',
'enroll_face' => true,
'wait_for_result' => 0,
'file' => 'data:image/png;base64,your_image_base64_here'
}.to_json
response = http.request(request)
puts "Response Code: #{response.code}"
puts "Response Body: #{response.body}"
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class AgeEstimationRequest {
public static void main(String[] args) {
try {
String apiUrl = "https://api.facia.ai/age-estimation";
String token = "your_token";
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Authorization", "Bearer " + token);
connection.setRequestProperty("Content-Type", "application/json");
// Add type, enroll_face, wait_for_result and the Base64 encoded image to the JSON request body
String requestBody = "{ \"type\": \"age_estimation\", \"enroll_face\": true, \"wait_for_result\": 0, \"file\": \"data:image/png;base64,your_image_base64_here\" }";
try (OutputStream os = connection.getOutputStream()) {
byte[] input = requestBody.getBytes("utf-8");
os.write(input, 0, input.length);
}
int responseCode = connection.getResponseCode();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
System.out.println("Response Code: " + responseCode);
System.out.println("Response Body: " + response.toString());
connection.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
string apiUrl = "https://api.facia.ai/age-estimation";
string token = "your_token";
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
// Create JSON content with the Base64 encoded image
var json = "{\"type\":\"age_estimation\",\"enroll_face\":true,\"file\":\"data:image/png;base64,your_image_base64_here\"}";
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync(apiUrl, content);
Console.WriteLine($"Response Code: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response Body: {responseBody}");
}
}
}
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
apiURL := "https://api.facia.ai/age-estimation"
token := "your_token"
// Add 'type', 'enroll_face', 'wait_for_result' and the Base64 encoded image
body := bytes.NewBuffer([]byte(`{
"type": "age_estimation",
"enroll_face": true,
"wait_for_result": 0,
"file": "data:image/png;base64,your_image_base64_here"
}`))
client := &http.Client{}
request, err := http.NewRequest("POST", apiURL, body)
if err != nil {
fmt.Println("Error creating request:", err)
return
}
request.Header.Set("Authorization", "Bearer "+token)
request.Header.Set("Content-Type", "application/json")
response, err := client.Do(request)
if err != nil {
fmt.Println("Error making request:", err)
return
}
defer response.Body.Close()
fmt.Println("Response Code:", response.Status)
responseBody, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
return
}
fmt.Println("Response Body:", string(responseBody))
}
Request Parameter
| Parameters | Description |
|---|---|
| type | Required: Yes Type: string Example: type=age_estimationType must be age_estimation. |
| enroll_face | Required: No Type: boolean Example: enroll_face=trueDefault value: true If you do not want the system to enroll the face then set the value of the key as false. |
| file | Required: Yes Type: file or string multipart/form-data: the image file (.jpg, .jpeg, .png). application/json: a Base64 data URI including the prefix, e.g. data:image/jpeg;base64,/9j/4AAQ.... Plain Base64 without the data:image/...;base64, prefix is rejected. |
| wait_for_result | Required: No Type: boolean / integer Accepted values: 1 / 0 (integer) or true / false (boolean)Default: 0 (false)Set to 1 or true to wait for the processing result in the same response. Set to 0 or false (or omit it) to receive only the reference_id and fetch the result later. |
Multipart Upload Sample
Image fields can also be sent as files with multipart/form-data instead of Base64 JSON:
curl -X POST https://api.facia.ai/age-estimation \
-H "Authorization: Bearer <token>" \
-F "type=age_estimation" \
-F "file=@/path/to/photo.jpg"
Response Sample
{
"status": true,
"message": "Transaction Created",
"result": {
"data": {
"reference_id": "your_reference_id_here"
}
}
}
Response Parameter
| Parameters | Description |
|---|---|
| reference_id | Type: string Example: reference_id=your_reference_id_here |
| message | Type: string Example: message=Transaction created |
Age Estimation Result
This endpoint accepts a single field in the body request payload: reference_id (String). Once the backend finalizes the response, this endpoint returns a result object containing an 'age' variable, which is an estimated age of type integer. Failure to provide a valid reference_id will result in a 422 status code.
Endpoint
POSThttps://api.facia.ai/result
Authorization:
Token Type: BearerDescription:
This API utilizes Access token or Client-Secret key in header for authentication.
You can use your client_id and client_secret key when using the "/request-access-token" endpoint to obtain a Bearer token for authorization while connecting to this API. For additional details on Authorization, click Here
Request Body Samples:
- HTTP
- Javascript
- Curl
- PHP
- Python
- Ruby
- Java
- C#
- Go
//POST /result HTTP/1.1
//Host: api.facia.ai
//Content-Type: application/json
//Authorization: Bearer <access-token-here>
{
"reference_id": "your_reference_id_here"
}
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer token");
var formdata = new FormData();
formdata.append("reference_id", "your_reference_id_here");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: formdata,
redirect: 'follow'
};
fetch("/result", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
curl --location 'https://api.facia.ai/result' \
--header 'Content-Type: application/json' \
--data '{
"reference_id": "your_reference_id_here"
}'
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => '/result',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array(),
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer token'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import requests
url = "/result"
payload={}
files=[
]
headers = {
'Authorization': 'Bearer token'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
require 'net/http'
require 'uri'
url = URI.parse('result')
token = 'your_token'
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url.path)
request['Authorization'] = "Bearer #{token}"
response = http.request(request)
puts "Response Code: #{response.code}"
puts "Response Body: #{response.body}"
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class AgeEstimationResultRequest {
public static void main(String[] args) {
try {
String apiUrl = "result";
String token = "your_token";
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Authorization", "Bearer " + token);
int responseCode = connection.getResponseCode();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
System.out.println("Response Code: " + responseCode);
System.out.println("Response Body: " + response.toString());
connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
string apiUrl = "result";
string token = "your_token";
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
var response = await httpClient.PostAsync(apiUrl, null);
Console.WriteLine($"Response Code: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response Body: {responseBody}");
}
}
}
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
apiURL := "result"
token := "your_token"
client := &http.Client{}
request, err := http.NewRequest("POST", apiURL, nil)
if err != nil {
fmt.Println("Error creating request:", err)
return
}
request.Header.Set("Authorization", "Bearer " + token)
response, err := client.Do(request)
if err != nil {
fmt.Println("Error making request:", err)
return
}
defer response.Body.Close()
fmt.Println("Response Code:", response.Status)
responseBody, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
return
}
fmt.Println("Response Body:", string(responseBody))
}
Request Parameter
| Parameters | Description |
|---|---|
| reference_id | Required: Yes Type: string Example: reference_id=your_reference_id_here The unique identifier associated with the created transaction. |
Response Sample
{
"status": true,
"message": "Success",
"result": {
"data": {
"reference_id": "your_reference_id_here",
"age": 24,
"is_age_detected": 1,
"age_txt": "21 to 27 years",
"under_18": 0,
"under_21": 50
}
}
}
Response Parameter
| Parameters | Description |
|---|---|
| reference_id | Required: Yes Type: string Example: reference_id=your_reference_id_here |
| age | Type: integer Example: age=30 Includes the estimated age from the provided image. |
| is_age_detected | Type: boolean (0,1)Example: is_age_detected=1 Is 1, if face is found and age is estimated, otherwise 0. |
| age_txt | Type: string Example: age_txt=21 to 27 years Includes a range of estimated age |
| under_18 | Type: integer Example: under_18=0 Range: 0 to 100 Includes the probability percentage of being under 18. |
| under_21 | Type: integer Example: under_21=0 Range: 0 to 100 Includes the probability percentage of being under 21. |