Head Swap – Generate

namifusion/head-swap/generate

Replace selected heads in the video with your reference images using Wan2.2-Animate. Keeps the original audio track.

Examples

Head Swap – Generate Examples 1

Parameters

NameTypeDefaultConstraintsDescription
track_manifest_url *Track manifest URLtext——track_manifest_url returned by the analyze model
mappings *Head mappingsarray<object>——Array of {obj_id, img_urls}. obj_id comes from analyze output; 1-3 reference image URLs per head.
↳obj_id *Head obj_idnumber——Object identifier returned by the corresponding analyze request.
↳img_urls *Reference imagesimage_upload—1–3 itemsReference image URLs associated with this detected object.
resolutionResolutionselect720p480p | 720pSelects the output resolution or provider generation mode. Higher settings may take longer to process.
seedSeednumber——Optional random seed for reproducible results; leave empty to use a random seed.

Output fields

FieldTypeDescription
videosarrayResult video URL(s), original audio track preserved

API

Call this model through one unified REST API. Get a key on the API Keys page.

cURL
# 1) Submit — returns { "task_uuid": "..." }
curl -X POST "https://www.namifusion.com/api/v1/marketplace/run/namifusion/head-swap/generate" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "input": {
    "track_manifest_url": "ANALYZE_OUTPUT.track_manifest_url",
    "mappings": [
      {
        "obj_id": 0,
        "img_urls": [
          "https://assets-public.namifusion.com/marketplace/images/2026-06-12/638e1ee18ac7.jpeg"
        ]
      }
    ],
    "resolution": "720p"
  }
}'

# 2) Poll until status is "completed", then read the output URLs
curl "https://www.namifusion.com/api/v1/marketplace/run/tasks/TASK_UUID" \
  -H "Authorization: Bearer YOUR_API_KEY"
Python
import time, requests

API_KEY = "YOUR_API_KEY"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}

# 1) Submit
resp = requests.post(
    "https://www.namifusion.com/api/v1/marketplace/run/namifusion/head-swap/generate",
    headers=HEADERS,
    json={
        "input": {
            "track_manifest_url": "ANALYZE_OUTPUT.track_manifest_url",
            "mappings": [
                {
                    "obj_id": 0,
                    "img_urls": [
                        "https://assets-public.namifusion.com/marketplace/images/2026-06-12/638e1ee18ac7.jpeg"
                    ]
                }
            ],
            "resolution": "720p"
        }
    },
)
resp.raise_for_status()  # 401/402/429/5xx stop here instead of polling a bad task
task = resp.json()

# 2) Poll until a terminal state (completed / failed / cancelled).
#    This model is allowed up to 7200s server-side.
deadline = time.time() + 7260
while task.get("status") not in ("completed", "failed", "cancelled"):
    if time.time() > deadline:
        raise TimeoutError(f"still {task.get('status')} — keep the task_uuid and poll later")
    time.sleep(3)
    poll = requests.get(f"https://www.namifusion.com/api/v1/marketplace/run/tasks/{task['task_uuid']}", headers=HEADERS)
    poll.raise_for_status()
    task = poll.json()

print(task["status"], task.get("output"))
JavaScript
const API_KEY = "YOUR_API_KEY";
const HEADERS = { Authorization: `Bearer ${API_KEY}` };

// 1) Submit
const resp = await fetch("https://www.namifusion.com/api/v1/marketplace/run/namifusion/head-swap/generate", {
  method: "POST",
  headers: { ...HEADERS, "Content-Type": "application/json" },
  body: JSON.stringify({
    "input": {
      "track_manifest_url": "ANALYZE_OUTPUT.track_manifest_url",
      "mappings": [
        {
          "obj_id": 0,
          "img_urls": [
            "https://assets-public.namifusion.com/marketplace/images/2026-06-12/638e1ee18ac7.jpeg"
          ]
        }
      ],
      "resolution": "720p"
    }
  }),
});
if (!resp.ok) throw new Error(`submit failed: ${resp.status} ${await resp.text()}`);
let task = await resp.json();

// 2) Poll until a terminal state (completed / failed / cancelled).
//    This model is allowed up to 7200s server-side.
const deadline = Date.now() + 7260 * 1000;
while (!["completed", "failed", "cancelled"].includes(task.status)) {
  if (Date.now() > deadline) throw new Error(`still ${task.status} — keep the task_uuid and poll later`);
  await new Promise((r) => setTimeout(r, 3000));
  const poll = await fetch(`https://www.namifusion.com/api/v1/marketplace/run/tasks/${task.task_uuid}`, { headers: HEADERS });
  if (!poll.ok) throw new Error(`poll failed: ${poll.status}`);
  task = await poll.json();
}

console.log(task.status, task.output);

Documentation

Head Swap - Generate

Replace selected heads in an analyzed video with reference images while preserving the original audio.

Head Swap Generate is the second stage of the Head Swap workflow. Each item in mappings associates an Analyze obj_id with one to three reference image URLs, making the replacement target explicit. The video_url and track_manifest_url must come from the same Analyze task, and the generation resolution must match the analysis resolution.

Key Features

  • Explicit per-head selection: Uses the obj_id from Analyze to avoid replacing the wrong target.
  • Multiple-target mappings: Assign separate reference images to several heads in one video.
  • Multiple reference images: Supply one to three images per target to cover appearance and viewing-angle details.
  • Original audio preservation: Keeps the input video's audio track in the completed output.
  • 480p and 720p output: Select the quality tier that matches the intended result and existing pricing band.

Technical Specifications

ItemDetails
WorkflowHead Swap step 2
Required inputsvideo_url, track_manifest_url, mappings
mappings formatArray of {obj_id, img_urls} objects
Reference images1-3 URLs per target
Resolution480p, 720p (default)
Maximum video length30 seconds
Optional inputseed
OutputVideo URL with the original audio preserved

Basic Workflow

  1. Process the input video with Head Swap Analyze.
  2. Select the target obj_id values from the previews in objects.
  3. Pair each ID with its head reference image URLs in mappings.
  4. Submit the same video and returned Analyze manifest, then poll until generation completes.

Pricing

The existing Marketplace rates are 40 credits per 5-second unit at 480p and 75 credits per 5-second unit at 720p. Videos are limited to 30 seconds. This documentation update does not change pricing.

Best Practices

Use sharp references that show the full head, ideally with camera angles and lighting close to the target video. When supplying multiple images, keep the person's appearance consistent across them. The video, manifest, and obj_id values must come from the same Analyze result; never mix values from separate tasks.