Samples
REST examples in cURL, Node, and Python
Copy server-side examples that read AIFACESWAP_API_KEY from the environment and use idempotency keys for safe retries.
RESTBearer authJSON responses
Language tabs
curl -sS -X POST https://aifacesswap.com/api/v1/swaps \
-H "Authorization: Bearer $AIFACESWAP_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"type": "image",
"source_url": "https://example.com/face.jpg",
"target_url": "https://example.com/target.jpg",
"webhook_url": "https://example.com/webhooks/aifaceswap"
}'// Node 18+ has `fetch` and `crypto.randomUUID` globally.
const res = await fetch("https://aifacesswap.com/api/v1/swaps", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.AIFACESWAP_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(),
},
body: JSON.stringify({
type: "image",
source_url: "https://example.com/face.jpg",
target_url: "https://example.com/target.jpg",
webhook_url: "https://example.com/webhooks/aifaceswap",
}),
});
if (!res.ok) {
const { error } = await res.json();
throw new Error(`${error.code}: ${error.message} (request_id=${error.request_id})`);
}
const swap = await res.json();
console.log(swap.id, swap.status);import os
import uuid
import requests
resp = requests.post(
"https://aifacesswap.com/api/v1/swaps",
headers={
"Authorization": f"Bearer {os.environ['AIFACESWAP_API_KEY']}",
"Content-Type": "application/json",
"Idempotency-Key": str(uuid.uuid4()),
},
json={
"type": "image",
"source_url": "https://example.com/face.jpg",
"target_url": "https://example.com/target.jpg",
"webhook_url": "https://example.com/webhooks/aifaceswap",
},
timeout=30,
)
if not resp.ok:
err = resp.json()["error"]
raise RuntimeError(f"{err['code']}: {err['message']} (request_id={err['request_id']})")
swap = resp.json()
print(swap["id"], swap["status"])Server-side only. Keep API keys out of client bundles.
Code samples
Happy-path POST /api/v1/swaps in three languages. Each sample reads AIFACESWAP_API_KEY from the environment and sets a fresh Idempotency-Key.
curl -sS -X POST https://aifacesswap.com/api/v1/swaps \
-H "Authorization: Bearer $AIFACESWAP_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"type": "image",
"source_url": "https://example.com/face.jpg",
"target_url": "https://example.com/target.jpg",
"webhook_url": "https://example.com/webhooks/aifaceswap"
}'// Node 18+ has `fetch` and `crypto.randomUUID` globally.
const res = await fetch("https://aifacesswap.com/api/v1/swaps", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.AIFACESWAP_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(),
},
body: JSON.stringify({
type: "image",
source_url: "https://example.com/face.jpg",
target_url: "https://example.com/target.jpg",
webhook_url: "https://example.com/webhooks/aifaceswap",
}),
});
if (!res.ok) {
const { error } = await res.json();
throw new Error(`${error.code}: ${error.message} (request_id=${error.request_id})`);
}
const swap = await res.json();
console.log(swap.id, swap.status);import os
import uuid
import requests
resp = requests.post(
"https://aifacesswap.com/api/v1/swaps",
headers={
"Authorization": f"Bearer {os.environ['AIFACESWAP_API_KEY']}",
"Content-Type": "application/json",
"Idempotency-Key": str(uuid.uuid4()),
},
json={
"type": "image",
"source_url": "https://example.com/face.jpg",
"target_url": "https://example.com/target.jpg",
"webhook_url": "https://example.com/webhooks/aifaceswap",
},
timeout=30,
)
if not resp.ok:
err = resp.json()["error"]
raise RuntimeError(f"{err['code']}: {err['message']} (request_id={err['request_id']})")
swap = resp.json()
print(swap["id"], swap["status"])