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

# Video Faceswap

> Swap faces in videos with high quality

<Warning>
  The resources (image, video, voice) generated by our API are valid for 7 days.
  Please save the relevant resources as soon as possible to prevent expiration.
</Warning>

## Important Notes

* **sourceImage**: You need to change it to the link collection of the face you need. Pass your image through the [Face Detect API](/ai-tools-suite/faceswap/face-detect) to obtain the link and key point data
* **targetImage**: Represents the collection of faces after face detection using modifyVideo. When the original video has multiple faces, here is the image link and key point data of each face
* When using [Face Detect API](/ai-tools-suite/faceswap/face-detect), set `single_face: true` to return only the largest face data, or `false` to return all detected faces
* Ensure that each picture in the sourceImage is a single face, otherwise the face change may fail
* You need to ensure that sourceImage and targetImage correspond to each other in order


## OpenAPI

````yaml POST /api/open/v3/faceswap/highquality/specifyvideo
openapi: 3.0.3
info:
  title: Face Swap API
  description: API for face swapping in images and videos
  version: 1.0.0
servers:
  - url: https://openapi.akool.com
    description: Production server
security:
  - ApiKeyAuth: []
  - BearerAuth: []
paths:
  /api/open/v3/faceswap/highquality/specifyvideo:
    post:
      tags:
        - Face Swap
      summary: Video Faceswap
      description: Swap faces in videos with high quality
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/VideoFaceswapRequest'
            example:
              sourceImage:
                - path: >-
                    https://d21ksh0k4smeql.cloudfront.net/crop_1705475757658-3362-0-1705475757797-3713.png
                  opts: 239,364:386,366:317,472:266,539
              targetImage:
                - path: >-
                    https://d21ksh0k4smeql.cloudfront.net/crop_1705479323786-0321-0-1705479323896-7695.png
                  opts: 176,259:243,259:209,303:183,328
              face_enhance: 0
              modifyVideo: >-
                https://d21ksh0k4smeql.cloudfront.net/avatar_01-1705479314627-0092.mp4
              webhookUrl: ''
      responses:
        '200':
          description: Video faceswap request submitted successfully
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/ApiResponse'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/FaceswapResult'
components:
  schemas:
    VideoFaceswapRequest:
      type: object
      required:
        - targetImage
        - sourceImage
        - modifyVideo
      properties:
        sourceImage:
          type: array
          items:
            $ref: '#/components/schemas/FaceImageWithOpts'
          description: >-
            Replacement target image information. You need to change it to the
            link collection of the face you need.
        targetImage:
          type: array
          items:
            $ref: '#/components/schemas/FaceImageWithOpts'
          description: >-
            A collection of faces in the original video. Represents the
            collection of faces after face detection using modifyVideo.
        face_enhance:
          type: integer
          enum:
            - 0
            - 1
          default: 0
          description: Whether facial enhancement (1 means open, 0 means close)
        modifyVideo:
          type: string
          description: The original video you need to change the face
        webhookUrl:
          type: string
          description: Callback url address based on HTTP request
    ApiResponse:
      type: object
      required:
        - code
        - msg
      properties:
        code:
          type: integer
          description: 'Interface returns business status code (1000: success)'
          example: 1000
        msg:
          type: string
          description: Interface returns status information
          example: OK
    FaceswapResult:
      type: object
      properties:
        _id:
          type: string
          description: Interface returns data ID
        url:
          type: string
          description: Faceswap result URL
        job_id:
          type: string
          description: Task processing unique ID
    FaceImageWithOpts:
      type: object
      required:
        - path
      properties:
        path:
          type: string
          format: uri
          description: |
            Valid URL of the face image. Must be a valid HTTP/HTTPS URL.
            Invalid URLs will be rejected during validation.
        opts:
          type: string
          description: >
            Face landmark coordinates string (conditional requirement).

            You can get this value from the `crop_landmarks` field returned by
            the [Face Detection
            API](/ai-tools-suite/face-detection/detect-faces).


            **Required** when `sourceImage` or `targetImage` array length > 1.

            **Optional** when both `sourceImage` and `targetImage` arrays have
            exactly 1 element each.


            When provided, improves face alignment accuracy.

            Format: colon-separated coordinate pairs, e.g.
            "262,175:363,175:313,215:272,279"
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Your API Key used for request authorization. If both Authorization and
        x-api-key have values, Authorization will be used first and x-api-key
        will be discarded.
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Your API Key used for request authorization. Get Token from
        authentication/usage#get-the-token

````