Developer Docs/Head Swap API

Head Swap API

Build Head Swap integrations with HeadSwap. Review authentication, request parameters, task creation, status, and result endpoints.

Overview

Replace the head in an image with a target face while keeping the original body, clothing, lighting, and background intact.

Primary Endpoint

POST/api/v1/headSwap/start

Generate a head swap result by replacing the head in a target image/video with a source head. **Supported modes:** - **Image to Image**: Provide an image as `target_image_url` to get a head-swapped image - **Image to Video**: Provide a video as `target_image_url` to get a head-swapped video (max 15 seconds) **Content moderation:** - CSAM detection is performed on input images - If confirmed CSAM intent is detected together with age < 15, the request will be rejected with code 1003 - If suspected CSAM is detected, set `minor_suspected_skip: true` to proceed - Head swap sends no user prompt to the detector, so a low apparent age alone does not trigger 1003 **Async workflow:** 1. Task is created with status `initialized` 2. Task is queued and sent to algorithm service (status: `sent`) 3. Algorithm processes the task (status: `processing`) 4. Result is ready (status: `completed`) or failed (status: `failed`) 5. Use `/api/v1/headSwap/{_id}` to poll for status updates. ### Request - This operation permits anonymous requests. Authenticated callers may send a bearer token. - Supply `x-anonymous-id` headers as documented in the parameter schema, including any anonymous identity requirements. - Send an `application/json` body. Required fields: `image_url`, `target_image_url`. - API-token callers may include `webhook_url` and `webhook_token` for best-effort terminal-state notifications; ordinary JWT/cookie calls ignore these fields. ### Behavior - This is an asynchronous operation: a successful submission creates a task and returns before processing finishes. - Persist the returned task identifier and use the corresponding detail or list operation to observe progress. - Treat the detail endpoint as the source of truth even when webhook delivery is enabled. ### Response - A `200` response confirms task acceptance; it does not by itself mean media generation has completed. - Retain the returned identifier and wait for a documented terminal status before using output URLs. - JSON object responses, including error responses, normally carry a top-level `trace_id` string for this request; include it when contacting support. It is not a task identifier. - Do not infer undocumented fields or statuses; clients should tolerate additional response properties. ### Errors - `400` — Invalid request parameters or insufficient coins. - `401` — Unauthorized - Invalid or missing JWT token. - `422` — Content moderation rejected an input image (`image_url` or an image supplied as `target_image_url`). Code `1003` means confirmed minor content. Code `1004` means suspected minor content. For `1004`, confirm the input and retry with `minor_suspected_skip: true`. ### Related Operations - `GET /api/v1/headSwap/allRecords` — Get all head swap records. - `GET /api/v1/headSwap/{_id}` — Get head swap task detail. - `DELETE /api/v1/headSwap/{_id}` — Delete head swap task. Authentication: set header Authorization: Bearer <token> (supports user JWT or sk_ API token).

Request Parameters

NameTypeRequiredDescription
ai_sharing_consentobjectNoConsent receipt for newer native apps. Legacy native requests may omit this field and continue without a consent record. If present, null, malformed, expired or incomplete receipts return AI_SHARING_CONSENT_REQUIRED before generation. Valid receipts cover all actual AI recipients, including safety providers and intermediaries, and constrain later fallback. Content safety checks remain required for native requests. Web and legacy API behavior is unchanged.
ai_sharing_consent.versionenum: 2026-11-12Yes-
ai_sharing_consent.recipientsarray<string>Yes-
free_quota_expectedbooleanNoWeb request expecting a free discount; returns 12006 when the discount decreases. API tokens are ineligible.
free_quota_expected_coinsnumberNoMinimum expected free credits. If the available discount decreases, returns 12006 without creating a task or automatically charging a higher price.; minimum: 0
image_urlstringYesURL of the source head image (the head to be transplanted)
target_image_urlstringYesURL of the target body image or video (where the head will be placed)
minor_suspected_skipbooleanNoSkip the suspected CSAM warning. Use with caution.; default: false
webhook_urlstringNoHTTPS URL to receive task.completed / task.failed notifications. Best-effort delivery, single attempt, no retries; clients should treat the detail API as the source of truth.; maxLength: 2048
webhook_tokenstringNoOptional plaintext token returned in the X-A2e-Webhook-Token header so receivers can verify the request originated from a2e.; maxLength: 256
Request schema and conditional rules
{
  "allOf": [
    {
      "type": "object",
      "properties": {
        "ai_sharing_consent": {
          "type": "object",
          "description": "Consent receipt for newer native apps. Legacy native requests may omit this field and continue without a consent record. If present, null, malformed, expired or incomplete receipts return AI_SHARING_CONSENT_REQUIRED before generation. Valid receipts cover all actual AI recipients, including safety providers and intermediaries, and constrain later fallback. Content safety checks remain required for native requests. Web and legacy API behavior is unchanged.",
          "required": [
            "version",
            "recipients"
          ],
          "properties": {
            "version": {
              "type": "string",
              "enum": [
                "2026-11-12"
              ]
            },
            "recipients": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "example": [
                "A2E",
                "Alibaba Cloud"
              ]
            }
          }
        },
        "free_quota_expected": {
          "type": "boolean",
          "description": "Web request expecting a free discount; returns 12006 when the discount decreases. API tokens are ineligible."
        },
        "free_quota_expected_coins": {
          "type": "number",
          "minimum": 0,
          "description": "Minimum expected free credits. If the available discount decreases, returns 12006 without creating a task or automatically charging a higher price."
        },
        "image_url": {
          "type": "string",
          "description": "URL of the source head image (the head to be transplanted)",
          "format": "uri",
          "example": "https://example.com/head.jpg"
        },
        "target_image_url": {
          "type": "string",
          "description": "URL of the target body image or video (where the head will be placed)",
          "format": "uri",
          "example": "https://example.com/body.jpg"
        },
        "minor_suspected_skip": {
          "type": "boolean",
          "default": false,
          "description": "Skip the suspected CSAM warning. Use with caution.",
          "example": false
        }
      },
      "required": [
        "image_url",
        "target_image_url"
      ]
    },
    {
      "$ref": "#/components/schemas/WebhookInput"
    }
  ]
}

Response Fields

code: integer
data: object
data.hasRefundCoin: boolean
Stored refund flag; true does not confirm crediting while refund_pending is true. Omitted when unknown, including legacy records without a stored flag.
data.refund_pending: boolean
True means refund pending resolution and takes precedence over hasRefundCoin. Explicit false is preserved; omitted when unknown, including legacy records without a stored flag.
data._id: string
Task ID for polling status
data.image_url: string
Source head image URL
data.target_image_url: string
Target body image/video URL
data.current_status: enum: initialized | sent | pending | processing | completed | failed
Current task status
data.coins: number
Coins consumed for this task
data.createdAt: string
Task creation time
trace_id: string
Trace ID of this HTTP request. Include it when contacting support about this request. It is generated per request and is not a task identifier; use the returned task `_id` to query results.

Request Example

curl -X POST "https://headswap.app/api/v1/headSwap/start" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "image_url": "https://example.com/head.jpg",
  "target_image_url": "https://example.com/body.jpg"
}'

Related Endpoints

Responses

200

Head swap task started successfully

400

Invalid request parameters or insufficient coins.

401

Unauthorized - Invalid or missing bearer token

422

Content moderation rejected an input image (`image_url` or an image supplied as `target_image_url`). Code `1003` means confirmed minor content. Code `1004` means suspected minor content. For `1004`, confirm the input and retry with `minor_suspected_skip: true`.

Head Swap API Documentation