=== URL: https://useapi.net/docs/start-here/setup-faceswap === Document URL: https://useapi.net/docs/start-here/setup-faceswap --- layout: default title: Setup InsightFaceSwap parent: Start Here nav_order: 500 --- # Setup InsightFaceSwap {: .no_toc } ## Table of contents {: .no_toc .text-delta } 1. TOC {:toc} Approximately 3 minutes to complete setup steps. --- ## Create Discord account You need a [Discord](https://discord.com) account to interact with [InsightFaceSwap Discord bot](https://discord.gg/Ym3X8U59ZN). Create a [new account](https://discord.com/register) if you don't have one already. Please note even if you have an existing Discord account we are **strongly** recommending creating a separate Discord account specifically designated to be used with useapi.net API. ## Create Discord server Please log in to your Discord account and create a new Discord server following [official instructions](https://support.discord.com/hc/en-us/articles/204849977-How-do-I-create-a-server-). ## Create `#api` text channel on your Discord server Once you created the Discord server you need to create a designated for API-related work text channel. You can refer to [official instructions](https://support.discord.com/hc/en-us/articles/4412085582359-Text-Channels-Text-Chat-In-Voice-Channels) to learn about Discord channels and how to manage them on your server. We suggest naming the text channel `#api` for clarity and also making that channel private. Please see [Midjourney instructions](https://docs.midjourney.com/docs/invite-the-bot) to learn how you can restrict the bot to a single private channel. ## Join Picsi.Ai - Powered by InsightFace Discord Server Follow Picsi.Ai [instructions](https://github.com/deepinsight/insightface/blob/master/web-demos/swapping_discord/README.md) and join official [Picsi.Ai - Powered by InsightFace Discord Server](https://discord.gg/Ym3X8U59ZN). ## Add InsightFaceSwap bot to your Discord server Please follow [official instructions](https://discord.com/channels/1095014106576212101/1128550062683865178/1189604165006135379) to add InsightFaceSwap bot to your Discord server created earlier. ## Example of Discord server with private `#api` text channel and InsightFace bot Below you can see we created `useapi` Discord server with private `#api` text channel: ![](../../assets/images/discord_faceswap_server_setup_example.png) InsightFace bot invited to the server and has access to private `#api` text channel ![](../../assets/images/discord_faceswap_channel_setup_example.png) ## Test InsightFace bot Navigate to the created above `#api` text channel and execute few InsightFaceSwap bot command(s) to make sure it works. ## Make a note of your server id and channel id values Your Discord URL looks like `https://discord.com/channels//` In the screenshot above URL is `https://discord.com/channels/1122226477161144546/1122277481822456166` where `1122226477161144546` is your Discord server id and `1122277481822456166` is your private `#api` channel id. Save both server id and channel id values, you will need those numbers for API. ## Obtain Discord token There are many tutorials describing how to obtain Discord tokens. Please refer to the following links bellow for additional guidance: - [How to Find Your Discord Token](https://discordhelp.net/discord-token) - [How To Get Your Discord Token](https://pcstrike.com/how-to-get-discord-token/) - [How to get Discord Token](https://linuxhint.com/get-discord-token/) Keep in mind that anyone with a Discord token can have **full access** to your Discord account so please keep it **safe** and **secure**. To reset your Discord token simply change your Discord password. ## Verify Discord access Once all the above steps are completed you should have the following: - Discord token - Discord server id number - Discord private `#api` channel id number This only verifies that the token, server id and channel id values are correct. To complete setup, you **MUST** proceed to [POST account/`channel`](../api-faceswap-v1/post-faceswap-account-channel) and complete the configuration. ##### Server {: .no_toc }
##### Channel {: .no_toc }
=== URL: https://useapi.net/docs/api-faceswap-v1 === Document URL: https://useapi.net/docs/api-faceswap-v1 --- layout: default title: InsightFaceSwap API v1 nav_order: 9000 has_children: true permalink: /docs/api-faceswap-v1 --- # InsightFaceSwap API v1 February 2024 This is [experimental](../../docs/legal) API for [InsightFaceSwap Discord Bot](https://discord.gg/Ym3X8U59ZN) by [Picsi.Ai](https://www.picsi.ai/). InsightFaceSwap allows users to swap faces from source image(s) onto different target images. It offers free and paid [subscription](https://www.patreon.com/picsi) models. Paid subscribers have access to a wide selection of extra features such as [HiFidelity Mode](https://www.patreon.com/posts/89036144), [ARTIFY](https://www.patreon.com/posts/picsi-ai-v2-0-97389077), oldify/youngify, morphing multiple faces in one image, and [many more](https://discord.com/channels/1095014106576212101/1128550062683865178). [Setup InsightFaceSwap](../../docs/start-here/setup-faceswap) [Postman collection](https://www.postman.com/useapinet/useapi-net/collection) (January 20, 2026) [LLM-friendly API spec](https://useapi.net/assets/aibot/api-faceswap-v1.txt) Feed this to your LLM to build integrations Official documentation links: - [Discord support channel](https://discord.com/channels/1095014106576212101/1128550062683865178) - [Patreon support channel](https://www.patreon.com/picsi/posts) - [YouTube channel](https://www.youtube.com/@PicsiAi) #### Example source code on GitHub * [Face swap and animate images generated by Midjourney using InsightFaceSwap and Pika (using webhook)](https://github.com/useapi/examples/tree/main/imagine-faceswap-animate) February 19, 2024 Developer Community: * Discord Server * Telegram Channel * Reddit Group === URL: https://useapi.net/docs/api-faceswap-v1/del-faceswap-account-channel === Document URL: https://useapi.net/docs/api-faceswap-v1/del-faceswap-account-channel --- layout: default title: DEL faceswap/account/channel parent: InsightFaceSwap API v1 nav_order: 400 --- ## Delete InsightFaceSwap account {: .no_toc } ## Table of contents {: .no_toc .text-delta } 1. TOC {:toc} --- {: .delete } > **https://api.useapi.net/v1/faceswap/account/`channel`** The `channel` value should correspond to an account configured previously via a [POST](post-faceswap-account-channel) request. ##### Request Headers ``` yaml Authorization: Bearer {API token} ``` - `API token` is **required**, see [Setup useapi.net](../start-here/setup-useapi) for details. ##### Responses {% tabs del_account_InsightFaceSwap_response %} {% tab del_account_InsightFaceSwap_response 204 %} 204 No Content {% endtab %} {% tab del_account_InsightFaceSwap_response 401 %} 401 Unauthorized ```json { "error": "Unauthorized", "code": 401 } ``` {% endtab %} {% tab del_account_InsightFaceSwap_response 404 %} 404 Not Found {% endtab %} {% endtabs %} ##### Model ```typescript { // TypeScript, all fields are optional error: string, errorDetails: string, code: number } ``` ##### Examples {% tabs del_account_InsightFaceSwap_example %} {% tab del_account_InsightFaceSwap_example Curl %} ``` bash curl -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer …" \ -X DELETE https://api.useapi.net/v1/faceswap/account/ ``` {% endtab %} {% tab del_account_InsightFaceSwap_example JavaScript %} ``` javascript const channel = "Previously configured channel id"; const apiUrl = `https://api.useapi.net/v1/faceswap/account/${channnel}`; const token = "API token"; const data = { method: 'DELETE', headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' } }; const response = await fetch(apiUrl, data); const result = await response.json(); console.log("response", {response, result}); ``` {% endtab %} {% tab del_account_InsightFaceSwap_example Python %} ``` python import requests channel = "Previously configured channel id" apiUrl = f"https://api.useapi.net/v1/faceswap/account/{channel}" token = "API token" headers = { "Content-Type": "application/json", "Authorization" : f"Bearer {token}" } response = requests.delete(apiUrl, headers=headers) print(response, response.json()) ``` {% endtab %} {% endtabs %} === URL: https://useapi.net/docs/api-faceswap-v1/del-faceswap-delid === Document URL: https://useapi.net/docs/api-faceswap-v1/del-faceswap-delid --- layout: default title: DEL faceswap/delid parent: InsightFaceSwap API v1 nav_order: 1100 --- ## InsightFaceSwap [/delid](https://github.com/deepinsight/insightface/blob/master/web-demos/swapping_discord/README.md#delid-name) command {: .no_toc } ## Table of contents {: .no_toc .text-delta } 1. TOC {:toc} --- Use this endpoint to submit the InsightFaceSwap [/delid](https://github.com/deepinsight/insightface/blob/master/web-demos/swapping_discord/README.md#delid-name) command to your [InsightFaceSwap Discord channel](../start-here/setup-faceswap). The result will be returned in the response body and can also be sent as a callback to an optional [`replyUrl`](#request-body). 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 3 to 10 seconds. If you expect high load and need to make multiple concurrent calls, please consider setting up [multiple InsightFaceSwap accounts](https://useapi.net/docs/api-faceswap-v1/post-faceswap-account-channel). It is **important** not to use the InsightFaceSwap account setup for API access for any purposes other than its intended use, such as executing `/delid` 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. {: .delete } > **https://api.useapi.net/v1/faceswap/delid** ##### Request Headers ``` yaml Authorization: Bearer {API token} Content-Type: multipart/form-data ``` - `API token` is **required**, see [Setup useapi.net](../start-here/setup-useapi) for details. ##### Request Body ```json { "channel": "Discord channel id", "idname": "idname param", } ``` - `channel` is optional when only one [faceswap/account](../api-faceswap-v1/get-faceswap-account) configured. However, if you have multiple accounts configured, this parameter becomes **required**. - `idname` is **required**, please refer to InsightFaceSwap [/delid](https://github.com/deepinsight/insightface/blob/master/web-demos/swapping_discord/README.md#delid-name) for details. - `replyUrl` is optional, if not provided value from [useapi.net account](../account-management/get-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](https://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 {% tabs post_faceswap-delid_response %} {% tab post_faceswap-delid_response 200 %} 200 OK Field `content` contains message generated by InsightFaceSwap. ```json { "jobid": "", "verb": "faceswap-delid", "status": "completed", "idname": "me", "created": "2023-09-09T02:04:49.667Z", "updated": "2023-09-09T02:04:53.490Z", "discord": "", "server": "", "channel": "", "replyUrl": "https://webhook.site/abc", "replyRef": "", "messageId": "", "content": "idname me deleted", "timestamp": "2023-09-09T02:04:51.926000+00:00", "code": 200 } ``` {% endtab %} {% tab post_faceswap-delid_response 400 %} 400 Bad Request ```json { "error": "Required param idname is missing or empty" "Optional param replyRef is too long" "Optional param replyUrl is too long" "Required param channel is missing or empty" "Configuration not found for channel , to create POST v1/faceswap/account/" "code": 400 } ``` {% endtab %} {% tab post_faceswap-delid_response 401 %} 401 Unauthorized ```json { "error": "Unauthorized", "code": 401 } ``` {% endtab %} {% tab post_faceswap-delid_response 402 %} 402 Payment Required ```json { "error": "Account has no subscription or subscription expired", "code": 402 } ``` {% endtab %} {% tab post_faceswap-delid_response 429 %} 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/delid](#insightfaceswap-delid-command) requests. ```json { "error": "Unable to lock Discord after 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. ```json { "error": "Discord /interactions failed with HTTP status 429", "errorDetails": "{\"global\":true,\"message\":\"You are being rate limited.\",\"retry_after\":10}", "code": 429 } ``` {% endtab %} {% endtabs %} ##### Model ```typescript { // TypeScript, all fields are optional jobid: string, verb: 'faceswap-delid', status: 'completed' | 'failed', idname: 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 {% tabs faceswap-delid_example %} {% tab faceswap-delid_example Curl %} ``` bash curl -H "Accept: application/json" \ -H "Authorization: Bearer …" \ -X DELETE https://api.useapi.net/v1/faceswap/delid \ -F "channel=" \ -F "idname=" ``` {% endtab %} {% tab faceswap-delid_example JavaScript %} ``` javascript const main = async () => { const apiUrl = "https://api.useapi.net/v1/faceswap/delid"; const token = "API token"; const channel = "Discord channel"; const idname = "idname"; const data = { method: 'DELETE', headers: { 'Authorization': `Bearer ${token}` } }; const formData = new FormData(); formData.append("channel", channel); formData.append("idname", idname); data.body = formData; const response = await fetch(apiUrl, data); const result = await response.json(); console.log("response", { response, result }); }; main() ``` {% endtab %} {% tab faceswap-delid_example Python %} ``` python import requests api_url = "https://api.useapi.net/v1/faceswap/delid" token = "API token" channel = "Discord channel" idname = "idname" headers = { 'Authorization': f'Bearer {token}' } files = { 'channel': (None, channel), 'idname': (None, idname) } response = requests.delete(api_url, headers=headers, files=files) print(response, response.json()) ``` {% endtab %} {% endtabs %} === URL: https://useapi.net/docs/api-faceswap-v1/get-faceswap-account-channel === Document URL: https://useapi.net/docs/api-faceswap-v1/get-faceswap-account-channel --- layout: default title: GET faceswap/account/channel parent: InsightFaceSwap API v1 nav_order: 200 --- ## Retrieve InsightFaceSwap configuration for `channel` {: .no_toc } ## Table of contents {: .no_toc .text-delta } 1. TOC {:toc} --- {: .get } > **https://api.useapi.net/v1/faceswap/account/`channel`** The `channel` value should correspond to an account configured previously via a [POST](post-faceswap-account-channel) request. ##### Request Headers ``` yaml Authorization: Bearer {API token} Content-Type: application/json ``` - `API token` is **required**, see [Setup useapi.net](../start-here/setup-useapi) for details. ##### Responses {% tabs get_account_InsightFaceSwap_channel_response %} {% tab get_account_InsightFaceSwap_channel_response 200 %} 200 OK ```json { "server": "Discord server id", "channel": "Discord channel id", "discord": "Discord token", "credits": { "timestamp": "2024-02-01T02:05:24.991000+00:00", "total": 50, "used": 18 } } ``` {% endtab %} {% tab get_account_InsightFaceSwap_channel_response 401 %} 401 Unauthorized ```json { "error": "Unauthorized", "code": 401 } ``` {% endtab %} {% tab get_account_InsightFaceSwap_channel_response 404 %} 404 Not Found Configuration not found. To create configuration use [faceswap/account/`channel`](https://useapi.net/docs/api-faceswap-v1/post-faceswap-account-channel). {% endtab %} {% endtabs %} ##### Model ```typescript { // TypeScript, all fields are optional discord: string, server: string, channel: string, credits: { timestamp: string, total: number, used: number } } ``` ##### Examples {% tabs get_account_InsightFaceSwap_channel_example %} {% tab get_account_InsightFaceSwap_channel_example Curl %} ``` bash curl https://api.useapi.net/v1/faceswap/account/ \ -H "Accept: application/json" \ -H "Authorization: Bearer …" ``` {% endtab %} {% tab get_account_InsightFaceSwap_channel_example JavaScript %} ``` javascript const token = "API token"; const channel = "Previously configured channel id"; const apiUrl = `https://api.useapi.net/v1/faceswap/account/${channel}`; const response = await fetch(apiUrl, { headers: { "Authorization": `Bearer ${token}`, }, }); const result = await response.json(); console.log("response", {response, result}); ``` {% endtab %} {% tab get_account_InsightFaceSwap_channel_example Python %} ``` python import requests token = "API token" channel = "Previously configured channel id" apiUrl = f"https://api.useapi.net/v1/faceswap/account/{channel}" headers = { "Content-Type": "application/json", "Authorization" : f"Bearer {token}" } response = requests.get(apiUrl, headers=headers) print(response, response.json()) ``` {% endtab %} {% endtabs %} === URL: https://useapi.net/docs/api-faceswap-v1/get-faceswap-account === Document URL: https://useapi.net/docs/api-faceswap-v1/get-faceswap-account --- layout: default title: GET faceswap/account parent: InsightFaceSwap API v1 nav_order: 100 --- ## Retrieve InsightFaceSwap accounts information {: .no_toc } ## Table of contents {: .no_toc .text-delta } 1. TOC {:toc} --- Before you start using the API, you **must** [configure](../start-here/setup-faceswap) at least one InsightFaceSwap Discord account. You may specify multiple InsightFaceSwap accounts, the API will automatically perform load balancing by randomly selecting an account with available credits before making calls to InsightFaceSwap Discord bot. This endpoint retrieves the complete list of configured accounts for InsightFaceSwap. {: .get } > **https://api.useapi.net/v1/faceswap/account** ##### Request Headers ``` yaml Authorization: Bearer {API token} Content-Type: application/json ``` - `API token` is **required**, see [Setup useapi.net](../start-here/setup-useapi) for details. ##### Responses {% tabs account_InsightFaceSwap_response %} {% tab account_InsightFaceSwap_response 200 %} 200 OK ```json { "Discord channel A": { "server": "Discord server A", "channel": "Discord channel A", "discord": "Discord token A", "credits": { "timestamp": "2024-02-01T02:05:24.991000+00:00", "total": 50, "used": 18 }, }, "Discord channel B": { "server": "Discord server B", "channel": "Discord channel B", "discord": "Discord token B" }, "Discord channel N": { "server": "Discord server N", "channel": "Discord channel N", "discord": "Discord token N", "credits": { "timestamp": "2024-02-01T03:17:48.159000+00:00", "total": 200, "used": 115 } } } ``` {% endtab %} {% tab account_InsightFaceSwap_response 401 %} 401 Unauthorized ```json { "error": "Unauthorized", "code": 401 } ``` {% endtab %} {% tab account_InsightFaceSwap_response 404 %} 404 Not Found Configuration not found. To create configuration use [faceswap/account/`channel`](https://useapi.net/docs/api-faceswap-v1/post-faceswap-account-channel). {% endtab %} {% endtabs %} ##### Model ```typescript { // TypeScript, all fields are optional [channel: string]: { discord: string, server: string, channel: string, credits: { timestamp: string, total: number, used: number } } } ``` ##### Examples {% tabs account_InsightFaceSwap_example %} {% tab account_InsightFaceSwap_example Curl %} ``` bash curl https://api.useapi.net/v1/faceswap/account \ -H "Accept: application/json" \ -H "Authorization: Bearer …" ``` {% endtab %} {% tab account_InsightFaceSwap_example JavaScript %} ``` javascript const token = "API token"; const apiUrl = "https://api.useapi.net/v1/faceswap/account"; const response = await fetch(apiUrl, { headers: { "Authorization": `Bearer ${token}`, }, }); const result = await response.json(); console.log("response", {response, result}); ``` {% endtab %} {% tab account_InsightFaceSwap_example Python %} ``` python import requests token = "API token" apiUrl = "https://api.useapi.net/v1/faceswap/account" headers = { "Content-Type": "application/json", "Authorization" : f"Bearer {token}" } response = requests.get(apiUrl, headers=headers) print(response, response.json()) ``` {% endtab %} {% endtabs %} === URL: https://useapi.net/docs/api-faceswap-v1/get-faceswap-jobid === Document URL: https://useapi.net/docs/api-faceswap-v1/get-faceswap-jobid --- layout: default title: GET faceswap/jobs/?jobid=jobid parent: InsightFaceSwap API v1 nav_order: 1300 --- ## Retrieve InsightFaceSwap job status and results {: .no_toc } ## Table of contents {: .no_toc .text-delta } 1. TOC {:toc} --- Use this endpoint to retrieve status and results of - [faceswap/headshot](../api-faceswap-v1/post-faceswap-headshot) - [faceswap/changebg](../api-faceswap-v1/post-faceswap-changebg) - [faceswap/picsi](../api-faceswap-v1/post-faceswap-picsi) with initial jobs status returned `started` If you specified optional parameter [`replyUrl`](../api-faceswap-v1/post-faceswap-headshot#request-body) you technically do not need to use this endpoint to retrieve results since API will call provided `replyUrl` once job generation completed. **Important** API periodically polls (checks) Discord every 15 to 60 seconds (depending on the load) and updates all currently executed jobs statuses and results. Polling interval is used for safety reasons, aiming to prevent any potential issues with Discord and InsightFaceSwap, such as bans or excessive requests. Jobs lifespan guaranteed to be at least 31 days, after that they will be expired and may be recycled. {: .get } > **https://api.useapi.net/v1/faceswap/jobs/?jobid=`jobid`** ##### Request Headers ``` yaml Authorization: Bearer {API token} ``` - `API token` is **required**, see [Setup useapi.net](../start-here/setup-useapi) for details. ##### Query Parameter `jobid` is **required**, use value returned by - [faceswap/headshot](../api-faceswap-v1/post-faceswap-headshot) - [faceswap/changebg](../api-faceswap-v1/post-faceswap-changebg) - [faceswap/picsi](../api-faceswap-v1/post-faceswap-picsi) with initial jobs status returned `started` ##### Responses {:toc} {% tabs get_faceswap_jobid_response %} {% tab get_faceswap_jobid_response 200 %} 200 OK If field `status` value is *created*, *started* or *progress* wait in a loop for **at least** 10..30 seconds and retry again. When completed retrieve generated images or video from `attachments` array. Field `content` contains message generated by InsightFaceSwap reflecting current generation parameters and progress. Optional array `embeds` contains additional information. ```json { "jobid": "", "verb": "faceswap-headshot", "status": "completed", "created": "2023-09-09T02:04:49.667Z", "updated": "2023-09-09T02:19:20.256Z", "prompt": "me, a mad king with an evil smile, wearing medieval royal blue attire and a crown. --no green --square", "discord": "", "server": "", "channel": "", "messageId": "", "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: