The resources (image, video, voice) generated by our API are valid for 7 days. Please save the relevant resources as soon as possible to prevent expiration.
Experience our face swap technology in action by exploring our interactive demo on GitHub: AKool Face Swap Demo.

Image Faceswap

POST https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyimage
Request Headers
ParameterValueDescription
AuthorizationBearer {token}Your API Key used for request authorization.getToken
Body Attributes
ParameterTypeValueDescription
targetImageArray[{path:"",opts:""}]A collection of faces in the original image(Each array element is an object, and the object contains 2 properties, path:Links to faces detected in the original image.opts: Key information of faces detected in original pictures(You can get it through the face https://sg3.akool.com/detect API,You can get the landmarks_str value returned by the api interface as the value of opts)
sourceImageArray[{path:"",opts:""}]Replacement target image information.(Each array element is an object, and the object contains 2 properties, path:Links to faces detected in target images.opts: Key information of the face detected in the target image(You can get it through the face https://sg3.akool.com/detect API,You can get the landmarks_str value returned by the api interface as the value of opts)
face_enhanceInt0 or 1Whether facial enhancement: 1 means open, 0 means close
modifyImageStringModify the link address of the image
webhookUrlStringCallback url address based on HTTP request
Response Attributes
ParameterTypeValueDescription
codeint1000Interface returns business status code(1000: success)
msgStringInterface returns status information
dataObject{_id:"",url: "",job_id: ""}_id: Interface returns data url: faceswwap result url job_id: Task processing unique id
Example Body
{
    "targetImage": [    // A collection of faces in the original image
        {
            "path": "https://d21ksh0k4smeql.cloudfront.net/crop_1694593694387-4562-0-1694593694575-0526.png", // Links to faces detected in the original image
            "opts": "262,175:363,175:313,215:272,279" // Key information of faces detected in original pictures【You can get it through the face https://sg3.akool.com/detect API,You can get the landmarks_str value returned by the api interface as the value of opts
        }
    ],
    "sourceImage": [    // Replacement target image information
        {
            "path": "https://d21ksh0k4smeql.cloudfront.net/crop_1705462509874-9254-0-1705462510015-9261.png",  // Links to faces detected in target images
            "opts": "239,364:386,366:317,472:266,539"   // Key information of the face detected in the target image【You can get it through the face https://sg3.akool.com/detect API,You can get the landmarks_str value returned by the api interface as the value of opts
        }
    ],
    "face_enhance": 0,  // Whether facial enhancement: 1 means open, 0 means close
    "modifyImage": "https://d21ksh0k4smeql.cloudfront.net/bdd1c994c4cd7a58926088ae8a479168-1705462506461-1966.jpeg", // Modify the link address of the image
    "webhookUrl":"http://localhost:3007/api/webhook" // Callback url address based on HTTP request
}
Request
curl -X POST --location "https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyimage" \
    -H "Authorization: Bearer token" \
    -H "Content-Type: application/json" \
    -d '{
          "sourceImage": [
            {
              "path": "https://d21ksh0k4smeql.cloudfront.net/crop_1694593694387-4562-0-1694593694575-0526.png",
              "opts": "262,175:363,175:313,215:272,279"
            }
          ],
          "targetImage": [
            {
              "path": "https://d21ksh0k4smeql.cloudfront.net/crop_1705462509874-9254-0-1705462510015-9261.png",
              "opts": "239,364:386,366:317,472:266,539"
            }
          ],
          "face_enhance": 0,
          "modifyImage": "https://d21ksh0k4smeql.cloudfront.net/bdd1c994c4cd7a58926088ae8a479168-1705462506461-1966.jpeg",
          "webhookUrl": "http://localhost:3007/api/webhook"
        }'
Response
{
  "code": 1000, // Interface returns business status code
  "msg": "Please be patient! If your results are not generated in three hours, please check your input image.", // Interface returns status information
  "data": {
    "_id": "6593c94c0ef703e8c055e3c8",  // Interface returns data
    "url": "https://***.cloudfront.net/final_71688047459_.pic-1704184129269-4947-f8abc658-fa82-420f-b1b3-c747d7f18e14-8535.jpg",    // faceswwap result url
    "job_id": "20240102082900592-5653"  // Task processing unique id
  }
}

Video Faceswap

POST https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyvideo
Request Headers
ParameterValueDescription
AuthorizationBearer {token}Your API Key used for request authorization
Body Attributes
ParameterTypeValueDescription
sourceImageArray[{path:"",opts:""}]Replacement target image information:sourceImage means that you need to change it to the link collection of the face you need. You need to pass your image through the https://sg3.akool.com/detect interface. Obtain the link and key point data and fill them here, and ensure that they correspond to the order of the targetImage. You need to pay attention to that each picture in the sourceImage must be a single face, otherwise the face change may fail. (Each array element is an object, and the object contains 2 properties, path:Links to faces detected in the original image. opts: Key information of faces detected in original pictures【You can get it through the face https://sg3.akool.com/detect API, You can get the landmarks_str value returned by the api interface as the value of opts)
targetImageArray[{path:"",opts:""}]A collection of faces in the original video: targetImage represents the collection of faces after face detection using modifyVideo. When the original video has multiple faces, here is the image link and key point data of each face. You need to pass https://sg3.akool.com/detect interface to obtain data.(Each array element is an object, and the object contains 2 properties, path:Links to faces detected in target images. opts: Key information of the face detected in the target image【You can get it through the face https://sg3.akool.com/detect API, You can get the landmarks_str value returned by the api interface as the value of opts)
face_enhanceInt0 or 1Whether facial enhancement: 1 means open, 0 means close
modifyVideoStringmodifyImage represents the original image you need to change the face
webhookUrlStringCallback url address based on HTTP request
Response Attributes
ParameterTypeValueDescription
codeint1000Interface returns business status code(1000: success)
msgStringInterface returns status information
dataObject{_id:"",url: "",job_id: ""}_id: Interface returns data url: faceswwap result url job_id: Task processing unique id
Example Body
{
    "sourceImage": [    // Replacement target image information: sourceImage means that you need to change it to the link collection of the face you need. You need to pass your image through the https://sg3.akool.com/detect interface. Obtain the link and key point data and fill them here, and ensure that they correspond to the order of the targetImage. You need to pay attention to that each picture in the sourceImage must be a single face, otherwise the face change may fail.
        {
            "path": "https://d21ksh0k4smeql.cloudfront.net/crop_1705475757658-3362-0-1705475757797-3713.png",   // Links to faces detected in the original image
            "opts": "239,364:386,366:317,472:266,539"   // Key information of faces detected in original pictures【You can get it through the face https://sg3.akool.com/detect API,You only need to enter the first 4 items of the content array of the landmarks field of the returned data, and concatenate them into a string through ":", like this: ["434,433","588,449","509,558","432,614", "0,0", "0,0"] to "434,433:588,449:509,558:432,614"】
        }
    ],
    "targetImage": [    //  A collection of faces in the original video: targetImage represents the collection of faces after face detection using modifyVideo. When the original image has multiple faces, here is the image link and key point data of each face. You need to pass https://sg3.akool.com/detect interface to obtain data
        {
            "path": "https://d21ksh0k4smeql.cloudfront.net/crop_1705479323786-0321-0-1705479323896-7695.png",   // Links to faces detected in target images
            "opts": "176,259:243,259:209,303:183,328" // Key information of the face detected in the target image【You can get it through the face https://sg3.akool.com/detect API,You only need to enter the first 4 items of the content array of the landmarks field of the returned data, and concatenate them into a string through ":", like this: ["1622,759","2149,776","1869,1085","1875,1345", "0,0", "0,0"] to "1622,759:2149,776:1869,1085:1875,1345"】
        }
    ],
    "face_enhance":0,
    "modifyVideo": "https://d21ksh0k4smeql.cloudfront.net/avatar_01-1705479314627-0092.mp4",    // modifyImage represents the original image you need to change the face;
    "webhookUrl":"http://localhost:3007/api/webhook2" // Callback url address based on HTTP request

}
Request
curl --location 'https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyvideo' \
--header 'Authorization: Bearer token' \
--header 'Content-Type: application/json' \
--data '{
    "sourceImage": [
        {
            "path": "https://d21ksh0k4smeql.cloudfront.net/crop_1705475757658-3362-0-1705475757797-3713.png",
            "opts": "239,364:386,366:317,472:266,539"
        }
    ],
    "targetImage": [
        {
            "path": "https://d21ksh0k4smeql.cloudfront.net/crop_1705479323786-0321-0-1705479323896-7695.png",
            "opts": "176,259:243,259:209,303:183,328"
        }
    ],
    "face_enhance": 0,
    "modifyVideo": "https://d21ksh0k4smeql.cloudfront.net/avatar_01-1705479314627-0092.mp4",
    "webhookUrl":"http://localhost:3007/api/webhook2"

}'
Response
{
  "code": 1000, // Interface returns business status code
  "msg": "Please be patient! If your results are not generated in three hours, please check your input image.", // Interface returns status information
  "data": {
    "_id": "6582bf774e47940151d8fa1e",  // db id
    "url": "https://***.cloudfront.net/final_1703067481578-7151-1703067481578-7151-470fbfbc-ab77-4868-a7f4-dbba1ec4f1c9-3478.jpg",  // faceswwap result url
    "job_id": "20231220101831489-3860"  // Task processing unique id
  }
}

Get Faceswap Result List Byids

GET https://openapi.akool.com/api/open/v3/faceswap/result/listbyids?_ids=64ef2f27b33f466877701c6a
Request Headers
ParameterValueDescription
AuthorizationBearer {token}Your API Key used for request authorization.getToken
Query Attributes
ParameterTypeValueDescription
_idsStringresult ids are strings separated by commas【You can get it by returning the _id field from https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyimage or https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyvideo api.】
Response Attributes
ParameterTypeValueDescription
codeint1000Interface returns business status code(1000: success)
msgStringInterface returns status information
dataObjectresult: [{faceswap_status:"",url: "",createdAt: ""}]faceswap_status: faceswap result status: 1 In Queue 2 Processing 3 Success 4 failed url: faceswwap result url createdAt: current faceswap action created time
Example Request
curl --location 'https://openapi.akool.com/api/open/v3/faceswap/result/listbyids?_ids=64ef2f27b33f466877701c6a' \
--header 'Authorization: Bearer token'
Response
{
  "code": 1000,   // error code
  "msg": "OK",    // api message
  "data": {
    "result": [
      {
        "faceswap_type": 1,
        "faceswap_quality": 2,
        "faceswap_status": 1,   // faceswap result status: 1 In Queue 2 Processing 3 Success 4 failed
        "deduction_status": 1,
        "image": 1,
        "video_duration": 0,
        "deduction_duration": 0,
        "update_time": 0,
        "_id": "64dae65af6e250d4fb2bca63",
        "userId": "64d985c5571729d3e2999477",
        "uid": 378337,
        "url": "https://d21ksh0k4smeql.cloudfront.net/final_material__d71fad6e-a464-43a5-9820-6e4347dce228-80554b9d-2387-4b20-9288-e939952c0ab4-0356.jpg", // faceswwap result url
        "createdAt": "2023-08-15T02:43:38.536Z"    // current faceswap action created time
      }
    ]
  }
}

GET Faceswap User Credit Info

GET https://openapi.akool.com/api/open/v3/faceswap/quota/info
Request Headers
ParameterValueDescription
AuthorizationBearer {token}Your API Key used for request authorization.getToken
Response Attributes
ParameterTypeValueDescription
codeint1000Interface returns business status code(1000: success)
msgStringInterface returns status information
dataObject{"credit": 0 }credit: Account balance
Example Request
curl --location 'https://openapi.akool.com/api/open/v3/faceswap/quota/info' \
--header 'Authorization: Bearer token'
Response
{
  "code": 1000, // Business status code
  "msg": "OK",  // The interface returns status information
  "data": {
    "credit": 0 // Account balance
  }
}

POST Faceswap Result Del Byids

POST https://openapi.akool.com/api/open/v3/faceswap/result/delbyids
Request Headers
ParameterValueDescription
AuthorizationBearer {token}Your API Key used for request authorization.getToken
Body Attributes
ParameterTypeValueDescription
_idsStringresult ids are strings separated by commas
Response Attributes
ParameterTypeValueDescription
codeint1000Interface returns business status code(1000:success)
msgStringInterface returns status information
Example Body
{
    "_ids":""//result ids are strings separated by commas
}
Request

curl --location 'https://openapi.akool.com/api/open/v3/faceswap/result/delbyids' \
--header 'Authorization: Bearer token' \
--header 'Content-Type: application/json' \
--data '{
    "_ids":""
}'
Response
{
  "code": 1000, // Business status code
  "msg": "OK"   // The interface returns status information
}

Face Detect

POST https://sg3.akool.com/detect
Request Headers
ParameterValueDescription
AuthorizationBearer {token}Your API Key used for request authorization.getToken
Body Attributes
ParameterTypeValueDescription
single_faceBooleantrue/falseIs it a single face picture: This should be true when the incoming picture has only one face, and false when the incoming picture has multiple faces.
image_urlStringimage link: You can choose to enter this parameter or the img parameter.
imgStringImage base64 information: You can choose to enter this parameter or the image_url parameter.
Response Attributes
ParameterTypeValueDescription
error_codeint0Interface returns business status code(0:success)
error_msgStringerror message of this api
landmarksArray[]Key point data of face
Example Body
{
  "single_face": false, // Is it a single face picture: This should be true when the incoming picture has only one face, and false when the incoming picture has multiple faces.
  "image_url":"https://d21ksh0k4smeql.cloudfront.net/IMG_6150-1696984459910-0610.jpeg",   // image link:You can choose to enter this parameter or the img parameter.
  "img": "data:image/jpeg;base64***"    // Image base64 information:You can choose to enter this parameter or the image_url parameter.
}
Request
curl --location 'https://sg3.akool.com/detect' \
--header 'Authorization: Bearer token' \
--header 'Content-Type: application/json' \
--data '{
  "single_face": false,
  "image_url":"https://d21ksh0k4smeql.cloudfront.net/IMG_6150-1696984459910-0610.jpeg",
  "img": "data:image/jpeg;base64***"
}'
Response
{
  "error_code": 0,  // error code: 0 is seccuss
  "error_msg": "SUCCESS",   // error message of this api
  "landmarks": [    // Key point data of face
    [
            [
                238,365
            ],
            [
                386,363
            ],
            [
                318,470
            ],
            [
                267,539
            ],
            [
                0,0
            ],
            [
                0,0
            ]
        ]
  ],
  "landmarks_str": [
        "238,365:386,363:318,470:267,539"
    ],
  "region": [
        [
            150,195,317,429
        ]
    ],
  "seconds": 0.04458212852478027,   // API time-consuming
  "trx_id": "74178dc5-199a-479a-89d0-4b0e1c161219"
}
Response Code Description
Please note that if the value of the response code is not equal to 1000, the request is failed or wrong
ParameterValueDescription
code1000Success
code1003Parameter error or Parameter can not be empty
code1005Operation is too frequent
code1006Your quota is not enough
code1007The number of people who can have their faces changed cannot exceed 8
code1101Invalid authorization or The request token has expired
code1102Authorization cannot be empty
code1200The account has been banned