Execute InsightFaceSwap /saveid command immediately following by /swapid command.

Table of contents

  1. Request Headers
  2. Request Body
  3. Responses
  4. Model
  5. Examples
  6. Try It

This endpoint to execute the InsightFaceSwap /saveid and /swapid command as a single call. The result will be returned in the response body and can also be sent as a callback to an optional replyUrl.

Use this endpoint if you want to swap the face from a source image, identified by /saveid, onto a target image designated by /swapid, in a single API call.

This is a blocking call, you will not be able to make another call to the same InsightFaceSwap Discord channel until the current call is completed. The average execution time is approximately 7 to 20 seconds. If you expect high load and need to make multiple concurrent calls, please consider setting up multiple InsightFaceSwap accounts.

It is important not to use the InsightFaceSwap account setup for API access for any purposes other than its intended use, such as executing /swap or any other InsightFaceSwap commands manually or in conjunction with any other automation tools. The useapi.net API internally tracks the usage of the InsightFaceSwap account, including the number of currently active executions. Using it for other activities may cause API to function incorrectly.

https://api.useapi.net/v1/faceswap/swap

Request Headers
Authorization: Bearer {API token}
Content-Type: multipart/form-data
Request Body
{
    "channel": "Discord channel id",
    "saveid_idname": "idname param to be used for /saveid command",
    "saveid_image": "Source image File or Blob",
    "swapid_idname": "idname param to be used for /swapid command",
    "swapid_image": "Target image File or Blob"
}
  • channel is optional, if omitted a randomly selected configured channel with available credits will be used.

  • saveid_idname is optional, if omitted it will default to id. Please refer to InsightFaceSwap /saveid for details.

  • saveid_image is required, image to upload and register for subsequent facial replacement and editing. Must be either a File or Blob object when included in this FormData POST request.

  • swapid_idname is optional, if omitted it will default to id. Please refer to InsightFaceSwap /swapid for details.

  • swapid_image is required, target image to be uploaded for replacing the face identified by the idname parameter mentioned above. Must be either a File or Blob object when included in this FormData POST request.

  • replyUrl is optional, if not provided value from account will be used.
    Place here your callback URL. API will call the provided replyUrl once job completed or failed.
    Maximum length 1024 characters.
    We recommend using sites like webhook.site to test callback URL functionality.

  • replyRef is optional, place here your reference id which will be stored and returned along with this job response / result.
    Maximum length 1024 characters.

Responses
  • 200 OK

    Field content contains message generated by InsightFaceSwap. Attachments array contains generated image.

    {
        "jobid": "<jobid>",
        "verb": "faceswap-swap",
        "status": "completed",
        "saveid_idname": "id",
        "saveid_image": { "size": 2408432, "type": "image/png" },
        "swapid_idname": "id",
        "swapid_image": { "size": 2273656, "type": "image/png" },
        "created": "2023-09-09T02:04:49.667Z",
        "updated": "2023-09-09T02:04:53.490Z",
        "discord": "<ABC…secured…xyz>",
        "server": "<Discord server id>",
        "channel": "<Discord channel id>",
        "replyUrl": "https://webhook.site/abc",
        "replyRef": "<your optional reference id>",
        "messageId": "<Discord message id>",
        "content": "Picsi.Ai ver.2.0 [SaveID: 'id'] [<@Discord user id>] (80/200 credits used)",
        "attachments": [
          {
            "url": "<generated image url>",
            "proxy_url": "<generated proxy image url>",
            "width": 2048,
            "height": 2048,
            "content_type": "<generated image type>",
            "id": "<Discord image id>",
            "filename": "<generated image name>",
            "size": 7204115
          }
        ],
        "timestamp": "2023-09-09T02:04:51.926000+00:00",
        "code": 200
    }
    
  • 400 Bad Request

    {
        "error": 
          "Required param saveid_image is missing or empty"
          "Required param swapid_image is missing or empty"
          "Param saveid_image is not File or Blob"
          "Param swapid_image is not File or Blob"
          "Optional param replyRef is too long"
          "Optional param replyUrl is too long"
          "Required param channel is missing or empty"
          "Configuration not found for channel <channel>, to create POST v1/faceswap/account/<channel>"
        "code": 400
    }
    
  • 401 Unauthorized

    {
        "error": "Unauthorized",
        "code": 401
    }
    
  • 402 Payment Required

    {
        "error": "Account has no subscription or subscription expired",
        "code": 402
    }
    
  • 429 Too Many Requests

    Wait in a loop for at least 10..30 seconds and retry again.

    There are two possible cases for API response 429.

    1. API query is full and can not accept new faceswap/swap requests.
      {
       "error": "Unable to lock Discord after <attempts> attempts",
       "code": 429
      }
      
    2. The API received an HTTP status 429 from the Discord API when it attempted to POST to the /interactions endpoint. Under normal circumstances, this should be a rare occurrence because the API is designed to strictly adhere to Discord rate limits. However, in certain scenarios, Discord may still issue a 429 response.
      {
       "error": "Discord /interactions failed with HTTP status 429",
       "errorDetails": "{\"global\":true,\"message\":\"You are being rate limited.\",\"retry_after\":10}",
       "code": 429
      }
      
