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": 1,
"file": file.jpg
}
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer token");
var formdata = new FormData();
formdata.append("type", "age_estimation");
formdata.append("enroll_face", true);
formdata.append("wait_for_result", 1);
formdata.append("file", fileInput.files[0], "321238932_678447270428202_3141578377253799698_n.jpeg");
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: formdata,
redirect: 'follow'
};
fetch("/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' \
--data '{
"type": "age_estimation",
"enroll_face": true,
"wait_for_result":1,
"file": file.jpg
}'
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => '/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' =>1, '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 = "/age-estimation/"
payload={
'type': 'age_estimation',
'enroll_face': 'true',
'wait_for_result': 1,
}
files=[
('file',('321238932_678447270428202_3141578377253799698_n.jpeg',open('/321238932_678447270428202_3141578377253799698_n.jpeg','rb'),'image/jpeg'))
]
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('/age-estimation/')
token = 'your_token'
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url.path)
request['Authorization'] = "Bearer #{token}"
request.set_form_data(
'type' => 'age_estimation',
'enroll_face' => 'true',
'wait_for_result' => 1,
)
file_path = '/path/to/321238932_678447270428202_3141578377253799698_n.jpeg'
file_content = File.read(file_path)
request.body = file_content
response = http.request(request)
puts "Response Code: #{response.code}"
puts "Response Body: #{response.body}"
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
public class AgeEstimationRequest {
public static void main(String[] args) {
try {
String apiUrl = "/age-estimation/";
String token = "your_token";
String type = "age_estimation";
boolean enrollFace = true;
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", "image/jpeg");
// Add type and enroll_face to the request body
String requestBody = "type=" + type + "&enroll_face=" + enrollFace + "&wait_for_result="1;
connection.getOutputStream().write(requestBody.getBytes());
String filePath = "/path/to/321238932_678447270428202_3141578377253799698_n.jpeg";
File file = new File(filePath);
FileInputStream fileInputStream = new FileInputStream(file);
byte[] fileBytes = new byte[(int) file.length()];
fileInputStream.read(fileBytes);
fileInputStream.close();
connection.getOutputStream().write(fileBytes);
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.IO;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
string apiUrl = "/age-estimation/";
string token = "your_token";
string filePath = "/path/to/321238932_678447270428202_3141578377253799698_n.jpeg";
string type = "age_estimation";
bool enrollFace = true;
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
// Create form content with file
MultipartFormDataContent formData = new MultipartFormDataContent();
formData.Add(new StringContent(type), "type");
formData.Add(new StringContent(enrollFace.ToString()), "enroll_face");
byte[] fileBytes = File.ReadAllBytes(filePath);
ByteArrayContent fileContent = new ByteArrayContent(fileBytes);
formData.Add(fileContent, "file", "321238932_678447270428202_3141578377253799698_n.jpeg");
var response = await httpClient.PostAsync(apiUrl, formData);
Console.WriteLine($"Response Code: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response Body: {responseBody}");
}
}
}
package main
import (
"bytes"
"fmt"
"io/ioutil"
"mime/multipart"
"net/http"
"os"
)
func main() {
apiURL := "/age-estimation/"
token := "your_token"
filePath := "/path/to/321238932_678447270428202_3141578377253799698_n.jpeg"
fileContent, err := ioutil.ReadFile(filePath)
if err != nil {
fmt.Println("Error reading file:", err)
return
}
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
// Add 'type' parameter
_ = writer.WriteField("type", "age_estimation")
// Add 'enroll_face' parameter
_ = writer.WriteField("enroll_face", "true")
_ = writer.WriteField("wait_for_result", 1)
part, err := writer.CreateFormFile("file", "321238932_678447270428202_3141578377253799698_n.jpeg")
if err != nil {
fmt.Println("Error creating form file:", err)
return
}
_, err = part.Write(fileContent)
if err != nil {
fmt.Println("Error writing file content:", err)
return
}
writer.Close()
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", writer.FormDataContentType())
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_estimation Type must be age_estimation. |
enroll_face | Required: No Type: boolean Example: enroll_face=true Default 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 Example: file=file File must be of type .jpeg, .jpg or .png. |
wait_for_result | Required: No Type: boolean Default value: 0 Accepted values: 0,1 Set the value of this key as 1 if you want the results of the transaction within the same API request. |
Response Sample
{
"status": true,
"message": "Transaction Created",
"result": {
"data": {
"reference_id": "W4437KIWN0KDM13"
}
}
}
Response Parameter
Parameters | Description |
---|---|
reference_id | Type: string Example: reference_id=W4437KIWN0KDM13 |
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": "W4437KIWN0KDM13"
}
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer token");
var formdata = new FormData();
formdata.append("reference_id", "W4437KIWN0KDM13");
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": "W4437KIWN0KDM13"
}'
<?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=W4437KIWN0KDM13 The unique identifier associated with the created transaction. |
Response Sample
{
"status": true,
"message": "Success",
"result": {
"data": {
"reference_id": "W4437KIWN0KDM13",
"age": "30"
}
}
}
Response Parameter
Parameters | Description |
---|---|
reference_id | Required: Yes Type: string Example: reference_id=W4437KIWN0KDM13 |
age | Type: string Example: age=30 Includes the estimated age from the provided image. |