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 video face swap
Personalize a short template video with a portrait. This example replaces every detected face with the same identity. Review one finished clip before processing a batch.
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_swap_mode": "all-faces",
"image_file_path": "/path/to/1234.png",
"video_file_path": "/path/to/1234.mp4",
"video_source": "file",
},
end_seconds=5.0,
start_seconds=0.0,
name="My 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.
- Replace the sample paths with your uploaded portrait and video file_path values. Use a clear face and media you have permission to process. Keep the selected segment within the source video's duration. 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. This example submits one video face-swap job and uses credits.
For a still image, use the Photo Face Swap guide. Photo and video requests use different input fields and pricing.
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
Video Face Swap charges depend on the clip length and rendered frame rate. Read the completed video project for its exact charge. The calculator below estimates monthly video workloads. Credit packs share your API balance but do not raise subscription-tier resolution limits. 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. Video requests use image_file_path, video_file_path and video_source, plus start_seconds and end_seconds for the selected clip.
- 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 Video 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
- 15,000credits / month
- 3,000credits / month