InsightFaceSwap /headshot command

Table of contents

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

Use this endpoint to submit the InsightFaceSwap /headshot command to your InsightFaceSwap Discord channel. Results obtained as a callback via optional parameter replyUrl or by querying faceswap/jobs/?jobid=jobid endpoint.

It is important not to use the InsightFaceSwap account setup for API access for any purposes other than its intended use, such as executing /headshot 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/headshot

Request Headers
Authorization: Bearer {API token}
Content-Type: multipart/form-data
# Alternatively you can use application/json
# Content-Type: application/json 
Request Body
{
    "channel": "Discord channel id",
    "prompt": "Background prompt",
    "replyUrl": "Place your call back URL here",
    "replyRef": "Place your reference id here"
}
  • channel is optional when only one faceswap/account configured. However, if you have multiple accounts configured, this parameter becomes required.

  • prompt is required, please refer to InsightFaceSwap /headshot for details.

  • 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

    Use returned jobid to retrieve InsightFaceSwap job status and results or use callback replyUrl.

    Field content contains message generated by InsightFaceSwap.

    {
        "jobid": "<jobid>",
        "verb": "faceswap-headshot",
        "status": "started",
        "prompt": "me, a mad king with an evil smile, wearing medieval royal blue attire and a crown. --no green --square",
        "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": "<@Discord user id>  Picsi.Ai Headshot Job Submitted [jobid: 8a1f574fdbf79e8cd57e070476d9d5f3] [credits: 4] [prompt: 'a mad king with an evil smile, wearing medieval royal blue attire and a crown. --no green --square'] [time: <time>] [SaveID: 'me'] (796/800 credits remaining)",
        "timestamp": "2023-09-09T02:04:51.926000+00:00",
        "code": 200
    }
    
  • 400 Bad Request

    {
        "error": 
          "Required param prompt is missing or empty"
          "Optional param replyRef is too long"
          "Optional param replyUrl is too long"
          "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/headshot 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-headshot',
  status: 'started' | 'failed',
  prompt: 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 
  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/headshot \
         -F "channel=<Discord channel id>" \
         -F "prompt=<prompt>" 
    
  • const main = async () => {
        const apiUrl = "https://api.useapi.net/v1/faceswap/headshot";
        const token = "API token";
        const prompt = "prompt";
        const channel = "Discord channel";
        const data = {
            method: 'POST',
            headers: {
                'Authorization': `Bearer ${token}`
            }
        };
        const formData = new FormData();
        formData.append("prompt", prompt);
        formData.append("channel", channel);
        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/headshot"
    token = "API token"
    prompt = "prompt"
    channel = "Discord channel"
    
    headers = {
        'Authorization': f'Bearer {token}'
    }
    
    files = {
        'prompt': (None, prompt),
        'channel': (None, channel)
    }
    
    response = requests.post(api_url, headers=headers, files=files)
    print(response, response.json())
    
Try It