Website API Documentation

Obtaining API Keys

Before you can make API calls, you need to obtain your API key from the API Management Page.

Face Swap (2 Credits)

Perform a face swap based on the URL of the original image and the URL of the face image to be swapped.

**POST api/aifaceswap/v1/faceswap**

Body Attributes

Parameter Type Description
source_image string or file URL or file of the original image to be face-swapped.
face_image string or file URL or file of the face image to be used for the swap.
webhook string Callback URL address for HTTP requests.

Note: If source_image or face_image is not a URL on the aifaceswap server, please provide the complete URL.

Response Attributes

Parameter Type Description
task_id string The unique ID of the task.
points int The points consumed by the task.

Example

  • Request Code
import requests

url = "https://aifaceswap.io/api/aifaceswap/v1/faceswap"
headers = {
  "Authorization": "Bearer xxxx" # your api key
}

# Method1: by image links to generate
data1 = {
  "source_image": "https://temp.aifaceswap.io/aifaceswap/static_img/8a1bce5ea303791589165a5f607e7399.webp",
  "face_image": "https://temp.aifaceswap.io/aifaceswap/static_img/1f153b1ab8d134f1eff57eb527467137.webp",
  "webhook": "http:xxxx.xx/api/task_callback"
}
response = requests.post(url, headers=headers, json=data1)
print(response.json())


# Method2: by local files to generate
files = {
    "source_image": open(r"C:\Users\Administrator\Pictures\5edfb3199e2e846589e60e01645688b2.webp", "rb"),
    "face_image": open(r"C:\Users\Administrator\Pictures\8d797bb6e22f3fb1b533922da009a1df.webp", "rb")
}
data2 = {
    "webhook": "http:xxxx.xx/api/task_callback"
}
response = requests.post(url, headers=headers, data=data2, files=files)
print(response.json())
  • Response
{
    "code": 200,
    "data": {
        "task_id": "4e8f96115346c727c688b81d3700924f",
        "points": 2
    },
    "message": "OK"
}

Webhook Definition

When the results are generated, the aifaceswap server will call the webhook to return the results. Therefore, developers need to define an API endpoint for this purpose.

http:xxxx.xx/api/task_callback

Body Attributes

Parameter Type Description
success int 1 for success, 0 for failure.
type int 1 for single person face swap, 2 for multiple person face swap.
task_id string The unique ID of the task.
result_image string The URL of the result image.

Extract Faces (2 Credits)

For multiple person face swaps, extract all faces from the image.

extract face

POST api/aifaceswap/v1/extract_face

Body Attributes

Parameter Type Description
img string or file URL or file of the image.

Response Attributes

Parameter Type Description
data list List of face positions in the image. Positions are relative to the top-left corner.

Example

  • Example Request Code
import requests

url = "https://aifaceswap.io/api/aifaceswap/v1/extract_face"
headers = {
  "Authorization": "Bearer xxxx" # your api key
}

# Method1: by an image link to extract
data = {
  "img": "https://art-global.yimeta.ai/face-swap/d3a6f7febe4f6490f26f3cf901b72126.webp",
}
response = requests.post(url, headers=headers, json=data)
print(response.json())

# Method2: by a local file to extract
files = {
    "img": open(r"C:\Users\Administrator\Pictures\5edfb3199e2e846589e60e01645688b2.webp", "rb"),
}
response = requests.post(url, headers=headers, files=files)
print(response.json())
  • Response
{
  "code": 200, 
  "data": {
    "faces": [
      [146, 256, 240, 381], 
      [297, 521, 371, 621], 
      [441, 208, 529, 332]
    ], 
    "points": 2
  }, 
  "message": "OK"
}

Multiple Person Face Swap (5 Credits)

Replace one or more faces in an image containing multiple faces.

POST api/aifaceswap/v1/multi_faceswap

Body Attributes

Parameter Type Description
source_image string URL of the image containing multiple faces.
face_image list Array of face images to be swapped.
index list Index corresponding to each face image.
webhook string Callback URL for HTTP requests.

Response Attributes

Parameter Type Description
task_id string Unique ID of the task.
points int Points consumed by the task.

Example

  • Request Code
import requests

url = "https://aifaceswap.io/api/aifaceswap/v1/multi_faceswap"
headers = {
  "accept": "application/json",
  "Authorization": "Bearer xxxx" # your api key
}

# Method1: by image links to generate
data1 = {
    "source_image": "https://art-global.yimeta.ai/face-swap/d3a6f7febe4f6490f26f3cf901b72126.webp",
    "face_image": [
        "https://temp.aifaceswap.io/aifaceswap/static_img/8a1bce5ea303791589165a5f607e7399.webp",
        "https://temp.aifaceswap.io/aifaceswap/static_img/1f153b1ab8d134f1eff57eb527467137.webp"
    ],
    "index": [0, 2],
    "webhook": "http:xxxx.xx/api/task_callback"
}
response = requests.post(url, headers=headers, json=data1)
print(response.json())

# Method2: by local files to generate
source_image_file = open(r"C:\Users\Administrator\Pictures\source.jpg", "rb")
face_image_file1 = open(r"C:\Users\Administrator\Pictures\face1.webp", "rb")
face_image_file2 = open(r"C:\Users\Administrator\Pictures\face2.jpeg", "rb")
files = [
  ("source_image", source_image_file),
  ("face_image", face_image_file1),
  ("face_image", face_image_file2)
]
data2 = {"webhook": "http:xxxx.xx/api/task_callback", "index": [0, 2]}
response = requests.post(url, headers=headers, data=data2, files=files)
print(response.json())

  • Response
{
    "code": 200,
    "data": {
        "points": 5,
        "task_id": "6c3ce398d9e2bdd6abed6d636ec2ac03"
    },
    "message": "OK"
}