Age & Gender swap
curl --request POST \
--url https://www.ailabapi.com/api/portrait/effects/face-attribute-editing \
--header 'Content-Type: multipart/form-data' \
--header 'ailabapi-api-key: <api-key>' \
--form image='@example-file' \
--form 'action_type=<string>' \
--form 'quality_control=<string>' \
--form 'face_location=<string>' \
--form 'target=<string>'import requests
url = "https://www.ailabapi.com/api/portrait/effects/face-attribute-editing"
files = { "image": ("example-file", open("example-file", "rb")) }
payload = {
"action_type": "<string>",
"quality_control": "<string>",
"face_location": "<string>",
"target": "<string>"
}
headers = {"ailabapi-api-key": "<api-key>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('image', '<string>');
form.append('action_type', '<string>');
form.append('quality_control', '<string>');
form.append('face_location', '<string>');
form.append('target', '<string>');
const options = {method: 'POST', headers: {'ailabapi-api-key': '<api-key>'}};
options.body = form;
fetch('https://www.ailabapi.com/api/portrait/effects/face-attribute-editing', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.ailabapi.com/api/portrait/effects/face-attribute-editing",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"action_type\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"quality_control\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"face_location\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"target\"\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Content-Type: multipart/form-data",
"ailabapi-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://www.ailabapi.com/api/portrait/effects/face-attribute-editing"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"action_type\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"quality_control\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"face_location\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"target\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("ailabapi-api-key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://www.ailabapi.com/api/portrait/effects/face-attribute-editing")
.header("ailabapi-api-key", "<api-key>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"action_type\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"quality_control\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"face_location\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"target\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.ailabapi.com/api/portrait/effects/face-attribute-editing")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["ailabapi-api-key"] = '<api-key>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"action_type\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"quality_control\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"face_location\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"target\"\r\n\r\n<string>\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"request_id": "",
"log_id": "",
"error_detail": {
"code": "",
"code_message": "",
"message": ""
},
"result": {
"image": ""
}
}Age & Gender Swap
Age & Gender Swap API
Age & Gender Swap API edits portrait attributes to change age or gender and generate realistic face transformation effects.
POST
/
api
/
portrait
/
effects
/
face-attribute-editing
Age & Gender swap
curl --request POST \
--url https://www.ailabapi.com/api/portrait/effects/face-attribute-editing \
--header 'Content-Type: multipart/form-data' \
--header 'ailabapi-api-key: <api-key>' \
--form image='@example-file' \
--form 'action_type=<string>' \
--form 'quality_control=<string>' \
--form 'face_location=<string>' \
--form 'target=<string>'import requests
url = "https://www.ailabapi.com/api/portrait/effects/face-attribute-editing"
files = { "image": ("example-file", open("example-file", "rb")) }
payload = {
"action_type": "<string>",
"quality_control": "<string>",
"face_location": "<string>",
"target": "<string>"
}
headers = {"ailabapi-api-key": "<api-key>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('image', '<string>');
form.append('action_type', '<string>');
form.append('quality_control', '<string>');
form.append('face_location', '<string>');
form.append('target', '<string>');
const options = {method: 'POST', headers: {'ailabapi-api-key': '<api-key>'}};
options.body = form;
fetch('https://www.ailabapi.com/api/portrait/effects/face-attribute-editing', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.ailabapi.com/api/portrait/effects/face-attribute-editing",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"action_type\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"quality_control\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"face_location\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"target\"\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Content-Type: multipart/form-data",
"ailabapi-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://www.ailabapi.com/api/portrait/effects/face-attribute-editing"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"action_type\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"quality_control\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"face_location\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"target\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("ailabapi-api-key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://www.ailabapi.com/api/portrait/effects/face-attribute-editing")
.header("ailabapi-api-key", "<api-key>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"action_type\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"quality_control\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"face_location\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"target\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.ailabapi.com/api/portrait/effects/face-attribute-editing")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["ailabapi-api-key"] = '<api-key>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"action_type\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"quality_control\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"face_location\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"target\"\r\n\r\n<string>\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"request_id": "",
"log_id": "",
"error_detail": {
"code": "",
"code_message": "",
"message": ""
},
"result": {
"image": ""
}
}Request
- URL:
https://www.ailabapi.com/api/portrait/effects/face-attribute-editing - Method:
POST - Content-Type:
multipart/form-data
Image requirements
- Image format:
JPEGJPGPNGBMP - Image size: No more than 4 MB.
- Image resolution: Larger than 256x256px, smaller than 4096x4096px. The face area must be 64x64px or more.
Headers
| Field | Required | Type | Description |
|---|---|---|---|
ailabapi-api-key | YES | string | Application API KEY. Get API KEY |
Body
Fixed Fields
| Field | Required | Type | Scope | Default | Description |
|---|---|---|---|---|---|
image | YES | file | |||
action_type | YES | string | TO_KID, TO_OLD, TO_FEMALE, TO_MALE, V2_AGE, V2_GENDER | TO_KID`: V1 version becomes a child.`, TO_OLD: V1 version becomes old man., TO_FEMALE`: V1 version becomes girls.`, TO_MALE: V1 version becomes boys., V2_AGE`: V2 version age change.`, V2_GENDER: v2 version gender shift. | |
quality_control | NO | string | NONE, LOW, NORMAL, HIGH | NONE | NONE`: No control is performed.`, LOW: Lower quality requirements., NORMAL`: General quality requirements.`, HIGH: Higher quality requirements. |
face_location | NO | json string | When multiple faces are detected in the image, use this parameter to specify the position of the face to be edited in the image, or default to the largest face in the image if not specified. More Details |
action_type === V2_AGE
| Field | Required | Type | Scope | Description |
|---|---|---|---|---|
target | YES | integer | [1, 85] | Age. |
action_type === V2_GENDER
| Field | Required | Type | Scope | Description |
|---|---|---|---|---|
target | YES | integer | 0, 1 | Gender. 0`: Male.` 1: Female. |
quality_control
The quality control thresholds corresponding to different control systems: If any quality information detected does not meet the requirements of the control threshold, an error will be returned.
quality_control = LOW | quality_control = NORMAL | quality_control = HIGH | Scope | Description |
|---|---|---|---|---|
0.8 | 0.6 | 0.2 | [0, 1] | The proportion of the left eye being obscured. 1 indicates complete obstruction. |
0.8 | 0.6 | 0.2 | [0, 1] | The proportion of the right eye being obscured. 1 indicates complete obstruction. |
0.8 | 0.6 | 0.2 | [0, 1] | The proportion of the nose being obscured. 1 indicates complete obstruction. |
0.8 | 0.6 | 0.2 | [0, 1] | The proportion of the mouth being obscured. 1 indicates complete obstruction. |
0.8 | 0.6 | 0.2 | [0, 1] | The proportion of the left cheek being obscured. 1 indicates complete obstruction. |
0.8 | 0.6 | 0.2 | [0, 1] | The proportion of the right cheek being obscured. 1 indicates complete obstruction. |
0.8 | 0.6 | 0.2 | [0, 1] | The proportion of the chin being obscured. 1 indicates complete obstruction. |
20 | 40 | 100 | [0, 255] | Lighting. 0 indicates poor lighting. |
0.8 | 0.6 | 0.2 | [0, 1] | Image blur. 1 indicates complete blur. |
0 | 0 | 1 | 0, 1 | Completeness of the face. 0`: The face overflows the image boundaries.` 1: The entire face is within the image boundaries. |
45 | 30 | 20 | [-90 (left), 90 (right)] | Left-right rotation angle in three-dimensional rotation. A threshold of 30 indicates that the absolute value of the angle must be within 30. |
45 | 30 | 20 | [-180 (counterclockwise), 180 (clockwise)] | Rotation angle within the plane. A threshold of 30 indicates that the absolute value of the angle must be within 30. |
45 | 30 | 20 | [-90 (up), 90 (down)] | Pitch angle in three-dimensional rotation. A threshold of 30 indicates that the absolute value of the angle must be within 30. |
face_location
-
Request Example
{"left":111.4,"top":96.56,"width":98,"height":98,"rotation":3}
Response
Response Field Handling Flow
-
Handle
Public Response FieldsParse and validate thePublic Response Fields, checking the status code or response message to ensure the request is successful and error-free. -
Handle
Business Response FieldsIf thePublic Response Fieldsare valid and error-free, proceed with processing the business logic in theBusiness Response Fields.
Public Response Fields
Viewing Public Response Fields and Error CodesBusiness Response Fields
| Field | Type | Description |
|---|---|---|
result | object | The content of the result data returned. |
+image | string | The BASE64 value of the edited image. |
Response Example
{
"request_id": "",
"log_id": "",
"error_code": 0,
"error_msg": "",
"error_detail": {
"status_code": 200,
"code": "",
"code_message": "",
"message": ""
},
"result": {
"image": ""
}
}
Authorizations
API Key for authentication
Body
multipart/form-data
Face editing method.
TO_KID: V1 version becomes a child.TO_OLD: V1 version becomes old man.TO_FEMALE: V1 version becomes girls.TO_MALE: V1 version becomes boys.V2_AGE: V2 version age change.V2_GENDER: v2 version gender shift.
Image quality (image field image quality).
Please select the appropriate option based on quality information such as masking, lighting, blurriness, and integrity of the face.
If selecting a higher quality causes the image to be unprocessable, please select a lower quality to try.
NONE: No control is performed.LOW: Lower quality requirements.NORMAL: General quality requirements.HIGH: Higher quality requirements.
When multiple faces are detected in the image, use this parameter to specify the position of the face to be edited in the image, or default to the largest face in the image if not specified.
Response
200 - application/json
Success
The response is of type object.
⌘I

