End-to-end guide to generate face-swapped videos with simple HTTP calls.
Visit /api and start a free trial or buy credits. Your API key will be emailed to you. Keep it secret (don’t commit it to GitHub).
import os
API_KEY = os.getenv("FACE_SWAP_API_KEY", "YOUR_API_KEY") # set in your shell or .env
export FACE_SWAP_API_KEY="YOUR_API_KEY"
The API needs directly downloadable URLs (HTTP 200 without auth). Test your links in an incognito window.
/resolve/<branch>/file.ext URLs.?dl=0 → ?dl=1 for direct download.raw.githubusercontent.com link.# Requires: pip install boto3
import boto3
from botocore.client import Config
s3 = boto3.client("s3", config=Config(signature_version="s3v4"))
url = s3.generate_presigned_url(
ClientMethod="get_object",
Params={"Bucket": "YOUR_BUCKET", "Key": "path/to/face.jpg"},
ExpiresIn=3600
)
print(url) # use as input_image_url
Allowed durations (seconds): 4 (trial), 60, 120, 180.
import os, requests
API_KEY = os.getenv("FACE_SWAP_API_KEY", "YOUR_API_KEY")
IMAGE_URL = "https://tinyurl.com/elonmusk-faceswap"
VIDEO_URL = "https://tinyurl.com/ironman-faceswap"
payload = {
"key": API_KEY,
"input_image_url": IMAGE_URL,
"input_video_url": VIDEO_URL,
"duration": 120, # 4 | 60 | 120 | 180
"gender": "all" # optional: all | female | male
}
r = requests.post("https://www.face-swap.co/api/generate", json=payload, timeout=60)
r.raise_for_status()
resp = r.json()
print(resp)
job_id = resp.get("job_id") # Save this for polling
curl -s -X POST https://www.face-swap.co/api/generate \
-H 'Content-Type: application/json' \
-d '{
"key": "'"${FACE_SWAP_API_KEY}"'",
"input_image_url": "https://tinyurl.com/elonmusk-faceswap",
"input_video_url": "https://tinyurl.com/ironman-faceswap",
"duration": 120,
"gender": "all"
}'
Poll until the job is completed or failed; wait 3–5s between requests.
import time, requests
assert job_id, "job_id missing from generate response"
status_url = f"https://www.face-swap.co/api/status/{job_id}"
while True:
s = requests.get(status_url, timeout=30)
s.raise_for_status()
data = s.json()
print(data)
state = str(data.get("status", "")).lower()
if state in {"succeeded", "completed", "done"}:
print("✅ Finished.")
break
if state in {"failed", "error"}:
raise SystemExit("❌ Job failed: " + str(data))
time.sleep(5)
# Replace with your job_id
JOB_ID="0c1449fc0e764b5ebdfe24a52bd8f8fa"
# One-off check:
curl -s https://www.face-swap.co/api/status/${JOB_ID}
# Simple bash poller:
while true; do
resp=$(curl -s https://www.face-swap.co/api/status/${JOB_ID})
echo "$resp"
status=$(echo "$resp" | grep -o '"status":"[^"]*' | cut -d'"' -f4)
if [[ "$status" == "succeeded" || "$status" == "completed" || "$status" == "done" ]]; then
echo "✅ Finished"; break
elif [[ "$status" == "failed" || "$status" == "error" ]]; then
echo "❌ Failed"; exit 1
fi
sleep 5
done
Endpoint: GET /api/credits/{API_KEY}
import os, requests
API_KEY = os.getenv("FACE_SWAP_API_KEY", "YOUR_API_KEY")
r = requests.get(f"https://www.face-swap.co/api/credits/{API_KEY}", timeout=30)
r.raise_for_status()
print(r.json())
curl -s https://www.face-swap.co/api/credits/${FACE_SWAP_API_KEY}
Endpoint: GET /api/jobs/{API_KEY}
import os, requests
API_KEY = os.getenv("FACE_SWAP_API_KEY", "YOUR_API_KEY")
r = requests.get(f"https://www.face-swap.co/api/jobs/{API_KEY}", timeout=30)
r.raise_for_status()
print(r.json())
curl -s https://www.face-swap.co/api/jobs/${FACE_SWAP_API_KEY}
duration=4 while testing to conserve credits.Questions? Email face.swapper.app@gmail.com