Character swap
Pricing: Character swap
Replace one to three people in a video with the characters in reference pictures. The source performance (pose, gaze, expression, movement), the scene and the source audio are kept; the chosen people change. One picture per person swapped in. One mp4 comes back.
There are three jobs. Leave mode out and the renderer picks the right whole-frame job for your request:
bfs(the default with one picture): the whole frame is redrawn in one pass with a swap model trained for exactly this, from a shot-by-shot description of the clip. It follows the source most closely and renders up to 704p at the base price. One job covers at most 16 s of clip.regen(the default with two or three pictures): the same whole-frame approach on the general swap model, one pass for every picture, up to 20 s.masked: each person is found and tracked (SAM), and only a band around their silhouette is redrawn; every other pixel is the source. It takes your own Englishprompts, the mask levers and a mask preview. Use it when a whole-frame result changes the scene too much.
The whole-frame jobs redraw the scene too, close to the source but not pixel for pixel, so anything that must not change (another person, an object, subtitles) belongs in the description. Send your own description, or leave it out and say who to replace in plain words (prompt, for example "the woman on the right"): a vision model then watches the clip and writes the description while the job waits in the queue. If it cannot, the job runs as masked with the defaults instead of failing.
Known whole-frame defects: a short shot of someone else can take the next shot's framing, an object named in the description can appear before the source shows it, and burned-in text or subtitles are redrawn unless keep names them (or paste_back covers them). A precise description fixes most of them.
POST https://api.happypony.io/api/v1/jobs/character-swap
GET https://api.happypony.io/api/v1/jobs/:requestId/status
GET https://api.happypony.io/api/v1/jobs/:requestId
PUT https://api.happypony.io/api/v1/jobs/:requestId/cancel
1) Create a request
POST https://api.happypony.io/api/v1/jobs/character-swap with Content-Type: application/json. The clip and the pictures are fetched and stored when the request is created, so a URL that cannot be fetched is a 400 invalid_media and nothing is charged. A local file can be uploaded first.
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
video_url |
string | yes | http(s) URL of the source clip (mp4, mov, webm or mkv, up to 200 MB). | |
pictures |
string[] | yes | 1 to 3 http(s) URLs of pictures (jpg, png or webp), one per person swapped in. picture_url (one URL string) is accepted instead for a single person. A clear, front-facing full or half-body shot works best. |
|
mode |
string | no | chosen by the renderer | Leave it out unless you need one job by name. bfs: the whole frame, one picture only (two or more is a 400). regen (alias nomask): the whole frame on the general swap model, one pass for every picture; naming it switches bfs off. masked (alias sequential): one masked pass per person. Left out, a request with mask, dry_run: true or one prompt per picture is masked; anything else is bfs with one picture and regen with several. |
description |
object | no | written by a vision model from the clip and prompt |
bfs and regen: the clip in English, shot by shot. See The description. With it, prompts, window_prompts, mask, dry_run and mode masked are a 400. |
prompt |
string | no | the most prominent person per picture | Who to swap and whether the outfit stays, in plain words: "the person on the right", "the woman in the red dress gets Picture 1, the man gets Picture 2". A hint for the vision model that writes the description (or, on masked, picks the targets); never sent to the renderer. Up to 2000 characters. |
keep_outfit |
boolean | no | false |
A hint for the vision model that writes the description: true keeps the clothes of the clip, only face, hair and identity come from the pictures. With your own description, set characters[].keep_outfit instead. |
duration_seconds |
integer | no | 10 |
1 to 20. Only the first duration_seconds of the clip are processed; a shorter clip renders its whole length. A bfs job renders at most 16 s: a longer request is cut to 16 s, and that is what is billed. At resolution 768 the limit is 15. |
start_seconds |
number | no | 0 |
0 to 3600. Where in the clip the processed span starts; duration_seconds counts from there, so the 20 s cap is 20 s of rendered clip wherever it starts. A start past the end of the clip fails the job. The clip's audio is cut the same way. Times in description, mask, paste_back and window_prompts are relative to the start of the processed span, not of the source. |
seed |
integer | no | random | The same inputs and seed give the same result. |
swap_strength |
number | no | 1.0 on bfs and regen, 1.6 on masked |
0 (the swap LoRA off: the plain model swaps from the words alone) or 0.5 to 2.0. How strongly the new look overrides the source person. Leave it out on bfs. |
window |
integer | no | 226 on regen, 124 on masked |
Frames per render window: 226 (about 9.4 s) or 124 (about 5.2 s). 768 renders 124 only; 226 with it is a 400. A bfs job is always one window: leave it out. |
reference_background |
string | no | grey on bfs and regen, keep on masked |
grey: each person is cut out of their picture onto grey first, so the picture's own scene, caption or watermark cannot reach the video. keep: the pictures as they are. |
targets |
array | no | chosen by the vision model | Always an array (a bare string is a 400), one per picture, in order: "leftmost", "rightmost", "largest" (one picture only) or an integer position (0 = leftmost, -1 = rightmost). On masked it skips the vision model's choice of who to replace; on regen it is a hint for the description. |
prompts |
string[] | no | written from the vision model's plan | masked: your own English worker prompts, skipping the plan: one per picture (or one for all). Refer to the pictures as <Picture 1> … and to the clip as <Video 1>. |
sam_text |
string | no | person |
masked: what region of each target is replaced, in a few English words: person (the whole person, the default), head (only the head, when the new character keeps the source outfit and build). Up to 200 characters. |
resolution |
string | no | follows the clip on bfs, else 480 |
480, 600, 704 or 768: the size of the render (a pixel budget; the clip keeps its aspect ratio). Left out, a bfs job follows the source up to 704 (a 720p or 1080p clip renders at 704, a 540p clip at 480); regen and masked render at 480. Higher sizes are sharper and slower; 600 and 704 help small faces and reflections. 768 takes about three times the render time, at most 15 s (duration_seconds ≤ 15). |
targets: "all" |
masked, one picture only: swap every instance the mask finds (a person and their reflection in a mirror), not one person. |
|||
mask |
object | no | masked only. Tunes the swap mask: see Mask levers. |
|
window_prompts |
object | no | {"<window>": "prompt"}: a prompt for one render window (0-based, window frames each), for a change of action or expression mid-clip. Windows not listed use the main prompt. One-pass jobs without a description only: one picture on masked, or regen with prompts. Values up to 4000 characters. |
|
lipsync |
string | no | auto |
auto (pin the mouth to the source audio when the clip has some), on or off. |
paste_back |
object[] | no | Up to 8 { "rect": [x, y, w, h], "frames"?: [start_s, end_s] }, rect in 0–1 fractions of the frame: source pixels copied back over the render inside each rectangle, for subtitles, logos or text inside the mask band. |
|
dry_run |
boolean | no | false |
masked only. true: no render, only the mask preview and per-frame stats, in seconds. |
| People | 5 s | 10 s | 15 s | 20 s |
|---|---|---|---|---|
| 1 | 1 | 2 | 3 | 4 |
| 2 | 2 | 4 | 6 | 8 |
| 3 | 3 | 6 | 9 | 12 |
The pictures and the clip go through the content check, so a request can answer 422 content_rejected (Errors). Adult clips render with the same recipe and every lever, on an adult-capable model swapped in for the default one.
The description (description)
What the whole-frame renderer is told about the clip. It never sees the clip the way a viewer does: it writes its prompt from this, so a shot left out or a person not mentioned comes out wrong. Every string is English, at most 500 characters. Describe only what the clip shows: no dialogue, story, praise words or instructions to the model. Unknown keys are a 400.
| Key | Type | Description |
|---|---|---|
scene |
string | One sentence: the place, the light and the camera; the style when it is not live action. Best under 25 words. |
characters |
object[] | Exactly one per picture, in the order of pictures. |
characters[].look |
string | What the character in that picture looks like, as a list of attributes: gender, age, build, skin, eyes, hair, facial hair, accessories, clothes (leave the clothes out with keep_outfit). Best under 45 words. |
characters[].replaces |
string | A complete noun phrase that starts with "the" and names the person replaced in the clip by hair and clothes, with LEFT, RIGHT or MIDDLE when other people stay in the frame. Best under 20 words. |
characters[].changes |
string, optional | One or two sentences on what must visibly differ from the replaced person: a hat that goes, hair that now shows, the new clothes that stay on through the action. Best under 35 words. |
characters[].keep_outfit |
boolean, optional | true: the output keeps the clothes of the clip; only face, hair and identity come from the picture. |
shots |
object[], 1–24 | Every shot of the rendered clip in order, without gaps: the first starts at 0, the last ends at the rendered length, a new one at each hard cut. Each start is at least the previous end (0.05 s slack) and 0 ≤ start < end. |
shots[].start, shots[].end |
number | Seconds from the start of the processed span. |
shots[].present |
boolean, optional | false when no replaced person is visible in the shot (a back, hands or legs count as visible). Default true. List these shots too: one left out takes the next shot's framing and people. At least one shot is true. |
shots[].action |
string | The framing first, then where the replaced person is, how they move and what happens to them, never their own hair or clothes. "He" / "She" is the replaced person, anyone else by their look. A present: false shot says who is there and ends with "She is not in this shot." (or "He"). Name an object only in the shots where it is visible. Best under 55 words for a one-shot clip, 30 per shot otherwise. |
keep |
string[], up to 12, optional | One to four short phrases for what must survive: every other person with their position, an object that is handed over, burned-in text or subtitles. No scenery. |
The whole description becomes one prompt of at most 6000 characters; a description that would make a longer one is a 400. Example, one picture over 5.2 s:
{
"video_url": "https://assets.example.com/meadow.mp4",
"pictures": ["https://assets.example.com/new-look.png"],
"duration_seconds": 6,
"description": {
"scene": "Golden-hour meadow of dry grass with autumn trees behind, soft backlight, handheld camera that follows the two men in a medium shot throughout.",
"characters": [
{
"look": "Male, mid twenties, slim build, light-brown skin, dark-brown eyes, black voluminous curly hair of medium length, clean-shaved, thin round gold-rimmed glasses, light-blue denim trucker jacket, white t-shirt, khaki chino trousers, tan suede boots",
"replaces": "the man on the RIGHT, wearing a dark-grey cowboy hat and a tan-brown fringed suede shirt",
"changes": "He wears no cowboy hat: his black curls and round gold glasses are visible, and the light-blue denim jacket, white t-shirt and khaki trousers stay on him through the lunge, the lift and the final embrace."
}
],
"shots": [
{ "start": 0, "end": 5.2, "present": true, "action": "Medium two-shot, the two men stand side by side with arms around each other, laughing. He lunges at the other man and is lifted off the ground in a spinning bear hug, then set down, both laughing, still embracing." }
],
"keep": ["the man on the LEFT in the black cowboy hat, cream fringed shirt, blue jeans and brown belt"]
}
}
A description written in Simplified Chinese for the earlier contract is still accepted.
Mask levers (mask)
masked only. The mask is what the swap may repaint: each target person as found by SAM, grown by a band. A wrong mask is the usual cause of a bad swap (the wrong person, a flickering edge, a cup or a microphone swapped too), so check a mask preview before a long or tricky render. The levers apply in this order: largest, expand, temporal, frames, subtract, boxes.
| Key | Type | Default | Description |
|---|---|---|---|
expand |
integer 0–96 | 64 |
Band (px) the mask is grown by. 32 suits close-ups and medium shots; wider covers loose hair and clothes but repaints more of the background. |
temporal |
integer 0–8 | 0 |
Joins each frame's mask with its ±N neighbours (fills flicker and dropped frames). |
largest |
boolean | false |
Keep only the largest blob per frame (drops stray detections). |
cuts |
boolean | false |
For a clip with several shots: the tracker starts again at every hard cut, so a shot without the person is left alone. Pair it with a sam_text that names the person ("woman"). |
shots |
up to 32 { "time": s, "targets": [...] } |
Who is replaced in each shot (implies cuts): time is a second inside the shot, targets one per picture as in targets, or "none" to leave the shot alone for that picture. Shots not listed use targets. |
|
detect_time |
number (s) | 0 |
The frame where the target is detected; pick one where the person is clearly visible. Inside the processed clip and inside frames when both are set. |
frames |
[start_s, end_s] |
whole clip | Mask (and so swap) only inside this time range. |
subtract |
up to 4 { "text": string ≤ 200, "expand"?: 0–64 (default 18) } |
Occluders cut out of the mask, named in English ("the coffee cup", "microphone"). |
|
boxes |
up to 8 { "rect": [x, y, w, h], "set": 0 or 1, "frames"?: [start_s, end_s] } |
Rectangles (0–1 fractions of the frame) forced into (set: 1) or out of (set: 0) the mask, optionally only for a time range. |
Numbers must be numbers and flags booleans (no numeric strings); an unknown key, a value out of range or a time range that starts past the processed clip (duration_seconds, or 20 s, 15 s at 768) is a 400 before anything is charged, as are mask or dry_run on bfs or regen and window_prompts with two or more pictures on masked.
Request body:
{
"video_url": "https://assets.example.com/duo.mp4",
"pictures": ["https://assets.example.com/new-woman.png", "https://assets.example.com/new-man.png"],
"prompt": "the woman becomes Picture 1, the man becomes Picture 2",
"duration_seconds": 10
}
curl -X POST https://api.happypony.io/api/v1/jobs/character-swap \
-H "Authorization: Bearer $HP_KEY" -H "Content-Type: application/json" \
-d '{"video_url": "https://assets.example.com/solo.mp4", "picture_url": "https://assets.example.com/new-look.png", "duration_seconds": 5}'
Response 202 (fields: Create response):
{
"request_id": "48520",
"type": "character-swap",
"status": "IN_QUEUE",
"credits": 4,
"status_url": "https://api.happypony.io/api/v1/jobs/48520/status",
"response_url": "https://api.happypony.io/api/v1/jobs/48520",
"cancel_url": "https://api.happypony.io/api/v1/jobs/48520/cancel"
}
2) Poll for status
Poll the status_url until status is COMPLETED, FAILED or CANCELLED (fields: Status response). Once it leaves the queue, one person over 5 s takes about a minute and a half at 480p and longer at higher sizes (a 15 s clip at 704p takes several minutes); on regen one pass covers every picture, so two people take about as long as one; on masked two people over 10 s take about six minutes. Without your own description, writing one adds a little before the render starts. A queued job can be cancelled with PUT on the cancel_url (Cancel a request).
curl https://api.happypony.io/api/v1/jobs/48520/status -H "Authorization: Bearer $HP_KEY"
{
"request_id": "48520",
"type": "character-swap",
"status": "IN_PROGRESS",
"created_at": "2026-11-04T10:00:00.000Z",
"completed_at": null,
"credits": 4,
"status_url": "…", "response_url": "…", "cancel_url": "…"
}
3) Fetch the result
When status is COMPLETED, fetch the response_url (common fields: Result response). The video is under videos, not images:
curl https://api.happypony.io/api/v1/jobs/48520 -H "Authorization: Bearer $HP_KEY"
{
"request_id": "48520",
"type": "character-swap",
"status": "COMPLETED",
"created_at": "2026-11-04T10:00:00.000Z",
"completed_at": "2026-11-04T10:06:10.000Z",
"credits": 4,
"videos": [{ "url": "https://…signed…", "format": "mp4" }],
"expires_in": 259200,
"parameters": { "prompt": "the woman becomes Picture 1, the man becomes Picture 2",
"pictures": 2, "duration_seconds": 10, "mode": null, "seed": null, "swap_strength": null },
"status_url": "…", "response_url": "…", "cancel_url": "…"
}
| Field | Type | Description |
|---|---|---|
videos |
object[] | One mp4 with the source audio; empty until COMPLETED, and always empty for a dry_run. |
files |
object[] | When the renderer sends them: every output as { name, url, content_type, format }. Beside the mp4 that is compare.png (source and result frames side by side), so you can check a render without watching it, and on masked mask_preview.png (the mask drawn over source frames). Absent when there are none. |
parameters |
object | prompt, pictures (how many), duration_seconds, mode, seed and swap_strength (null where the default was used), and any of resolution, targets, description, keep_outfit, mask, window_prompts, window, reference_background, lipsync, paste_back and dry_run that were sent. A description the vision model wrote is not echoed. |
Mask preview (dry run)
A dry_run: true job renders nothing. It finds the mask on every frame and returns a picture of it and its statistics, in seconds:
{
"request_id": "48533",
"type": "character-swap",
"status": "COMPLETED",
"credits": 1,
"dry_run": true,
"videos": [],
"mask_preview": { "url": "https://…signed…", "content_type": "image/png" },
"mask_stats": { "url": "https://…signed…", "content_type": "application/json",
"data": { "fps": 24, "passes": [{ "pass": 0, "render_would_fail": false, "mask": { "coverage_min": 0.08, "coverage_mean": 0.11, "coverage_max": 0.14 } }] } },
"files": [{ "name": "mask_preview.png", "url": "…", "content_type": "image/png", "format": "png" },
{ "name": "mask_stats.json", "url": "…", "content_type": "application/json", "format": "json" }],
"expires_in": 259200,
"parameters": { "duration_seconds": 10, "mask": { "expand": 32 }, "dry_run": true, "resolution": null, "…": "…" }
}
parameters is abridged: it echoes every lever you sent (sam_text, targets, …) plus resolution. mask_preview shows the mask in green over frames across the clip: it should cover the person to swap, and only them, on every frame. mask_stats.data (inlined when small; otherwise fetch mask_stats.url) has per-pass and per-frame coverage: a frame with no mask, or render_would_fail: true, means a real render with the same settings would fail, so fix the mask first (detect_time, temporal, boxes). A sudden jump in coverage usually means the mask jumped to another person or object. A dry run is masked only (regen builds no mask). Send the same request without dry_run to render.
Full example
Create, poll until done, download:
curl (bash)
# Needs curl and jq. Usage: HP_KEY=hp_… ./charswap.sh
JOB=$(curl -s -X POST https://api.happypony.io/api/v1/jobs/character-swap \
-H "Authorization: Bearer $HP_KEY" -H "Content-Type: application/json" \
-d '{"video_url": "https://assets.example.com/duo.mp4",
"pictures": ["https://assets.example.com/new-woman.png", "https://assets.example.com/new-man.png"],
"prompt": "the woman becomes Picture 1, the man becomes Picture 2",
"duration_seconds": 10}')
echo "$JOB" | jq .
STATUS_URL=$(echo "$JOB" | jq -r .status_url)
RESPONSE_URL=$(echo "$JOB" | jq -r .response_url)
while :; do
STATUS=$(curl -s "$STATUS_URL" -H "Authorization: Bearer $HP_KEY" | jq -r .status)
[ "$STATUS" = IN_QUEUE ] || [ "$STATUS" = IN_PROGRESS ] || break
sleep 15
done
echo "$STATUS"
curl -s -o swap.mp4 "$(curl -s "$RESPONSE_URL" -H "Authorization: Bearer $HP_KEY" | jq -r '.videos[0].url')"
Python
# pip install requests | HP_KEY=hp_… python charswap.py
import os, time, requests
BASE = "https://api.happypony.io/api/v1/jobs"
H = {"Authorization": f"Bearer {os.environ['HP_KEY']}"}
# A local clip instead of a public URL: upload it first.
# clip = requests.post(f"{BASE}/uploads", headers=H, files={"file": open("duo.mp4", "rb")}).json()["url"]
job = requests.post(f"{BASE}/character-swap", headers=H, json={
"video_url": "https://assets.example.com/duo.mp4",
"pictures": ["https://assets.example.com/new-woman.png", "https://assets.example.com/new-man.png"],
"prompt": "the woman becomes Picture 1, the man becomes Picture 2",
"duration_seconds": 10,
})
job.raise_for_status()
job = job.json()
print("job", job["request_id"], "costs", job["credits"], "credits")
while (s := requests.get(job["status_url"], headers=H).json())["status"] in ("IN_QUEUE", "IN_PROGRESS"):
time.sleep(15)
result = requests.get(job["response_url"], headers=H).json()
if result["status"] != "COMPLETED":
raise SystemExit(f"{result['status']}: {result.get('error', '')}")
with open(f"swap-{job['request_id']}.mp4", "wb") as f:
f.write(requests.get(result["videos"][0]["url"]).content)
Node.js
// Node 18+ (built-in fetch). Save as charswap.mjs: HP_KEY=hp_… node charswap.mjs
import { writeFileSync } from "node:fs";
const BASE = "https://api.happypony.io/api/v1/jobs";
const AUTH = { Authorization: `Bearer ${process.env.HP_KEY}` };
async function call(url, init = {}) {
const res = await fetch(url, { ...init, headers: { ...AUTH, ...init.headers } });
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
return res.json();
}
const job = await call(`${BASE}/character-swap`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
video_url: "https://assets.example.com/duo.mp4",
pictures: ["https://assets.example.com/new-woman.png", "https://assets.example.com/new-man.png"],
prompt: "the woman becomes Picture 1, the man becomes Picture 2",
duration_seconds: 10,
}),
});
console.log("job", job.request_id, "costs", job.credits, "credits");
let status;
while (true) {
({ status } = await call(job.status_url));
if (!["IN_QUEUE", "IN_PROGRESS"].includes(status)) break;
await new Promise((r) => setTimeout(r, 15_000));
}
const result = await call(job.response_url);
if (status !== "COMPLETED") throw new Error(`${status}: ${result.error ?? ""}`);
const res = await fetch(result.videos[0].url); // presigned: no auth header
writeFileSync(`swap-${job.request_id}.mp4`, Buffer.from(await res.arrayBuffer()));