> ## Documentation Index
> Fetch the complete documentation index at: https://docs.goenhance.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# GIF Face Swap API

> Swap a face into an animated GIF and get a looping GIF back. Send a GIF link and a face photo; no start or end time needed.

GIF Face Swap uses the same endpoint as [Video Face Swap](https://docs.goenhance.ai/api-reference/face-swap/video-generate.md). Pass a GIF link as `reference_video` and you get a face-swapped GIF back.

```bash theme={null}
curl --request POST \
  --url https://api.goenhance.ai/api/v1/videofaceswap/generate \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "reference_video": "https://example.com/reaction.gif",
    "reference_img": "https://example.com/my-face.jpg",
    "upscaler": 1
  }'
```

The response returns `data.img_uuid`. Poll [Task Detail](https://docs.goenhance.ai/api-reference/tasks/detail.md) or use a callback to get the result.

## Request

| Field | Required | Notes |
| - | - | - |
| `reference_video` | Yes | Link to the GIF. The URL path must end in `.gif`. |
| `reference_img` | Yes | Photo of the face to swap in. |
| `upscaler` | Yes | `1` (standard) or `2` (HD). |
| `start_time` | No | Seconds. Defaults to `0`. |
| `end_time` | No | Seconds. Defaults to the end of the GIF. A value past the end stops at the last frame. |
| `output_format` | No | `gif` (default for GIF input) or `mp4`. |
| `enhance_face` | No | Extra face restoration. |

Leave out `start_time` and `end_time` to swap the whole GIF. Set `output_format: "mp4"` to get a video instead, for example when the range is longer than 30 seconds.

## Limits

| | Limit |
| - | - |
| GIF file size | 20 MB |
| GIF frames | At least 2 (for a still image, use [Image Face Swap](https://docs.goenhance.ai/api-reference/face-swap/image-generate.md)) |
| Range length, GIF output | Up to 30 seconds |
| Range length, MP4 output | Up to 120 seconds |

## Pricing

Billed by the actual length of the range, with the same rates as Video Face Swap (1 token = \$0.02 USD). Anything shorter than 2 seconds is billed as 2 seconds. There is no extra charge for GIF output.

| Options | Tokens / second | USD / second |
| - | - | - |
| `upscaler: 1` | 1 | \$0.02 |
| `upscaler: 2` | 1.5 | \$0.03 |
| `upscaler: 1` + `enhance_face` | 1.5 | \$0.03 |
| `upscaler: 2` + `enhance_face` | 2.25 | \$0.045 |

Totals are rounded to whole tokens. Examples at `upscaler: 1`:

* A 1.2-second GIF costs 2 tokens (\$0.04).
* A 4-second GIF costs 4 tokens (\$0.08).

To quote a GIF, use the model name `mx-video-face-swap` and include the GIF link plus the range:

```json theme={null}
{
  "model": "mx-video-face-swap",
  "payload": {
    "reference_video": "https://example.com/reaction.gif",
    "start_time": 0,
    "end_time": 1.2,
    "upscaler": 1
  }
}
```

## Output

* The GIF loops forever and keeps the frame rate of the source, capped at 15 fps.
* Size: never larger than the source GIF, and at most 480 pixels wide and 854 pixels tall.
* The result keeps the duration of the requested range.
* Because the output is at most 480 pixels wide, `upscaler: 2` rarely makes a visible difference for GIFs.

## Result

In [Task Detail](https://docs.goenhance.ai/api-reference/tasks/detail.md) and callbacks, a GIF result has `type: "image"` and a `.gif` link. Show it with an `<img>` tag.

```json theme={null}
"json": [
  {
    "type": "image",
    "value": "https://.../user/face/2f1c9a3e-....gif"
  }
]
```

With `output_format: "mp4"` the result is a normal video: `type: "video"` and an `.mp4` link.

## Multiple people

To swap several people in one GIF, scan it first with [Video Face Scan](https://docs.goenhance.ai/api-reference/face-swap/video-scan.md), then follow the [multi-person face swap](https://docs.goenhance.ai/api-reference/face-swap/video-generate.md#multi-person-face-swap) steps. The GIF rules on this page still apply.


## OpenAPI

````yaml POST /api/v1/videofaceswap/generate
openapi: 3.1.0
info:
  title: GoEnhance API
  description: ''
  version: 1.0.0
servers:
  - url: https://api.goenhance.ai
security:
  - bearerAuth: []
tags:
  - name: Basic
  - name: Video2Video
paths:
  /api/v1/videofaceswap/generate:
    post:
      tags: []
      summary: Generate Video Face Swap
      description: >-
        **Pricing** — per second of the converted range (`end_time` minus
        `start_time`, which must be 2-120s), in tokens (USD at $0.02/token):


        | options | tokens/s | USD/s |

        |---|---|---|

        | `upscaler: 1` (720p) | 1 | $0.02 |

        | `upscaler: 2` (1080p) | 1.5 | $0.03 |

        | `upscaler: 1` + `enhance_face` | 1.5 | $0.03 |

        | `upscaler: 2` + `enhance_face` | 2.25 | $0.045 |


        ⚠️ **The length of the source video does not matter — only the range you
        ask for is billed.**


        Each multiplier is applied to the whole range and the running total is
        rounded to a whole number of tokens, so on a short range the effective
        rate can land a little off the table. Example: a 20s range at `upscaler:
        2` with `enhance_face` costs 45 tokens (= $0.90).


        **GIF** — pass a `.gif` link as `reference_video` to get a face-swapped
        GIF back. `start_time` / `end_time` are optional for GIFs (default: the
        whole GIF). GIFs are billed by the actual range length at the same
        rates; anything under 2 seconds is billed as 2 seconds. Limits: 20 MB
        per GIF, at least 2 frames, GIF output up to 30 seconds. The GIF result
        loops, keeps the source frame rate up to 15 fps, is never larger than
        the source and fits within 480×854; it is returned with `type: "image"`.


        **Multi-person** — to swap several people in one video, first call `POST
        /api/v1/videofaceswap/scan`, then pass its `img_uuid` as `scan_id`
        together with `faces` (one entry per person to swap). `reference_video`
        and `reference_img` are not needed in this mode: the scanned video is
        used. People you do not list stay unchanged. Pricing is exactly the same
        as a single-person swap, no matter how many people are swapped.
      parameters:
        - name: Authorization
          in: header
          description: ''
          required: true
          example: ''
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                reference_video:
                  type: string
                  description: >-
                    Target video or GIF URL. Supported: .mp4, .mov, .avi, .wmv,
                    .flv, .webm (max 100MB) and .gif (max 20MB, at least 2
                    frames). The format is taken from the extension in the URL
                    path. Required for single-person swaps. Ignored when
                    `scan_id` is set (the scanned video is used).
                reference_img:
                  type: string
                  description: >-
                    Face image URL (the face to put into the video), max 10 MB.
                    Required for single-person swaps. Ignored when `scan_id` is
                    set (use `faces` instead).
                scan_id:
                  type: string
                  description: >-
                    Optional. Multi-person mode: the `img_uuid` returned by
                    `POST /api/v1/videofaceswap/scan`. The scan must belong to
                    your account, have finished successfully and be less than 7
                    days old. Must be sent together with `faces`.
                  example: 8d3f2a61-5b7c-4e0a-9f12-3c4d5e6f7a8b
                faces:
                  type: array
                  minItems: 1
                  maxItems: 6
                  description: >-
                    Optional. Multi-person mode: which scanned people to swap
                    and with which face. 1-6 entries, each `person` at most
                    once. People not listed stay unchanged. The same
                    `reference_img` can be used for several people (for example,
                    when the scan split one person into two groups). Must be
                    sent together with `scan_id`.
                  items:
                    type: object
                    properties:
                      person:
                        type: integer
                        minimum: 0
                        description: >-
                          Index of the person in the scan result (the `person`
                          field of each scan entry, starting at 0).
                      reference_img:
                        type: string
                        description: >-
                          Face image URL for this person, max 10 MB. Must
                          contain a detectable face.
                    required:
                      - person
                      - reference_img
                upscaler:
                  type: integer
                  enum:
                    - 1
                    - 2
                  x-apifox:
                    enumDescriptions:
                      '1': 720p
                      '2': 1080p（仅vip）
                  description: Convert video resolution, 1 -> 720p, 2-> 1080p (1.5x price)
                start_time:
                  type: number
                  description: >-
                    The start time of the conversion (in seconds). Optional when
                    reference_video is a GIF (default 0).
                  maximum: 120
                  minimum: 0
                end_time:
                  type: number
                  description: >-
                    Conversion end time (in seconds). Optional when
                    reference_video is a GIF (default: end of the GIF). For
                    videos the range must be 2-120 seconds; for GIFs it can be
                    shorter than 2 seconds (billed as 2).
                  maximum: 120
                  minimum: 0
                enhance_face:
                  type: boolean
                  description: enable  (1.5x price)
                output_format:
                  type: string
                  enum:
                    - mp4
                    - gif
                  description: >-
                    Optional. Result format. Defaults to gif when
                    reference_video is a .gif, otherwise mp4. GIF output is
                    limited to 30 seconds, loops, keeps the source frame rate up
                    to 15 fps and fits within 480×854. GIF results are returned
                    with type "image".
                custom_callback_url:
                  type: string
                  format: uri
                  description: >-
                    Optional. A publicly accessible HTTPS URL. When the task
                    status changes (processing / success / failed), GoEnhance
                    sends a POST request to this URL. The request body is
                    identical to the response of GET /api/v1/jobs/detail. If
                    your server does not respond with HTTP 200, the notification
                    is retried up to 3 times, with a 3-second timeout per
                    attempt.
                  example: https://your-server.com/goenhance/callback
              required:
                - upscaler
                - start_time
                - end_time
              x-apifox-orders:
                - reference_video
                - reference_img
                - frame_rate
                - upscaler
                - start_time
                - end_time
                - enhance_face
            example:
              reference_video: https://cdn.goenhance.ai/images/static/demo/face-swap-1.mp4
              reference_img: https://cdn.goenhance.ai/images/static/demo/face-swap-1.jpg
              upscaler: 1
              start_time: 0
              end_time: 5
              enhance_face: false
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                  msg:
                    type: string
                  data:
                    type: object
                    properties:
                      img_uuid:
                        type: string
                      cost:
                        type: number
                        description: >-
                          Tokens deducted for this request. This is the amount
                          actually charged, so it already reflects any discount
                          active on your account and can be lower than the
                          listed price. Tokens are deducted when the task is
                          accepted, and refunded automatically if the generation
                          ends in failure.
                        example: 5.82
                    required:
                      - img_uuid
                      - cost
                required:
                  - code
                  - msg
                  - data
              example:
                code: 0
                msg: Success
                data:
                  img_uuid: c12b656c-747a-44fd-9c80-add79b0c52d5
                  cost: 5.82
          headers: {}
        '401':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties: {}
              example:
                code: 401
                msg: Token Error
          headers: {}
        '500':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties: {}
              example:
                code: 500
                msg: ''
          headers: {}
      deprecated: false
      security: []
components: {}

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.