> ## Documentation Index
> Fetch the complete documentation index at: https://docstest.akool.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Face Swap

<Warning>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.</Warning>

<Info>
  Experience our face swap technology in action by exploring our interactive demo on GitHub: [AKool Face Swap Demo](https://github.com/AKOOL-Official/akool-face-swap-demo).
</Info>

### Image Faceswap

```bash theme={null}
POST https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyimage
```

**Request Headers**

| **Parameter** | **Value**        | **Description**                                                                                                   |
| ------------- | ---------------- | ----------------------------------------------------------------------------------------------------------------- |
| Authorization | Bearer `{token}` | Your API Key used for request authorization.[getToken](https://docs.akool.com/authentication/usage#get-the-token) |

**Body Attributes**

| **Parameter** | **Type** | **Value**             | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ------------- | -------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| targetImage   | Array    | `[{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](https://docs.akool.com/ai-tools-suite/faceswap#face-detect) API,You can get the landmarks\_str value returned by the api interface as the value of opts) |
| sourceImage   | Array    | `[{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](https://docs.akool.com/ai-tools-suite/faceswap#face-detect) API,You can get the landmarks\_str value returned by the api interface as the value of opts)          |
| face\_enhance | Int      | 0 or 1                | Whether facial enhancement: 1 means open， 0 means close                                                                                                                                                                                                                                                                                                                                                                                                    |
| modifyImage   | String   |                       | Modify the link address of the image                                                                                                                                                                                                                                                                                                                                                                                                                       |
| webhookUrl    | String   |                       | Callback url address based on HTTP request                                                                                                                                                                                                                                                                                                                                                                                                                 |

**Response Attributes**

| Parameter | Type   | Value                         | Description                                                                               |
| --------- | ------ | ----------------------------- | ----------------------------------------------------------------------------------------- |
| code      | int    | 1000                          | Interface returns business status code(1000: success)                                     |
| msg       | String |                               | Interface returns status information                                                      |
| data      | Object | `{_id:"",url: "",job_id: ""}` | \_id: Interface returns data url: faceswwap result url job\_id: Task processing unique id |

**Example**

**Body**

```json theme={null}
{
    "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":"" // Callback url address based on HTTP request
}
```

**Request**

<CodeGroup>
  ```bash cURL theme={null}
  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": ""
          }'
  ```

  ```java Java theme={null}
  OkHttpClient client = new OkHttpClient().newBuilder()
    .build();
  MediaType mediaType = MediaType.parse("application/json");
  RequestBody body = RequestBody.create(mediaType, "{\n    \"sourceImage\": [    \n        {\n            \"path\": \"https://d21ksh0k4smeql.cloudfront.net/crop_1694593694387-4562-0-1694593694575-0526.png\", \n            \"opts\": \"262,175:363,175:313,215:272,279\" \n        }\n    ],\n    \"targetImage\": [    \n        {\n            \"path\": \"https://d21ksh0k4smeql.cloudfront.net/crop_1705462509874-9254-0-1705462510015-9261.png\",  \n            \"opts\": \"239,364:386,366:317,472:266,539\"   \n        }\n    ],\n    \"face_enhance\": 0,  \n    \"modifyImage\": \"https://d21ksh0k4smeql.cloudfront.net/bdd1c994c4cd7a58926088ae8a479168-1705462506461-1966.jpeg\", \n    \"webhookUrl\":\"\" \n}");
  Request request = new Request.Builder()
    .url("https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyimage")
    .method("POST", body)
    .addHeader("Authorization", "Bearer token")
    .addHeader("Content-Type", "application/json")
    .build();
  Response response = client.newCall(request).execute();
  ```

  ```js Javascript theme={null}
  const myHeaders = new Headers();
  myHeaders.append("Authorization", "Bearer token");
  myHeaders.append("Content-Type", "application/json");

  const raw = JSON.stringify({
    "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": ""
  });

  const requestOptions = {
    method: "POST",
    headers: myHeaders,
    body: raw,
    redirect: "follow"
  };

  fetch("https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyimage", requestOptions)
    .then((response) => response.text())
    .then((result) => console.log(result))
    .catch((error) => console.error(error));
  ```

  ```php PHP   theme={null}
  <?php
  $client = new Client();
  $headers = [
    'Authorization' => 'Bearer token',
    'Content-Type' => 'application/json'
  ];
  $body = '{
    "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": ""
  }';
  $request = new Request('POST', 'https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyimage', $headers, $body);
  $res = $client->sendAsync($request)->wait();
  echo $res->getBody();
  ```

  ```python Python   theme={null}
  import requests
  import json

  url = "https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyimage"

  payload = json.dumps({
    "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": ""
  })
  headers = {
    'Authorization': 'Bearer token',
    'Content-Type': 'application/json'
  }

  response = requests.request("POST", url, headers=headers, data=payload)

  print(response.text)
  ```
</CodeGroup>

**Response**

```json theme={null}
{
  "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
  }
}
```

### V4 Image Faceswap (Simplified)

```bash theme={null}
POST https://openapi.akool.com/api/open/v4/faceswap/faceswapByImage
```

**Request Headers**

| **Parameter** | **Value**        | **Description**                                                                                                   |
| ------------- | ---------------- | ----------------------------------------------------------------------------------------------------------------- |
| Authorization | Bearer `{token}` | Your API Key used for request authorization.[getToken](https://docs.akool.com/authentication/usage#get-the-token) |

**Body Attributes**

| **Parameter** | **Type** | **Value**                    | **Description**                                                                                                                                                                                     |
| ------------- | -------- | ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| targetImage   | Array    | `[{path:""}]`                | A collection of faces in the original image (Each array element is an object containing path: Links to faces in the original image)                                                                 |
| sourceImage   | Array    | `[{path:""}]`                | Replacement target image information (Each array element is an object containing path: Links to replacement faces)                                                                                  |
| model\_name   | String   | "akool\_faceswap\_image\_hq" | The model name used for face swap processing. Enum: \["akool\_faceswap\_image\_hq"]. The 'akool\_faceswap\_image\_hq' model only supports high-quality face swapping for a single face in an image. |
| webhookUrl    | String   |                              | Callback url address based on HTTP request                                                                                                                                                          |

**Response Attributes**

| Parameter | Type   | Value                         | Description                                                                              |
| --------- | ------ | ----------------------------- | ---------------------------------------------------------------------------------------- |
| code      | Int    | 1000                          | Interface returns business status code(1000: success)                                    |
| msg       | String |                               | Interface returns status information                                                     |
| data      | Object | `{_id:"",url: "",job_id: ""}` | \_id: Interface returns data url: faceswap result url job\_id: Task processing unique id |

**Example**

**Body**

```json theme={null}
{
    "targetImage": [    // A collection of faces in the original image
        {
            "path": "https://drz0f01yeq1cx.cloudfront.net/1756283639652-91bbc793c9a44830ba3dc5f4ae9d9793-12.png" // Links to faces detected in the original image
        }
    ],
    "sourceImage": [    // Replacement target image information
        {
            "path": "https://d3fulx9g4ogwhk.cloudfront.net/canva_backend/255b106e-6629-4d64-a2ac-e54d905959ca.jpeg"  // Links to faces detected in target images
        }
    ],
    "model_name": "akool_faceswap_image_hq",    // Model name for face swap processing
    "webhookUrl":"https://landing-test.akool.io/interface/stats-api/api/open/v5/faceswap/faceswapByImage" // Callback url address based on HTTP request
}
```

**Request**

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST --location "https://openapi.akool.com/api/open/v4/faceswap/faceswapByImage" \
      -H "Authorization: Bearer token" \
      -H "Content-Type: application/json" \
      -d '{
            "targetImage": [
              {
                "path": "https://drz0f01yeq1cx.cloudfront.net/1756283639652-91bbc793c9a44830ba3dc5f4ae9d9793-12.png"
              }
            ],
            "sourceImage": [
              {
                "path": "https://d3fulx9g4ogwhk.cloudfront.net/canva_backend/255b106e-6629-4d64-a2ac-e54d905959ca.jpeg"
              }
            ],
            "model_name": "akool_faceswap_image_hq",
            "webhookUrl": "https://landing-test.akool.io/interface/stats-api/api/open/v5/faceswap/faceswapByImage"
          }'
  ```

  ```java Java theme={null}
  OkHttpClient client = new OkHttpClient().newBuilder()
    .build();
  MediaType mediaType = MediaType.parse("application/json");
  RequestBody body = RequestBody.create(mediaType, "{\n    \"targetImage\": [\n        {\n            \"path\": \"https://drz0f01yeq1cx.cloudfront.net/1756283639652-91bbc793c9a44830ba3dc5f4ae9d9793-12.png\"\n        }\n    ],\n    \"sourceImage\": [\n        {\n            \"path\": \"https://d3fulx9g4ogwhk.cloudfront.net/canva_backend/255b106e-6629-4d64-a2ac-e54d905959ca.jpeg\"\n        }\n    ],\n    \"model_name\": \"akool_faceswap_image_hq\",\n    \"webhookUrl\": \"https://landing-test.akool.io/interface/stats-api/api/open/v5/faceswap/faceswapByImage\"\n}");
  Request request = new Request.Builder()
    .url("https://openapi.akool.com/api/open/v4/faceswap/faceswapByImage")
    .method("POST", body)
    .addHeader("Authorization", "Bearer token")
    .addHeader("Content-Type", "application/json")
    .build();
  Response response = client.newCall(request).execute();
  ```

  ```js Javascript theme={null}
  const myHeaders = new Headers();
  myHeaders.append("Authorization", "Bearer token");
  myHeaders.append("Content-Type", "application/json");

  const raw = JSON.stringify({
    "targetImage": [
      {
        "path": "https://drz0f01yeq1cx.cloudfront.net/1756283639652-91bbc793c9a44830ba3dc5f4ae9d9793-12.png"
      }
    ],
    "sourceImage": [
      {
        "path": "https://d3fulx9g4ogwhk.cloudfront.net/canva_backend/255b106e-6629-4d64-a2ac-e54d905959ca.jpeg"
      }
    ],
    "model_name": "akool_faceswap_image_hq",
    "webhookUrl": "https://landing-test.akool.io/interface/stats-api/api/open/v5/faceswap/faceswapByImage"
  });

  const requestOptions = {
    method: "POST",
    headers: myHeaders,
    body: raw,
    redirect: "follow"
  };

  fetch("https://openapi.akool.com/api/open/v4/faceswap/faceswapByImage", requestOptions)
    .then((response) => response.text())
    .then((result) => console.log(result))
    .catch((error) => console.error(error));
  ```

  ```php PHP   theme={null}
  <?php
  $client = new Client();
  $headers = [
    'Authorization' => 'Bearer token',
    'Content-Type' => 'application/json'
  ];
  $body = '{
    "targetImage": [
      {
        "path": "https://drz0f01yeq1cx.cloudfront.net/1756283639652-91bbc793c9a44830ba3dc5f4ae9d9793-12.png"
      }
    ],
    "sourceImage": [
      {
        "path": "https://d3fulx9g4ogwhk.cloudfront.net/canva_backend/255b106e-6629-4d64-a2ac-e54d905959ca.jpeg"
      }
    ],
    "model_name": "akool_faceswap_image_hq",
    "webhookUrl": "https://landing-test.akool.io/interface/stats-api/api/open/v5/faceswap/faceswapByImage"
  }';
  $request = new Request('POST', 'https://openapi.akool.com/api/open/v4/faceswap/faceswapByImage', $headers, $body);
  $res = $client->sendAsync($request)->wait();
  echo $res->getBody();
  ```

  ```python Python   theme={null}
  import requests
  import json

  url = "https://openapi.akool.com/api/open/v4/faceswap/faceswapByImage"

  payload = json.dumps({
    "targetImage": [
      {
        "path": "https://drz0f01yeq1cx.cloudfront.net/1756283639652-91bbc793c9a44830ba3dc5f4ae9d9793-12.png"
      }
    ],
    "sourceImage": [
      {
        "path": "https://d3fulx9g4ogwhk.cloudfront.net/canva_backend/255b106e-6629-4d64-a2ac-e54d905959ca.jpeg"
      }
    ],
    "model_name": "akool_faceswap_image_hq",
    "webhookUrl": "https://landing-test.akool.io/interface/stats-api/api/open/v5/faceswap/faceswapByImage"
  })
  headers = {
    'Authorization': 'Bearer token',
    'Content-Type': 'application/json'
  }

  response = requests.request("POST", url, headers=headers, data=payload)

  print(response.text)
  ```
</CodeGroup>

**Response**

```json theme={null}
{
  "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",    // faceswap 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**

| **Parameter** | **Value**        | **Description**                             |
| ------------- | ---------------- | ------------------------------------------- |
| Authorization | Bearer `{token}` | Your API Key used for request authorization |

**Body Attributes**

| **Parameter** | **Type** | **Value**             | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ------------- | -------- | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| sourceImage   | Array    | `[{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](https://docs.akool.com/ai-tools-suite/faceswap#face-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](https://docs.akool.com/ai-tools-suite/faceswap#face-detect) API, You can get the landmarks\_str value returned by the api interface as the value of opts) |
| targetImage   | Array    | `[{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](https://docs.akool.com/ai-tools-suite/faceswap#face-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](https://docs.akool.com/ai-tools-suite/faceswap#face-detect) API, You can get the landmarks\_str value returned by the api interface as the value of opts)                                                                                                                                                         |
| face\_enhance | Int      | 0 or 1                | Whether facial enhancement: 1 means open， 0 means close                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| modifyVideo   | String   |                       | modifyImage represents the original image you need to change the face                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| webhookUrl    | String   |                       | Callback url address based on HTTP request                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |

**Response Attributes**

| Parameter | Type   | Value                         | Description                                                                                |
| --------- | ------ | ----------------------------- | ------------------------------------------------------------------------------------------ |
| code      | int    | 1000                          | Interface returns business status code(1000: success)                                      |
| msg       | String |                               | Interface returns status information                                                       |
| data      | Object | `{_id:"",url: "",job_id: ""}` | `_id`: Interface returns data url: faceswwap result url job\_id: Task processing unique id |

**Example**

**Body**

```json theme={null}
{
    "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":"" // Callback url address based on HTTP request

}
```

**Request**

<CodeGroup>
  ```bash cURL theme={null}
  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":""

  }'
  ```

  ```java Java  theme={null}
  OkHttpClient client = new OkHttpClient().newBuilder()
    .build();
  MediaType mediaType = MediaType.parse("application/json");
  RequestBody body = RequestBody.create(mediaType, "{\n    \"sourceImage\": [    \n        {\n            \"path\": \"https://d21ksh0k4smeql.cloudfront.net/crop_1705475757658-3362-0-1705475757797-3713.png\",   \n            \"opts\": \"239,364:386,366:317,472:266,539\"   \n        }\n    ],\n    \"targetImage\": [    \n        {\n            \"path\": \"https://d21ksh0k4smeql.cloudfront.net/crop_1705479323786-0321-0-1705479323896-7695.png\",   \n            \"opts\": \"176,259:243,259:209,303:183,328\" \n        }\n    ],\n    \"modifyVideo\": \"https://d21ksh0k4smeql.cloudfront.net/avatar_01-1705479314627-0092.mp4\",    \n    \"webhookUrl\":\"\" \n\n}");
  Request request = new Request.Builder()
    .url("https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyvideo")
    .method("POST", body)
    .addHeader("Authorization", "Bearer token")
    .addHeader("Content-Type", "application/json")
    .build();
  Response response = client.newCall(request).execute();
  ```

  ```js Javascript theme={null}
  const myHeaders = new Headers();
  myHeaders.append("Authorization", "Bearer token");
  myHeaders.append("Content-Type", "application/json");

  const raw = JSON.stringify({
    "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": ""
  });

  const requestOptions = {
    method: "POST",
    headers: myHeaders,
    body: raw,
    redirect: "follow"
  };

  fetch("https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyvideo", requestOptions)
    .then((response) => response.text())
    .then((result) => console.log(result))
    .catch((error) => console.error(error));
  ```

  ```php PHP  theme={null}
  <?php
  $client = new Client();
  $headers = [
    'Authorization' => 'Bearer token',
    'Content-Type' => 'application/json'
  ];
  $body = '{
    "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": ""
  }';
  $request = new Request('POST', 'https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyvideo', $headers, $body);
  $res = $client->sendAsync($request)->wait();
  echo $res->getBody();
  ```

  ```python Python  theme={null}
  import requests
  import json

  url = "https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyvideo"

  payload = json.dumps({
    "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": ""
  })
  headers = {
    'Authorization': 'Bearer token',
    'Content-Type': 'application/json'
  }

  response = requests.request("POST", url, headers=headers, data=payload)

  print(response.text)
  ```
</CodeGroup>

**Response**

```json theme={null}
{
  "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**

| **Parameter** | **Value**        | **Description**                                                                                                   |
| ------------- | ---------------- | ----------------------------------------------------------------------------------------------------------------- |
| Authorization | Bearer `{token}` | Your API Key used for request authorization.[getToken](https://docs.akool.com/authentication/usage#get-the-token) |

**Query Attributes**

| Parameter | Type   | Value | Description                                                                                                                                                                                                                                                                                                                                                                           |
| --------- | ------ | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \_ids     | String |       | result 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](https://docs.akool.com/ai-tools-suite/faceswap#image-faceswap) or [https://openapi.akool.com/api/open/v3/faceswap/highquality/specifyvideo](https://docs.akool.com/ai-tools-suite/faceswap#video-faceswap) api.】 |

**Response Attributes**

| Parameter | Type   | Value                                                  | Description                                                                                                                                                    |
| --------- | ------ | ------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| code      | int    | 1000                                                   | Interface returns business status code(1000: success)                                                                                                          |
| msg       | String |                                                        | Interface returns status information                                                                                                                           |
| data      | Object | `result: [{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**

<CodeGroup>
  ```bash cURL theme={null}
  curl --location 'https://openapi.akool.com/api/open/v3/faceswap/result/listbyids?_ids=64ef2f27b33f466877701c6a' \
  --header 'Authorization: Bearer token'
  ```

  ```java Java  theme={null}
  OkHttpClient client = new OkHttpClient().newBuilder()
    .build();
  MediaType mediaType = MediaType.parse("text/plain");
  RequestBody body = RequestBody.create(mediaType, "");
  Request request = new Request.Builder()
    .url("https://openapi.akool.com/api/open/v3/faceswap/result/listbyids?_ids=64ef2f27b33f466877701c6a")
    .method("GET", body)
    .addHeader("Authorization", "Bearer token")
    .build();
  Response response = client.newCall(request).execute();
  ```

  ```js Javascript theme={null}
  const myHeaders = new Headers();
  myHeaders.append("Authorization", "Bearer token");

  const requestOptions = {
    method: "GET",
    headers: myHeaders,
    redirect: "follow"
  };

  fetch("https://openapi.akool.com/api/open/v3/faceswap/result/listbyids?_ids=64ef2f27b33f466877701c6a", requestOptions)
    .then((response) => response.text())
    .then((result) => console.log(result))
    .catch((error) => console.error(error));
  ```

  ```php PHP  theme={null}
  <?php
  $client = new Client();
  $headers = [
    'Authorization' => 'Bearer token'
  ];
  $request = new Request('GET', 'https://openapi.akool.com/api/open/v3/faceswap/result/listbyids?_ids=64ef2f27b33f466877701c6a', $headers);
  $res = $client->sendAsync($request)->wait();
  echo $res->getBody();
  ```

  ```python Python  theme={null}
  import requests

  url = "https://openapi.akool.com/api/open/v3/faceswap/result/listbyids?_ids=64ef2f27b33f466877701c6a"

  payload = {}
  headers = {
    'Authorization': 'Bearer token'
  }

  response = requests.request("GET", url, headers=headers, data=payload)

  print(response.text)
  ```
</CodeGroup>

**Response**

```json theme={null}
{
  "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**

| **Parameter** | **Value**        | **Description**                                                                                                   |
| ------------- | ---------------- | ----------------------------------------------------------------------------------------------------------------- |
| Authorization | Bearer `{token}` | Your API Key used for request authorization.[getToken](https://docs.akool.com/authentication/usage#get-the-token) |

**Response Attributes**

| Parameter | Type   | Value            | Description                                           |
| --------- | ------ | ---------------- | ----------------------------------------------------- |
| code      | int    | 1000             | Interface returns business status code(1000: success) |
| msg       | String |                  | Interface returns status information                  |
| data      | Object | `{"credit": 0 }` | credit:  Account balance                              |

**Example**

**Request**

<CodeGroup>
  ```bash theme={null}
  curl --location 'https://openapi.akool.com/api/open/v3/faceswap/quota/info' \
  --header 'Authorization: Bearer token'
  ```

  ```java Java  theme={null}
  OkHttpClient client = new OkHttpClient().newBuilder()
    .build();
  MediaType mediaType = MediaType.parse("text/plain");
  RequestBody body = RequestBody.create(mediaType, "");
  Request request = new Request.Builder()
    .url("https://openapi.akool.com/api/open/v3/faceswap/quota/info")
    .method("GET", body)
    .addHeader("Authorization", "Bearer token")
    .build();
  Response response = client.newCall(request).execute();
  ```

  ```js Javascript  theme={null}
  const myHeaders = new Headers();
  myHeaders.append("Authorization", "Bearer token");

  const requestOptions = {
    method: "GET",
    headers: myHeaders,
    redirect: "follow"
  };

  fetch("https://openapi.akool.com/api/open/v3/faceswap/quota/info", requestOptions)
    .then((response) => response.text())
    .then((result) => console.log(result))
    .catch((error) => console.error(error));
  ```

  ```php PHP  theme={null}
  <?php
  $client = new Client();
  $headers = [
    'Authorization' => 'Bearer token'
  ];
  $request = new Request('GET', 'https://openapi.akool.com/api/open/v3/faceswap/quota/info', $headers);
  $res = $client->sendAsync($request)->wait();
  echo $res->getBody();
  ```

  ```python Python  theme={null}
  import requests

  url = "https://openapi.akool.com/api/open/v3/faceswap/quota/info"

  payload = {}
  headers = {
    'Authorization': 'Bearer token'
  }

  response = requests.request("GET", url, headers=headers, data=payload)

  print(response.text)
  ```
</CodeGroup>

**Response**

```json theme={null}
{
  "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**

| **Parameter** | **Value**        | **Description**                                                                                                   |
| ------------- | ---------------- | ----------------------------------------------------------------------------------------------------------------- |
| Authorization | Bearer `{token}` | Your API Key used for request authorization.[getToken](https://docs.akool.com/authentication/usage#get-the-token) |

**Body Attributes**

| Parameter | Type   | Value | Description                                |
| --------- | ------ | ----- | ------------------------------------------ |
| \_ids     | String |       | result ids are strings separated by commas |

**Response Attributes**

| Parameter | Type   | Value | Description                                          |
| --------- | ------ | ----- | ---------------------------------------------------- |
| code      | int    | 1000  | Interface returns business status code(1000:success) |
| msg       | String |       | Interface returns status information                 |

**Example**

**Body**

```json theme={null}
{
    "_ids":""//result ids are strings separated by commas
}
```

**Request**

<CodeGroup>
  ```bash cURL theme={null}

  curl --location 'https://openapi.akool.com/api/open/v3/faceswap/result/delbyids' \
  --header 'Authorization: Bearer token' \
  --header 'Content-Type: application/json' \
  --data '{
      "_ids":""
  }'
  ```

  ```java Java  theme={null}
  OkHttpClient client = new OkHttpClient().newBuilder()
    .build();
  MediaType mediaType = MediaType.parse("application/json");
  RequestBody body = RequestBody.create(mediaType, "{\n    \"_ids\":\"\"\n}");
  Request request = new Request.Builder()
    .url("https://openapi.akool.com/api/open/v3/faceswap/result/delbyids")
    .method("POST", body)
    .addHeader("Authorization", "Bearer token")
    .addHeader("Content-Type", "application/json")
    .build();
  Response response = client.newCall(request).execute();
  ```

  ```js JavaScript  theme={null}
  const myHeaders = new Headers();
  myHeaders.append("Authorization", "Bearer token");
  myHeaders.append("Content-Type", "application/json");

  const raw = JSON.stringify({
    "_ids": ""
  });

  const requestOptions = {
    method: "POST",
    headers: myHeaders,
    body: raw,
    redirect: "follow"
  };

  fetch("https://openapi.akool.com/api/open/v3/faceswap/result/delbyids", requestOptions)
    .then((response) => response.text())
    .then((result) => console.log(result))
    .catch((error) => console.error(error));
  ```

  ```php PHP  theme={null}
  <?php
  $client = new Client();
  $headers = [
    'Authorization' => 'Bearer token',
    'Content-Type' => 'application/json'
  ];
  $body = '{
    "_ids": ""
  }';
  $request = new Request('POST', 'https://openapi.akool.com/api/open/v3/faceswap/result/delbyids', $headers, $body);
  $res = $client->sendAsync($request)->wait();
  echo $res->getBody();
  ```

  ```python Python  theme={null}
  import requests
  import json

  url = "https://openapi.akool.com/api/open/v3/faceswap/result/delbyids"

  payload = json.dumps({
    "_ids": ""
  })
  headers = {
    'Authorization': 'Bearer token',
    'Content-Type': 'application/json'
  }

  response = requests.request("POST", url, headers=headers, data=payload)

  print(response.text)
  ```
</CodeGroup>

**Response**

```json theme={null}
{
  "code": 1000, // Business status code
  "msg": "OK"   // The interface returns status information
}
```

### Face Detect

```
POST https://sg3.akool.com/detect
```

**Request Headers**

| **Parameter** | **Value**        | **Description**                                                                                                   |
| ------------- | ---------------- | ----------------------------------------------------------------------------------------------------------------- |
| Authorization | Bearer `{token}` | Your API Key used for request authorization.[getToken](https://docs.akool.com/authentication/usage#get-the-token) |

**Body Attributes**

| Parameter    | Type    | Value      | Description                                                                                                                                           |
| ------------ | ------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| single\_face | Boolean | true/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   | String  |            | image link: You can choose to enter this parameter or the img parameter.                                                                              |
| img          | String  |            | Image base64 information: You can choose to enter this parameter or the image\_url parameter.                                                         |

**Response Attributes**

| Parameter   | Type   | Value | Description                                       |
| ----------- | ------ | ----- | ------------------------------------------------- |
| error\_code | int    | 0     | Interface returns business status code(0:success) |
| error\_msg  | String |       | error message of this api                         |
| landmarks   | Array  | \[]   | Key point data of face                            |

**Example**

**Body**

```json theme={null}
{
  "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**

<CodeGroup>
  ```bash cURL theme={null}
  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***"
  }'
  ```

  ```java Java  theme={null}
  OkHttpClient client = new OkHttpClient().newBuilder()
    .build();
  MediaType mediaType = MediaType.parse("application/json");
  RequestBody body = RequestBody.create(mediaType, "{\n  \"single_face\": false, \n  \"image_url\":\"https://d21ksh0k4smeql.cloudfront.net/IMG_6150-1696984459910-0610.jpeg\",   \n  \"img\": \"data:image/jpeg;base64***\"    \n}");
  Request request = new Request.Builder()
    .url("https://sg3.akool.com/detect")
    .method("POST", body)
    .addHeader("Authorization", "Bearer token")
    .addHeader("Content-Type", "application/json")
    .build();
  Response response = client.newCall(request).execute();
  ```

  ```js Javascript  theme={null}
  const myHeaders = new Headers();
  myHeaders.append("Authorization", "Bearer token");
  myHeaders.append("Content-Type", "application/json");

  const raw = JSON.stringify({
    "single_face": false,
    "image_url": "https://d21ksh0k4smeql.cloudfront.net/IMG_6150-1696984459910-0610.jpeg",
    "img": "data:image/jpeg;base64***"
  });

  const requestOptions = {
    method: "POST",
    headers: myHeaders,
    body: raw,
    redirect: "follow"
  };

  fetch("https://sg3.akool.com/detect", requestOptions)
    .then((response) => response.text())
    .then((result) => console.log(result))
    .catch((error) => console.error(error));
  ```

  ```php PHP  theme={null}
  <?php
  $client = new Client();
  $headers = [
    'Authorization' => 'Bearer token',
    'Content-Type' => 'application/json'
  ];
  $body = '{
    "single_face": false,
    "image_url": "https://d21ksh0k4smeql.cloudfront.net/IMG_6150-1696984459910-0610.jpeg",
    "img": "data:image/jpeg;base64***"
  }';
  $request = new Request('POST', 'https://sg3.akool.com/detect', $headers, $body);
  $res = $client->sendAsync($request)->wait();
  echo $res->getBody();
  ```

  ```python Python  theme={null}
  import requests
  import json

  url = "https://sg3.akool.com/detect"

  payload = json.dumps({
    "single_face": False,
    "image_url": "https://d21ksh0k4smeql.cloudfront.net/IMG_6150-1696984459910-0610.jpeg",
    "img": "data:image/jpeg;base64***"
  })
  headers = {
    'Authorization': 'Bearer token',
    'Content-Type': 'application/json'
  }

  response = requests.request("POST", url, headers=headers, data=payload)

  print(response.text)
  ```
</CodeGroup>

**Response**

```json theme={null}
{
  "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**

<Note> Please note that if the value of the response code is not equal to 1000, the request is failed or wrong</Note>

| **Parameter** | **Value** | **Description**                                                       |
| ------------- | --------- | --------------------------------------------------------------------- |
| code          | 1000      | Success                                                               |
| code          | 1003      | Parameter error  or Parameter can not be empty                        |
| code          | 1005      | Operation is too frequent                                             |
| code          | 1006      | Your quota is not enough                                              |
| code          | 1007      | The number of people who can have their faces changed cannot exceed 8 |
| code          | 1101      | Invalid authorization or The request token has expired                |
| code          | 1102      | Authorization cannot be empty                                         |
| code          | 1200      | The account has been banned                                           |
