Face Swap API
Integrate AI face swap into your app in minutes. Swap faces in photos, videos, and GIFs with a simple REST API. SDKs for Python, Node.js, Go, and Rust.
Trusted by teams at
Everything You Need to Ship Face Swap
One API for photos, videos, and GIFs. Fully managed infrastructure, multi-language SDKs, and commercial-ready outputs.
Integrate in 3 Steps
From zero to face-swapping in production — no GPU setup; no model deployment; no infrastructure headaches.
Get Your API Key
Make Your First Request
Get Results & Scale
Make your first photo face swap
Start with one photo before processing videos or a batch. The source supplies the face; the target supplies the scene.
from magic_hour import Client
from os import getenv
client = Client(token=getenv("MAGIC_HOUR_API_KEY"))
res = client.v1.face_swap_photo.generate(
assets={
"face_mappings": [
{
"new_face": "/path/to/1234.png",
"original_face": "api-assets/id/0-0.png",
}
],
"face_swap_mode": "all-faces",
"source_file_path": "/path/to/1234.png",
"target_file_path": "/path/to/1234.png",
},
name="Face Swap image",
wait_for_completion=True,
download_outputs=True,
download_directory="."
)
from magic_hour import Client
from os import getenv
client = Client(token=getenv("MAGIC_HOUR_API_KEY"))
res = client.v1.face_swap.generate(
assets={
"face_mappings": [
{
"new_face": "/path/to/1234.png",
"original_face": "api-assets/id/0-0.png",
}
],
"face_swap_mode": "all-faces",
"image_file_path": "image/id/1234.png",
"video_file_path": "/path/to/1234.mp4",
"video_source": "file",
},
end_seconds=15.0,
start_seconds=0.0,
name="Face Swap video",
style={"version": "default"},
wait_for_completion=True,
download_outputs=True,
download_directory="."
)Before you run
- Create an API key and add it to the authorization value shown in your chosen snippet.
- Provide source and target images you control. Use a clear face and get permission from the people shown. For web-hosted inputs, use direct HTTPS file URLs. For private or local files, upload the file first and use its returned
file_path. - Choose Python, Node.js, or HTTP above, then review the example before running it. The Face Swap example demonstrates both the photo and video endpoints, so a full fresh run submits two billable jobs.
Choose the endpoint that matches your target media. For a single image, use the photo face-swap workflow. For a video clip, follow the video face-swap API guide. Test with your own source face and target media before scaling your integration.
Expected result and async processing
The POST returns a project id and credits_charged, not the finished media. Save the project ID and poll it with backoff until the status is complete, error or canceled. For completed jobs, read the final credit charge, download URL and expiration time. Handle errors and cancellations without continuing to poll. Download your output before the URL expires; if it expires, retrieve the project again for a fresh URL.
Stopping a poll does not cancel the job or prove failure. Reuse the saved project ID to resume polling without creating another job. If the create request times out before returning an ID, do not submit it again. Email support@magichour.ai with the endpoint, request name and UTC timestamp so the request can be traced first. For production, use webhooks, verify signatures and handle repeated deliveries. Poll for cancellation because canceled jobs do not emit a cancellation webhook. See measured processing times; queue load, input and settings affect latency.
Pricing and usage estimates
Photo and video face swap have different credit costs. This example includes one request for each endpoint. Read each completed project for its exact charge; the calculator below estimates supported monthly video workloads. These are usage-based billing examples, not subscription prices or a promise of free generation. Usage-based billing requires setup assistance. Subscription and credit-pack economics differ. Video create charges are estimates; read the completed project for the final charge.
Troubleshooting
- 401: verify the API key and Bearer header. Keep keys in server environment variables.
- Invalid input: use direct file URLs or uploaded paths, check the response message and compare the payload with the endpoint schema. Photo requests use source_file_path and target_file_path; they do not use face_file_path.
- Insufficient balance or plan access: inspect the error code and account balance and tier. A free key does not unlock every model.
- 429 or transient polling failure: reduce concurrency, back off and resume the existing project ID. Do not blindly retry a create request.
- Unexpected output: use a front-facing source face with fewer obstructions. Use face detection and individual mappings when each target face needs a different identity.
Continue with the bulk Face Swap guide when you are ready to turn this first request into a repeatable workflow.
Get an API key and run your first request →Estimate Your API Costs
- 12,000credits / month
- 25,000credits / month
- 13,000credits / month