AI-powered video face swap for videos up to 10 minutes long.
Configure model parameters
Results from model execution
No output yet
Configure inputs and click generate
1import json2import time34import requests56api_key = "YOUR_API_KEY"7start_url = "https://api.magica.com/api/v1/nodes/video_faceswap/run"8runs_url = "https://api.magica.com/api/v1/nodes/runs/"9headers = {"Authorization": f"Bearer {api_key}"}10MAX_TRANSIENT_RETRIES = 5111213def request_failed(response):14 try:15 body = response.json()16 except ValueError:17 body = None18 detail = body if isinstance(body, dict) else {}19 message = detail.get("message") or detail.get("error") or response.reason20 return RuntimeError(f"Request failed ({response.status_code}): {message}")212223# Start model execution (not retried: a retry could start a second run)24data = {25 "nodeType": "video_faceswap",26 "input": {27 "source_image_url": "https://example.com/image.png",28 "video_url": "https://example.com/video.mp4",29 "target_gender": "all",30 "target_index": 031 }32}3334response = requests.post(start_url, json=data, headers=headers)35if not response.ok:36 raise request_failed(response)37run_id = response.json()["runId"]38print(f"Started run: {run_id}")3940# Poll until the run reaches a terminal status41retries = 042while True:43 poll = requests.get(runs_url + run_id, headers=headers)44 if not poll.ok:45 transient = poll.status_code == 429 or poll.status_code >= 50046 if not transient or retries >= MAX_TRANSIENT_RETRIES:47 raise request_failed(poll)48 retries += 149 time.sleep(2 ** retries)50 continue51 retries = 052 run = poll.json()53 status = run.get("status")5455 if status == "COMPLETED":56 print(json.dumps(run["output"], indent=2))57 break58 elif status == "FAILED":59 raise RuntimeError(f"Run failed: {run.get('error') or 'Unknown error'}")60 elif status == "CANCELED":61 raise RuntimeError("Canceled: the run stopped before it completed")62 elif status not in ("QUEUED", "RUNNING"):63 raise RuntimeError(f"Unexpected run status: {status}")6465 time.sleep(5)
https://api.magica.com/api/v1/nodes/video_faceswap/runsource_image_urlstringrequirednullvideo_urlstringrequirednulltarget_genderstringoptional"all"target_indexnumberoptionalChoose which face to replace: 0 selects the largest face, 1 the next largest. Each run replaces one selected face.
0Min: 0Max: 10The start endpoint returns a runId. Poll GET /v1/nodes/runs/{runId} to check status and get output. When you include a webhook, the response also returns its webhook.signingSecret for Svix signature verification; store it securely and do not send it back as a custom header.
{
"runId": "run_abc123...",
"webhook": {
"signingSecret": "whsec_..."
}
}https://api.magica.com/api/v1/nodes/runs/{runId}Poll every 5 seconds until status is terminal:
{
"id": "run_abc123...",
"nodeType": "video_faceswap",
"status": "COMPLETED",
"output": {
"result": [
"https://..."
],
"creditUsed": 40000
},
"error": null,
"creditUsed": 40000,
"createdAt": "2025-01-01T00:00:00.000Z"
}Add a webhook object to your request body to receive live status updates instead of polling.
{
"webhook": {
"url": "https://your-server.com/webhook",
"events": [
"run.started",
"run.completed",
"run.failed"
],
"metadata": {
"myCustomField": "value"
},
"headers": {
"X-Custom-Header": "value"
}
}
}urlstringrequiredThe URL to receive webhook POST requests.
eventsstring[]optionalFilter which events to receive. Defaults to all events.
metadataobjectoptionalCustom metadata included in every webhook payload.
headersobjectoptionalCustom headers sent with each webhook request.
These headers are separate from Svix's signed svix-* headers.
Webhook Payload Example
{
"type": "run.completed",
"runId": "run_abc123...",
"data": {
"status": "COMPLETED",
"nodeType": "video_faceswap",
"output": {
"result": [
"https://..."
],
"creditUsed": 40000
},
"creditUsed": 40000,
"finishedAt": "2025-01-01T00:00:05.000Z"
}
}