Face swap
Pricing: Face swap
A base image and one to three reference faces in, one image out: the person in the base image with the reference face. The same job as a generation on www.happypony.io/face-swap.
POST https://api.happypony.io/api/v1/jobs/face-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/face-swap with Content-Type: application/json.
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
base_image_url |
string | yes | — | The body, pose, clothes and scene to keep. See Image inputs. |
face_image_urls |
string[] | yes | — | 1 to 3 photos of the face to put in. More angles of the same face help. |
There are no other settings: the output follows the base image.
Request body:
{
"base_image_url": "https://resource.pipelet.net/images/test/selfie5.png",
"face_image_urls": ["https://resource.pipelet.net/images/test/selfie3.png"]
}
curl -X POST https://api.happypony.io/api/v1/jobs/face-swap \
-H "Authorization: Bearer $HP_KEY" -H "Content-Type: application/json" \
-d '{"base_image_url": "https://resource.pipelet.net/images/test/selfie5.png", "face_image_urls": ["https://resource.pipelet.net/images/test/selfie3.png"]}'
Response 202 (fields: Create response):
{
"request_id": "48340",
"type": "face-swap",
"status": "IN_QUEUE",
"credits": 5,
"status_url": "https://api.happypony.io/api/v1/jobs/48340/status",
"response_url": "https://api.happypony.io/api/v1/jobs/48340",
"cancel_url": "https://api.happypony.io/api/v1/jobs/48340/cancel"
}
2) Poll for status
Poll the status_url until status is COMPLETED, FAILED or CANCELLED (fields: Status response). A queued job can be cancelled with PUT on the cancel_url (Cancel a request).
curl https://api.happypony.io/api/v1/jobs/48340/status -H "Authorization: Bearer $HP_KEY"
{
"request_id": "48340",
"type": "face-swap",
"status": "IN_PROGRESS",
"created_at": "2026-10-05T10:00:00.000Z",
"completed_at": null,
"credits": 5,
"status_url": "…", "response_url": "…", "cancel_url": "…"
}
3) Fetch the result
When status is COMPLETED, fetch the response_url (common fields: Result response):
curl https://api.happypony.io/api/v1/jobs/48340 -H "Authorization: Bearer $HP_KEY"
{
"request_id": "48340",
"type": "face-swap",
"status": "COMPLETED",
"created_at": "2026-10-05T10:00:00.000Z",
"completed_at": "2026-10-05T10:00:41.000Z",
"credits": 5,
"images": [{ "url": "https://…signed…", "format": "png" }],
"expires_in": 259200,
"parameters": { "model": "qwen-image-edit-face-swap", "faces": 1 },
"status_url": "…", "response_url": "…", "cancel_url": "…"
}
| Field | Type | Description |
|---|---|---|
images |
object[] | The swapped image. |
parameters |
object | model (always qwen-image-edit-face-swap) and faces, the number of reference faces. |
Full example
Create, poll until done, download:
curl (bash)
# Needs curl and jq. Usage: HP_KEY=hp_… ./swap.sh body.png face.png
up() { curl -s -X POST https://api.happypony.io/api/v1/jobs/uploads \
-H "Authorization: Bearer $HP_KEY" -F "file=@$1" | jq -r .url; }
BASE=$(up "$1"); FACE=$(up "$2")
JOB=$(curl -s -X POST https://api.happypony.io/api/v1/jobs/face-swap \
-H "Authorization: Bearer $HP_KEY" -H "Content-Type: application/json" \
-d "{\"base_image_url\": \"$BASE\", \"face_image_urls\": [\"$FACE\"]}")
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 5
done
echo "$STATUS"
curl -s "$RESPONSE_URL" -H "Authorization: Bearer $HP_KEY" | jq -r '.images[] | "\(.format) \(.url)"' |
while read -r FORMAT URL; do curl -s -o "swap-$((++i)).$FORMAT" "$URL"; done
Python
# pip install requests | HP_KEY=hp_… python swap.py
import os, time, requests
BASE = "https://api.happypony.io/api/v1/jobs"
H = {"Authorization": f"Bearer {os.environ['HP_KEY']}"}
job = requests.post(f"{BASE}/face-swap", headers=H, json={
"base_image_url": "https://resource.pipelet.net/images/test/selfie5.png",
"face_image_urls": ["https://resource.pipelet.net/images/test/selfie3.png"],
})
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(5)
result = requests.get(job["response_url"], headers=H).json()
if result["status"] != "COMPLETED":
raise SystemExit(f"{result['status']}: {result.get('error', '')}")
for i, image in enumerate(result["images"]):
with open(f"swap-{job['request_id']}-{i}.{image['format']}", "wb") as f:
f.write(requests.get(image["url"]).content)