{
  "openapi": "3.0.0",
  "info": {
    "title": "AI 影片換臉",
    "description": "# 概述\n影片換臉是 AI 驅動的流程，使用 YouCam 的 AI 影片換臉 API，在影片中將一個人的臉換成另一個人的臉。\n透過先進的 AI 技術，AI 影片換臉帶來極為逼真的結果。臉部表情、光線與膚色都經過精細調校，確保換後的臉部與原始影像無縫融合。\n\n> **注意：** 這個 API 僅支援單人臉的影片。若需要可自訂的解決方案，請  [聯絡我們](mailto:YouCamOnlineEditor_API@perfectcorp.com)。\n\n使用案例範例：\n![](https://plugins-media.makeupar.com/smb/blog/post/2024-08-23/b1f96100-37d6-4c28-b467-d397e9c3a25d.jpg)\n\n![](https://bcw-media.s3.ap-northeast-1.amazonaws.com/dt_yce_video_face_swap_S3_video_03_28785ebe0c.jpg)\n\n![](https://plugins-media.makeupar.com/smb/story/2024-09-12/3582f617-e88e-4219-9e72-43d4c26791cd.png)\n\n---\n\n## 檔案規格與錯誤\n\n* 支援的格式與尺寸\n\n|AI 功能|支援的尺寸|支援的檔案大小|支援的格式|\n|  ----  | ----  | ----  | ----  |\n| AI 影片換臉 | 輸入影片不得超過 30 秒、4K 解析度或 30 FPS，輸出限制為長邊 1280 解析度、30 FPS，最長 30 秒。 | 長度限制：30 秒 | 容器：mov, mp4 <br>影像：MPEG-4, MPEG-4 AVC, <br>音訊：aac, amr, mp3 |\n\n* 錯誤代碼\n\n|錯誤代碼|說明|\n|  ----  | ----  |\n| error_download_video | 下載來源影片錯誤 |\n| error_decode_video | 解碼來源影片錯誤 |\n| error_unsupported_video | 不支援的影片格式 |\n| exceed_max_filesize | 輸入檔案大小超過上限|\n| error_nsfw_content_detected | 在來源檔案中偵測到 NSFW 內容 |\n| error_decode_mask | 解碼遮罩圖片錯誤 |\n| invalid_parameter | 參數值無效|\n\n---\n\n## 點數消耗\n\n| AI 功能 | 消耗的點數 |\n|---|---|\n| AI 影片換臉 V1.0 | 1（5 秒）* |\n\n    > *若圖片數量或影片長度無法整除，點數無條件進位。\n\n---\n",
    "version": "",
    "termsOfService": "https://www.makeupar.com/perfectbeauty/youcam/terms-of-service-api",
    "contact": {
      "email": "YouCamOnlineEditor_API@perfectcorp.com"
    },
    "license": {
      "name": "Privacy policy",
      "url": "https://www.makeupar.com/perfectbeauty/youcam/privacy-policy-api"
    }
  },
  "servers": [
    {
      "url": "https://yce-api-01.makeupar.com"
    }
  ],
  "tags": [
    {
      "name": "V1.0",
      "description": "AI 照片換臉（影片）API 可讓您使用 AI 技術，在目標影片與一或多張參考圖片之間交換臉部。"
    }
  ],
  "paths": {
    "/s2s/v2.0/task/face-swap-vid": {
      "post": {
        "summary": "執行 AI 照片換臉（影片）任務。",
        "description": "AI 任務是非同步的。當功能支援 webhook 時，請優先使用以 webhook 為基礎的完成處理。設定您的 webhook 端點、驗證 webhook 簽章，並在收到 `success` 或 `error` 通知後，使用收到的 `task_id` 查詢任務結果。設定與驗證細節請見 [webhook 整合指南](/develop/webhook.md)。\n\n若您的整合不支援 webhook 或無法使用 webhook，請實作輪詢。送出 AI 任務後，以固定間隔（例如每 10 秒）輪詢狀態端點，直到任務狀態為 `success` 或 `error`。\n",
        "tags": [
          "V1.0"
        ],
        "security": [
          {
            "BearerAuthenticationV2": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "anyOf": [
                      {
                        "allOf": [
                          {
                            "title": "以來源檔案網址與參考檔案網址執行任務",
                            "required": [
                              "ref_file_url"
                            ]
                          },
                          {
                            "$ref": "#/components/schemas/BasicRunTaskV2VidSrcFileUrl"
                          },
                          {
                            "$ref": "#/components/schemas/BasicRunTaskV2RefFileUrl"
                          }
                        ]
                      },
                      {
                        "allOf": [
                          {
                            "title": "以來源檔案網址與參考檔案 ID 執行任務",
                            "required": [
                              "ref_file_id"
                            ]
                          },
                          {
                            "$ref": "#/components/schemas/BasicRunTaskV2VidSrcFileUrl"
                          },
                          {
                            "$ref": "#/components/schemas/BasicRunTaskV2RefFileId"
                          }
                        ]
                      },
                      {
                        "allOf": [
                          {
                            "title": "以來源檔案 ID 與參考檔案網址執行任務",
                            "required": [
                              "ref_file_url"
                            ]
                          },
                          {
                            "$ref": "#/components/schemas/BasicRunTaskV2SrcFileId"
                          },
                          {
                            "$ref": "#/components/schemas/BasicRunTaskV2RefFileUrl"
                          }
                        ]
                      },
                      {
                        "allOf": [
                          {
                            "title": "以來源檔案 ID 與參考檔案 ID 執行任務",
                            "required": [
                              "ref_file_id"
                            ]
                          },
                          {
                            "$ref": "#/components/schemas/BasicRunTaskV2SrcFileId"
                          },
                          {
                            "$ref": "#/components/schemas/BasicRunTaskV2RefFileId"
                          }
                        ]
                      }
                    ]
                  },
                  {
                    "type": "object",
                    "required": [
                      "dst_duration"
                    ],
                    "properties": {
                      "dst_duration": {
                        "type": "integer",
                        "description": "影片長度，以秒計"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "任務執行成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BasicRunTaskResponseV2"
                }
              }
            }
          },
          "400": {
            "description": "任務執行失敗",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/RunError"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/InvalidApiKey"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/s2s/v2.0/task/face-swap-vid/{task_id}": {
      "get": {
        "summary": "查詢 AI 照片換臉（影片）任務的狀態。",
        "tags": [
          "V1.0"
        ],
        "security": [
          {
            "BearerAuthenticationV2": []
          }
        ],
        "parameters": [
          {
            "name": "task_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "example": "grH0CvsgXuAIHLUzD0V1Ol34hoet3R1tvdbtiVHrDb6_UqCLKIejAIajwxrhOAfe"
            },
            "description": "要查詢的任務 ID"
          }
        ],
        "responses": {
          "200": {
            "description": "成功查詢任務狀態",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VidTaskStatusResponseV2"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidTaskId"
          },
          "401": {
            "$ref": "#/components/responses/InvalidApiKey"
          },
          "500": {
            "$ref": "#/components/responses/TaskTimeout"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuthenticationV2": {
        "type": "http",
        "scheme": "bearer",
        "description": "使用標準的 'Bearer authentication'。請在標頭中放入您的 'API Key'：`Authorization:Bearer YOUR_API_KEY`。請注意 'Bearer' 與 'YOUR_API_KEY' 之間有一個空格。"
      }
    },
    "schemas": {
      "BasicRunTaskV2VidSrcFileUrl": {
        "type": "object",
        "required": [
          "src_file_url"
        ],
        "properties": {
          "src_file_url": {
            "type": "string",
            "description": "要執行任務的檔案網址。該網址應可公開存取。",
            "example": "https://example.com/cat_video.mp4"
          }
        }
      },
      "BasicRunTaskV2RefFileUrl": {
        "type": "object",
        "properties": {
          "ref_file_url": {
            "type": "string",
            "description": "執行任務所用參考檔案的網址。該網址需可公開存取。",
            "example": "https://example.com/accessory.jpg"
          }
        }
      },
      "BasicRunTaskV2RefFileId": {
        "type": "object",
        "properties": {
          "ref_file_id": {
            "type": "string",
            "description": "執行任務所用參考檔案的 ID。來自上傳檔案 API 的檔案 ID。",
            "example": "pfNK5PuRe0MrwLHcGA3DOmB1ahwfXTbYHjv+KoBIxbE="
          }
        }
      },
      "BasicRunTaskV2SrcFileId": {
        "type": "object",
        "required": [
          "src_file_id"
        ],
        "properties": {
          "src_file_id": {
            "type": "string",
            "description": "要執行任務的檔案 ID。檔案 ID 來自上傳檔案 API。",
            "example": "pfNK5PuRe0MrwLHcGA3DOmB1ahwfXTbYHjv+KoBIxbE="
          }
        }
      },
      "BasicRunTaskResponseV2": {
        "type": "object",
        "properties": {
          "status": {
            "type": "integer",
            "description": "回應狀態",
            "example": 200
          },
          "data": {
            "type": "object",
            "properties": {
              "task_id": {
                "type": "string",
                "description": "這個任務的 ID。任務結果可以此 ID 查詢，有效期限 24 小時。",
                "example": "grH0CvsgXuAIHLUzD0V1Ol34hoet3R1tvdbtiVHrDb6_UqCLKIejAIajwxrhOAfe"
              }
            }
          }
        }
      },
      "RunError": {
        "type": "object",
        "properties": {
          "status": {
            "type": "integer",
            "description": "回應狀態",
            "example": 400
          },
          "error": {
            "type": "string",
            "description": "錯誤訊息",
            "example": "The operation could not be completed"
          },
          "error_code": {
            "type": "string",
            "enum": [
              "InvalidParameters",
              "CreditInsufficiency",
              "InvalidStyleGroup",
              "InvalidStyle",
              "BadRequest"
            ],
            "description": "錯誤代碼：\n* InvalidParameters - 請求參數無效\n* CreditInsufficiency - 點數不足，無法執行\n* BadRequest - 非預期的請求參數\n* InvalidStyleGroup - 風格群組 id 無效\n* InvalidStyle - 風格 id 無效\n"
          }
        }
      },
      "EngineErrorCode": {
        "type": "string",
        "nullable": true,
        "enum": [
          "error_exceed_max_image_size",
          "exceed_max_filesize",
          "invalid_parameter",
          "error_download_image",
          "error_download_mask",
          "error_decode_image",
          "error_decode_mask",
          "error_nsfw_content_detected",
          "error_no_face",
          "error_pose",
          "error_face_parsing",
          "error_inference",
          "exceed_nsfw_retry_limits",
          "error_upload",
          "unknown_internal_error"
        ],
        "description": "錯誤：\n- \\`error_exceed_max_image_size\\`  - 輸入圖片尺寸超過上限\n- \\`exceed_max_filesize\\` - 輸入檔案大小超過上限\n- \\`invalid_parameter\\` - 參數值無效\n- \\`error_download_image\\` - 下載來源圖片錯誤\n- \\`error_download_mask\\` - 下載遮罩圖片錯誤\n- \\`error_decode_image\\` - 解析來源圖片錯誤\n- \\`error_decode_mask\\` - 解析遮罩圖片錯誤\n- \\`error_nsfw_content_detected\\` - 在來源圖片中偵測到 NSFW 內容\n- \\`error_no_face\\` - 來源圖片未偵測到臉部\n- \\`error_pose\\` - 無法偵測來源圖片的姿势\n- \\`error_face_parsing\\` - 無法對來源圖片進行臉部分割\n- \\`error_inference\\` - 推論流程錯誤\n- \\`exceed_nsfw_retry_limits\\` - 超過重試上限以避免產生 NSFW 圖片\n- \\`error_upload\\` - 上傳結果圖片錯誤\n- \\`unknown_internal_error\\` - 其他"
      },
      "VidTaskStatusResponseBodySingleUrlResultsV2": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "description": "下載這個結果的網址。有效期限 2 小時",
            "example": "https://example.com/sample-result-url"
          }
        }
      },
      "VidTaskStatusResponseV2": {
        "type": "object",
        "properties": {
          "status": {
            "type": "integer",
            "description": "回應狀態",
            "example": 200
          },
          "data": {
            "type": "object",
            "properties": {
              "task_status": {
                "type": "string",
                "enum": [
                  "running",
                  "success",
                  "error"
                ],
                "description": "這個任務的狀態"
              },
              "error": {
                "$ref": "#/components/schemas/EngineErrorCode"
              },
              "error_message": {
                "type": "string",
                "description": "錯誤的詳細說明"
              },
              "results": null
            }
          }
        },
        "$ref": "#/components/schemas/VidTaskStatusResponseBodySingleUrlResultsV2"
      }
    },
    "responses": {
      "InvalidApiKey": {
        "description": "API 金鑰無效或缺失",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "integer",
                  "example": 401,
                  "description": "回應狀態"
                },
                "error": {
                  "type": "string",
                  "example": "Invalid API key"
                }
              }
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "請求過多",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "integer",
                  "example": 429,
                  "description": "回應狀態"
                },
                "error": {
                  "type": "string",
                  "example": "Too many requests"
                }
              }
            }
          }
        }
      },
      "InvalidTaskId": {
        "description": "任務 ID 無效",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "integer",
                  "example": 400,
                  "description": "回應狀態"
                },
                "error": {
                  "type": "string",
                  "example": "Invalid task ID"
                }
              }
            }
          }
        }
      },
      "TaskTimeout": {
        "description": "任務執行逾時",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "integer",
                  "example": 500,
                  "description": "回應狀態"
                },
                "error": {
                  "type": "string",
                  "example": "Task execution timed out"
                }
              }
            }
          }
        }
      }
    }
  }
}