POST
/v1/image-swap
Swap faces in static images using AI-powered face detection and alignment. Supports up to 4K resolution output with professional-grade quality.
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
source_image | string | Yes | Base64-encoded image or URL of the face to use |
target_image | string | Yes | Base64-encoded image or URL where face will be placed |
output_format | string | No | Output format: "png", "jpg", "webp" (default: "png") |
quality | string | No | "standard", "high", "4k" (default: "high") |
face_index | integer | No | Which face to swap if multiple faces detected (0-indexed) |
Code Examples
PyPython
import deepswapai
client = deepswapai.Client(api_key="YOUR_API_KEY")
# Using file paths
result = client.image_swap(
source_image="path/to/source.jpg",
target_image="path/to/target.jpg",
quality="4k"
)
print(f"Output URL: {result.output_url}")
print(f"Processing time: {result.processing_time}ms")
# Download result
result.download("output.png")JSJavaScript
import DeepSwapAI from '@deepswapai/sdk';
const client = new DeepSwapAI({ apiKey: 'YOUR_API_KEY' });
const result = await client.imageSwap({
sourceImage: 'https://example.com/source.jpg',
targetImage: 'https://example.com/target.jpg',
quality: '4k'
});
console.log('Output URL:', result.outputUrl);$cURL
curl -X POST https://api.deepswapai.com/v1/image-swap \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"source_image": "https://example.com/source.jpg",
"target_image": "https://example.com/target.jpg",
"quality": "4k",
"output_format": "png"
}'Response
{
"success": true,
"job_id": "job_abc123xyz",
"output_url": "https://cdn.deepswapai.com/results/abc123.png",
"output_format": "png",
"resolution": "3840x2160",
"processing_time": 2340,
"faces_detected": 1,
"credits_used": 1
}| Field | Type | Description |
|---|---|---|
output_url | string | URL to download the processed image (valid for 24 hours) |
processing_time | integer | Processing time in milliseconds |
faces_detected | integer | Number of faces detected in target image |
Error Handling
Common Errors
NO_FACE_DETECTED- No face found in source or target imageIMAGE_TOO_LARGE- Image exceeds maximum size (50MB)INVALID_FORMAT- Unsupported image format