Faceswap V3

Face Swap V3 is a cutting-edge tool that empowers you to seamlessly swap faces in images. With customizable features and advanced technology, you can achieve professional-quality results.

~4.01s
~$0.005
 1import requests
 2import json
 3
 4url = "https://api.segmind.com/v1/faceswap-v3"
 5headers = {
 6    "x-api-key": "YOUR_API_KEY",
 7    "Content-Type": "application/json"
 8}
 9
10data = {
11    "source_img": "https://segmind-sd-models.s3.amazonaws.com/display_images/faceswapv2_target.jpg",
12    "target_img": "https://segmind-sd-models.s3.us-east-1.amazonaws.com/elon.jpg",
13    "input_faces_index": "0",
14    "source_faces_index": "0",
15    "face_restore": "codeformer-v0.1.0.pth",
16    "interpolation": "Bilinear",
17    "detection_face_order": "large-small",
18    "facedetection": "retinaface_resnet50",
19    "detect_gender_input": "no",
20    "detect_gender_source": "no",
21    "face_restore_weight": 0.75,
22    "image_format": "jpeg",
23    "image_quality": 95,
24    "base64": false
25}
26
27response = requests.post(url, headers=headers, json=data)
28
29if response.status_code == 200:
30    result = response.json()
31    print(json.dumps(result, indent=2))
32else:
33    print(f"Error: {response.status_code}")
34    print(response.text)

API Endpoint

POSThttps://api.segmind.com/v1/faceswap-v3

Parameters

source_imgrequired
string (uri)

Your face goes here. A closeup shot would be ideal.(image url)

target_imgrequired
string (uri)

The face you want to swap with (image url).

base64optional
boolean

Base64 encoding of the output image.

Default: false
detect_gender_inputoptional
string

Detect the gender of the target face

Default: "no"
Allowed values :
"no""female""male"
detect_gender_sourceoptional
string

Detect the gender of the input face

Default: "no"
Allowed values :
"no""female""male"
detection_face_orderoptional
string

The order in which faces are detected.

Default: "large-small"
Allowed values :
"large-small""small-large""top-bottom""bottom-top""left-right""right-left"
face_restoreoptional
string

which face restore model to use

Default: "codeformer-v0.1.0.pth"
Allowed values :
"codeformer-v0.1.0.pth""GFPGANv1.4.pth""GFPGANv1.3.pth"
face_restore_weightoptional
number

Face Restore Weight

Default: 0.75Range: 0 - 1
facedetectionoptional
string

The model used to detect the face

Default: "retinaface_resnet50"
Allowed values :
"retinaface_resnet50""retinaface_mobile0.25""YOLOv5l""YOLOv5n"
image_formatoptional
string

Output image format

Default: "jpeg"
Allowed values :
"jpeg""png""webp"
image_qualityoptional
integer

Image quality setting for output

Default: 95Range: 10 - 100
input_faces_indexoptional
string

Index of the input faces: By default the model detects faces in images from 'large' to 'small'.Index of the first detected face is 0. Multiple faces can be selected using a comma (,)

Default: "0"
interpolationoptional
string

Face restore interpolation method

Default: "Bilinear"
Allowed values :
"Nearest""Bilinear""Bicubic""Lanczos"
source_faces_indexoptional
string

Index of the source faces: By default the model detects faces in images from 'large' to 'small'.Index of the first detected face is 0. Multiple faces can be selected using a comma (,)

Default: "0"

Response Type

Returns: Image

Common Error Codes

The API returns standard HTTP status codes. Detailed error messages are provided in the response body.

400

Bad Request

Invalid parameters or request format

401

Unauthorized

Missing or invalid API key

403

Forbidden

Insufficient permissions

404

Not Found

Model or endpoint not found

406

Insufficient Credits

Not enough credits to process request

429

Rate Limited

Too many requests

500

Server Error

Internal server error

502

Bad Gateway

Service temporarily unavailable

504

Timeout

Request timed out