{
  "openapi": "3.0.0",
  "info": {
    "title": "AI 照片去背",
    "description": "# 概述\n以無可挑剔的精準度移除照片背景，確保影像的高品質。\n* 自動背景偵測：：使用 AI 辨識並將主體與背景分離。\n* 高精度編輯：：在主體周圍提供乾淨且精準的邊緣。\n* 支援多種類別：人物、產品、動物、汽車、圖形等。\n* 易於串接其他 AI 任務：輸出的檔案 ID 可即刻串接到其他 AI 任務。\n\n![](https://plugins-media.makeupar.com/smb/blog/post/2023-11-03/54285311-7c65-4658-9e27-11bf5c8dfe56.jpg)\n\n## 整合指南\n* 如何執行 AI 照片去背\n1. **調整來源圖片尺寸**</br>\n  調整您的照片以符合支援的尺寸。細節請參考**[檔案規格與錯誤](#section/overview/File-Specs-and-Errors)**\n\n2. **使用 File API 上傳檔案**</br>\n  使用 ***/s2s/v2.0/file*** API 上傳目標使用者圖片。\n    - 圖片需求\n      - 細節請參考**[檔案規格與錯誤](#section/overview/File-Specs-and-Errors)**。\n    - ***重要***：僅呼叫 File API 並不會上傳您的檔案。您必須**手動上傳**檔案到**File API 回應中提供的網址**。該網址就是您的上傳目的地，請確保檔案成功傳輸到該處後再繼續。<br>\n    在呼叫 AI API 之前，請確保您的檔案已成功上傳。使用 File API 取得上傳網址，然後將檔案上傳到該位置。上傳完成後，您會在回應中取得 ***file_id***，這個 ID 就是您用於存取該檔案相關 AI 功能的依據。\n    \n      > **警告：** 請注意，若您未將檔案上傳到 File API 回應中提供的網址，使用 AI API 時會得到 500 Server Error / unknown_internal_error 或 404 Not Found 錯誤。\n\n3. **執行 AI 任務**</br>\n  上傳完成後，使用檔案 ID 呼叫 POST 'task/sod' 執行 AI 任務，並取得用於監控的 ***task_id***。\n\n4. **設定 webhook 或輪詢，以查詢任務狀態直到成功或錯誤**</BR>\n***task_id*** 用於設定 webhook 或實作輪詢，在整個保留期間監控任務狀態。在 AI 引擎完成任務之前，狀態會維持為 running。任務處於執行狀態時不會消耗點數。處理完成後，任務狀態會變為 success 或 error。\n\n1. **成功後取得 AI 任務的結果**</BR>\n引擎成功處理您的輸入檔案並生成結果影像後，任務會變為 'success' 狀態。您會取得處理後影像的網址，以及一個 dst_id，讓您在無需重新上傳結果圖片的情況下串接另一個 AI 任務。\n點數僅在這種情況下會被消耗。若引擎處理任務失敗，任務狀態會變為 'error'，且不會消耗點數。</BR>\n扣除點數時，系統會優先使用接近到期的點數。若到期日相同，則扣除最早取得的點數。\n\n* 示範情境：\n常見實作案例：\n![](https://bcw-media.s3.ap-northeast-1.amazonaws.com/Transparen_Background_aca3cdbd83.jpg)\n\n## 輸入與輸出\n* 輸入\n   * `Image`\n- **類型：** `image`\n- **說明：** 具有清晰前景的影像。\n\n實際應用（輸入）： \n![](https://bcw-media.s3.ap-northeast-1.amazonaws.com/yce_removal_bg_s4_poster_1_289b8eaf81.png)\n\n---\n\n* 輸出\n   * `前景圖片`\n- **類型：** `image`\n- **說明：** 已移除背景的影像。\n\n實際應用（輸出）：\n![](https://bcw-media.s3.ap-northeast-1.amazonaws.com/yce_removal_bg_s4_poster_2_a6bc3c5f6a.png)\n\n## 檔案規格與錯誤\n* 支援的格式與尺寸\n\n|AI 功能|支援的尺寸|檔案大小|接受的格式|\n|  ----  | ----  | ----  | ----  |\n|AI 照片去背|輸入與輸出圖片的建議與限制如下：</br>解析度：4096 × 4096 像素（最長邊不得超過 4096 像素）|<10MB|JPG 與 PNG|\n\n* 錯誤代碼\n\n|錯誤代碼|說明|\n|  ----  | ----  |\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_download_video|下載來源影片錯誤|\n|error_decode_video|解碼來源影片錯誤|\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|error_multiple_people|在來源圖片中偵測到多人|\n|error_no_shoulder|來源圖片中肩膀不可見|\n|error_large_face_angle|上傳圖片的臉部角度過大|\n|error_hair_too_short|輸入的頭髮過短|\n|error_unexpected_video_duration|影片長度等於 dstDuration|\n|error_bald_image|輸入的髮型為禿頭|\n|error_unsupport_ratio|輸入圖片的長寬比不受支援|\n|unknown_internal_error|其他|\n\n---\n\n## 點數消耗\n\n| AI 功能 | 消耗的點數 |\n|---|---|\n| AI 照片去背 V1.0 | 1 |\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 分割自動偵測並移除圖片背景。"
    }
  ],
  "paths": {
    "/s2s/v2.0/task/sod": {
      "post": {
        "summary": "執行 AI 照片去背任務。",
        "description": "這個端點啟動背景移除流程。您必須提供從檔案上傳 API 取得的檔案 ID。任務會以非同步方式處理，您可以使用這個回應回傳的 task_id 查詢其狀態。\n",
        "tags": [
          "V1.0"
        ],
        "security": [
          {
            "BearerAuthenticationV2": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BasicRunTaskV2"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "任務執行成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BasicRunTaskResponseV2"
                }
              }
            }
          },
          "400": {
            "description": "任務執行失敗",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/responses/RunError"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/InvalidApiKey"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        }
      }
    },
    "/s2s/v2.0/task/sod/{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/TaskStatusResponseV2"
                }
              }
            }
          },
          "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": {
      "EngineErrorCode": {
        "type": "string",
        "nullable": true,
        "enum": [
          "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\n- `exceed_max_filesize` - 輸入檔案大小超過上限\n\n- `invalid_parameter` - 參數值無效\n\n- `error_download_image` - 下載來源圖片錯誤\n\n- `error_download_mask` - 下載遮罩圖片錯誤\n\n- `error_decode_image` - 解碼來源圖片錯誤\n\n- `error_decode_mask` - 解碼遮罩圖片錯誤\n\n- `error_nsfw_content_detected` - 在來源圖片中偵測到 NSFW 內容\n\n- `error_no_face` - 來源圖片未偵測到臉部\n\n- `error_pose` - 在來源圖片偵測姿勢失敗\n\n- `error_face_parsing` - 在來源圖片進行人臉分割失敗\n\n- `error_inference` - 推論流程錯誤\n\n- `exceed_nsfw_retry_limits` - 超過重試上限，以避免\n生成 NSFW 圖片\n\n- `error_upload` - 上傳結果圖片錯誤\n\n- `unknown_internal_error` - 其他\n"
      },
      "FileV1.1": {
        "title": "File V1.1",
        "description": "這個物件代表一個檔案。",
        "type": "object",
        "required": [
          "files"
        ],
        "properties": {
          "files": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "content_type",
                "file_name",
                "file_size"
              ],
              "properties": {
                "content_type": {
                  "type": "string",
                  "example": "image/jpg",
                  "description": "這個檔案的內容 MIME 類型。目前可用的值列於 enum 中。"
                },
                "file_name": {
                  "type": "string",
                  "example": "my-selfie.jpg",
                  "description": "這個檔案的名稱"
                },
                "file_size": {
                  "type": "integer",
                  "example": 50000,
                  "description": "這個檔案的內容長度，以位元組計。不應超過 10MB。"
                }
              }
            }
          }
        }
      },
      "BasicFileResponse": {
        "type": "object",
        "properties": {
          "files": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "content_type": {
                  "type": "string",
                  "example": "image/jpg",
                  "description": "這個檔案的內容 MIME 類型。"
                },
                "file_name": {
                  "type": "string",
                  "example": "my-selfie.jpg",
                  "description": "這個檔案的名稱"
                },
                "file_id": {
                  "type": "string",
                  "example": "U8aqJbsXGT537jtGnEDFHqxdDXqh8+oTF/cSkLimzuvVwMP+Jb1XbjPsf7ZgUgLY",
                  "description": "這個檔案的 ID。其他執行任務的 API 會需要這個 `file_id`。"
                },
                "requests": {
                  "type": "array",
                  "description": "使用下方的 `url`、`headers`、`method` 上傳檔案。完成後，使用 `file_id` 繼續呼叫執行任務的 API。",
                  "items": {
                    "type": "object",
                    "properties": {
                      "headers": {
                        "type": "object",
                        "example": {
                          "Content-Type": "image/jpg",
                          "Content-Length": 50000
                        },
                        "description": "上傳檔案時要納入的標頭"
                      },
                      "url": {
                        "type": "string",
                        "example": "https://example.com/presigned-upload-url",
                        "description": "上傳這個檔案的網址"
                      },
                      "method": {
                        "type": "string",
                        "example": "PUT",
                        "description": "上傳這個檔案所用的 HTTP 方法"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "FileResponseV2": {
        "type": "object",
        "properties": {
          "status": {
            "type": "integer",
            "example": 200,
            "description": "回應狀態"
          },
          "data": {
            "$ref": "#/components/schemas/BasicFileResponse"
          }
        }
      },
      "BasicRunTaskV2SrcFileUrl": {
        "title": "以來源檔案網址執行任務",
        "type": "object",
        "required": [
          "src_file_url"
        ],
        "properties": {
          "src_file_url": {
            "type": "string",
            "description": "要執行任務的檔案網址。該網址應可公開存取。",
            "example": "https://example.com/selfie.jpg"
          }
        }
      },
      "BasicRunTaskV2SrcFileId": {
        "title": "以來源檔案 ID 執行任務",
        "type": "object",
        "required": [
          "src_file_id"
        ],
        "properties": {
          "src_file_id": {
            "type": "string",
            "description": "要執行任務的檔案 ID。檔案 ID 來自上傳檔案 API。",
            "example": "pfNK5PuRe0MrwLHcGA3DOmB1ahwfXTbYHjv+KoBIxbE="
          }
        }
      },
      "BasicRunTaskV2": {
        "title": "BasicRunTaskV2",
        "anyOf": [
          {
            "$ref": "#/components/schemas/BasicRunTaskV2SrcFileUrl"
          },
          {
            "$ref": "#/components/schemas/BasicRunTaskV2SrcFileId"
          }
        ]
      },
      "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"
              }
            }
          }
        }
      },
      "TaskStatusResponseBodySingleUrlResultsV2": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "description": "下載這個結果的網址。有效期限 2 小時",
            "example": "https://example.com/sample-result-url"
          }
        }
      },
      "TaskStatusResponseV2": {
        "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": {
                "$ref": "#/components/schemas/TaskStatusResponseBodySingleUrlResultsV2"
              }
            }
          }
        }
      }
    },
    "responses": {
      "InvalidParameters": {
        "description": "請求參數無效",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "integer",
                  "example": 400,
                  "description": "回應狀態"
                },
                "error": {
                  "type": "string",
                  "description": "錯誤訊息",
                  "example": "The operation could not be completed"
                },
                "error_code": {
                  "type": "string",
                  "enum": [
                    "InvalidParameters"
                  ]
                }
              }
            }
          }
        }
      },
      "InvalidApiKey": {
        "description": "API Key 無效、已停用或已到期",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "integer",
                  "example": 401,
                  "description": "回應狀態"
                },
                "error_code": {
                  "type": "string",
                  "enum": [
                    "InvalidApiKey",
                    "InactiveApiKey",
                    "ExpiredApiKey"
                  ]
                }
              }
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "在指定時間內請求過多"
      },
      "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": [
              "CreditInsufficiency",
              "InvalidStyleGroup",
              "InvalidStyle",
              "BadRequest",
              "InvalidParameters"
            ]
          }
        }
      },
      "TaskTimeout": {
        "description": "任務在預期時間內沒有回應",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "integer",
                  "description": "回應狀態",
                  "example": 500
                },
                "error_code": {
                  "type": "string",
                  "enum": [
                    "TaskTimeout"
                  ]
                }
              }
            }
          }
        }
      },
      "InvalidTaskId": {
        "description": "任務 id 無效",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "integer",
                  "description": "回應狀態",
                  "example": 400
                },
                "error_code": {
                  "type": "string",
                  "enum": [
                    "InvalidTaskId"
                  ]
                }
              }
            }
          }
        }
      }
    }
  }
}