Model
{ // TypeScript, all fields are optional
  jobid: string, 
  verb: 'faceswap-swap',
  status: 'completed' | 'failed',
  saveid_idname: string,
  saveid_image: { size: number, type: string },
  swapid_idname: string,
  swapid_image: { size: number, type: string },
  created: string, // YYYY-MM-DDTHH:mm:ss.sssZ, IS0 8601, UTC
  updated: string, // YYYY-MM-DDTHH:mm:ss.sssZ, IS0 8601, UTC
  discord: string, // Provided for debugging purposes only, contains the first 3 and the last 3 characters of the original value
  server: string,
  channel: string,
  replyUrl: string,
  replyRef: string,
  messageId: string,
  content: string, // Contains message generated by InsightFaceSwap 
  attachments: [
      {
          id: string,
          content_type: string,
          filename: string,
          url: string,
          proxy_url: string,
          size: number,
          width: number,
          height: number
      }
  ],  
  timestamp: string,
  error: string,
  errorDetails: string,
  code: number
}
Examples
  • curl -H "Accept: application/json" \
         -H "Authorization: Bearer …" \
         -X POST https://api.useapi.net/v1/faceswap/swap \
         -F "channel=<Discord channel id>" \
         -F 'saveid_image=@"<Path to the image>"' \
         -F "saveid_idname=<idname>" \ 
         -F 'swapid_image=@"<Path to the image>"' \
         -F "swapid_idname=<idname>" 
    
  • const main = async () => {
        const apiUrl = "https://api.useapi.net/v1/faceswap/swap";
        const token = "API token";
        const saveid_idname = "saveid_idname";
        const swapid_idname = "swapid_idname";
        const channel = "Discord channel";
        const data = {
            method: 'POST',
            headers: {
                'Authorization': `Bearer ${token}`
            }
        };
        const formData = new FormData();
        formData.append("saveid_idname", idname);
        formData.append("swapid_idname", idname);
        formData.append("channel", channel);
        /*
            // Example 1: Fetch image from URL
            const imageUrl = "https://upload.wikimedia.org/wikipedia/commons/7/7d/Mona_Lisa_color_restoration.jpg";
            const responseImage = await fetch(imageUrl);
            formData.append("image", await responseImage.blob());
        */
        /* 
            // Example 2: Load image from local file (Blob)
            const fsp = require('fs').promises;
            const imageFileName = "./target_photo.png";
            const blob = new Blob([await fsp.readFile(imageFileName)]);
            formData.append("image", blob);
        */
        /*
            // Example 3: Load from input file html element
            // <input id="target-photo-image-file" type="file"> 
            const imageFile = document.getElementById(`target-photo-image-file`);
            if (imageFile.files[0])
                formData.append("image", imageFile.files[0]);
        */
        data.body = formData;
        const response = await fetch(apiUrl, data);
        const result = await response.json();
        console.log("response", { response, result });
    };
    main()
    
    
  • import requests
    
    api_url = "https://api.useapi.net/v1/faceswap/swap"
    token = "API token"
    saveid_idname = "saveid_idname"
    swapid_idname = "swapid_idname"
    channel = "Discord channel"
    
    headers = {
        'Authorization': f'Bearer {token}'
    }
    
    files = {
        'saveid_idname': (None, saveid_idname),
        'swapid_idname': (None, swapid_idname),
        'channel': (None, channel)
    }
    
    # # Example 1: Fetch image from URL
    # image_url = "https://upload.wikimedia.org/wikipedia/commons/7/7d/Mona_Lisa_color_restoration.jpg"
    # response_image = requests.get(image_url)
    # image_content = response_image.content
    # files['image'] = ('image.jpg', image_content, 'image/jpeg')
    
    # # Example 2: Load image from local file
    # image_file_path = "./target_photo.png"
    # with open(image_file_path, 'rb') as image_file:
    #     files['image'] = ('target_photo.png', image_file.read(), 'image/png')
    
    response = requests.post(api_url, headers=headers, files=files)
    print(response, response.json())
    
Try It