Python 3.10+ · requests 2.32+

FaceSwapAI Python API client

The Python reference keeps multipart upload, consent, polling and error handling visible. It uses a short dependency list and does not submit any live task during tests.

Image workflow

Create an isolated environment

  1. 1
    Install the single dependencypython -m pip install -r requirements.txt
  2. 2
    Set the server-side keyexport FACESWAPAI_API_KEY="YOUR_API_KEY"
  3. 3
    Run the examplepython examples/python/image_swap.py source.jpg target.jpg
PythonView source
import os
from src.python.faceswapai import FaceSwapAIClient

client = FaceSwapAIClient(os.environ["FACESWAPAI_API_KEY"])
accepted = client.submit_image("source.jpg", "target.jpg")
task = client.wait_for_task("image", accepted["taskId"])
print((task.get("result") or {}).get("url"))

Failure handling

Keep HTTP context intact

FaceSwapAIError preserves the HTTP status and parsed response body so integrations can distinguish verification, credit, input, rate-limit and provider failures.

401Missing or invalid API key
402Insufficient credits
403Email verification required
413Request or file exceeds a limit
429Authenticated request limit reached
503Processing provider unavailable