Skip to main content
POST
/
api
/
portrait
/
editing
/
ai-face-swap
AI Face Swap
curl --request POST \
  --url https://www.ailabapi.com/api/portrait/editing/ai-face-swap \
  --header 'Content-Type: multipart/form-data' \
  --header 'ailabapi-api-key: <api-key>' \
  --form image_target='@example-file' \
  --form image_template='@example-file'
{
  "request_id": "",
  "log_id": "",
  "error_code": 0,
  "error_code_str": "",
  "error_msg": "",
  "error_detail": {
    "status_code": 200,
    "code": "",
    "code_message": "",
    "message": ""
  },
  "task_type": "async",
  "task_id": ""
}

Request

  • URL: https://www.ailabapi.com/api/portrait/editing/ai-face-swap
  • Method: POST
  • Content-Type: multipart/form-data

API Information

FieldValue
API NameAI Face Swap
API URL/api/portrait/editing/ai-face-swap
Documentation URL/docs/ai-portrait/editing/ai-face-swap
Unique identificationportrait_ai_face_swap

Image requirements

FieldRequirements
image_targetImage format: JPEG/JPG/PNG, Image size: No more than 5 MB., Image resolution: Less than 4096x4096px.
image_templateImage format: JPEG/JPG/PNG, Image size: No more than 5 MB., Image resolution: Less than 4096x4096px.

Headers

FieldRequiredTypeDescription
ailabapi-api-keyYESstringApplication API KEY. Get API KEY

Body

FieldRequiredTypeDescription
image_targetYESfileTarget portrait image. The face in this image will be replaced.
image_templateYESfileTemplate portrait image that provides the face to swap.
This API is asynchronous. Submit the request, keep the returned task_id, and call Querying Async Task Results to obtain the final image result.

Response

Response Field Handling Flow
  1. Handle Public Response Fields Parse and validate the Public Response Fields, checking the status code or response message to ensure the request is successful and error-free.
  2. Handle Business Response Fields If the Public Response Fields are valid and error-free, proceed with processing the business logic in the Business Response Fields.

Public Response Fields

Viewing Public Response Fields and Error Codes

Business Response Fields

FieldTypeScopeDescription
task_typestringasyncTask Type. “async: Asynchronous tasks.
task_idstringAsynchronous task ID.
Please use this field when calling the Querying Async Task Results API.

Response Example

{
  "request_id": "",
  "log_id": "",
  "error_code": 0,
  "error_msg": "",
  "error_detail": {
    "status_code": 200,
    "code": "",
    "code_message": "",
    "message": ""
  },
  "task_type": "async",
  "task_id": ""
}

Querying Async Task Results Response

Response Field Handling Flow
  1. Handle Public Response Fields Parse and validate the Public Response Fields, checking the status code or response message to ensure the request is successful and error-free.
  2. Handle Business Response Fields If the Public Response Fields are valid and error-free, proceed with processing the business logic in the Business Response Fields.

Public Response Fields

Viewing Public Response Fields and Error Codes

Business Response Fields

FieldTypeScopeDescription
task_statusinteger0, 1, 2Asynchronous task status. 0`: The task is queued.` 1: Asynchronous processing. “2: Processing was successful.
dataobjectThe result payload returned by the asynchronous task.
+imagestringResult image URL.
The URL address is a temporary address, valid for 24 hours, and will not be accessible after it expires. If you need to save the file for a long time or permanently, please visit the URL address within 24 hours and download the file to your own storage space.

Response Example

{
  "error_code": 0,
  "error_msg": "",
  "error_detail": {
    "status_code": 200,
    "code": "",
    "code_message": "",
    "message": ""
  },
  "task_status": 2,
  "data": {
    "image": "https://***.jpg"
  }
}

Sample Code

Authorizations

ailabapi-api-key
string
header
required

API Key for authentication

Body

multipart/form-data
image_target
file
required

The image to be modified. The face in this image will be replaced.

  • Image format: JPEG JPG PNG
  • Image size: No more than 5 MB.
  • Image resolution: Less than 4096x4096px.
image_template
file
required

The image that provides the face to use.

  • Image format: JPEG JPG PNG
  • Image size: No more than 5 MB.
  • Image resolution: Less than 4096x4096px.

Response

200 - application/json

Success

The response is of type object.