{
  "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 接口上传文件**</br>\n  通过 ***/s2s/v2.0/file*** 接口上传目标用户图片。\n    - 图片要求\n      - 详见 **[文件规格与错误码](#section/overview/File-Specs-and-Errors)**。\n    - ***重要***：只调用 File 接口并不等于上传了文件。您必须**手动把文件上传到 File 接口响应中给出的那个 URL**，那个 URL 就是您的上传目标，务必确认文件已成功传过去，再继续往下做。<br>\n    调用 AI 接口之前，请确认文件已上传成功。先用 File 接口取到一个上传 URL，把文件上传到该位置。上传完成后，您会在响应中收到一个 ***file_id***，调用与该文件相关的 AI 功能时就用它。\n    \n      > **警告：** 请注意，若未把文件上传到 File 接口响应中给出的 URL，调用 AI 接口时会得到 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. **任务成功后取回结果**</BR>\n引擎成功处理您的输入文件、生成出图后，任务状态会变为 'success'。您会得到处理后图片的 URL 以及一个 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   * `Foreground image`\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|为避免生成不适宜内容，重试次数已达上限|\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": "本接口用于发起抠图流程。您需要提供上传文件接口返回的文件 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 鉴权。把您的 API 密钥放进请求头： `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重试次数已用尽\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 类型。当前支持的取值见上方的枚举。"
                },
                "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。其他运行任务的接口需要用到这个 `file_id`。"
                },
                "requests": {
                  "type": "array",
                  "description": "请用下面的 `url`、`headers`、`method` 上传文件。 上传完成后，用 `file_id` 继续调用运行任务接口。",
                  "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": "上传该文件的 URL"
                      },
                      "method": {
                        "type": "string",
                        "example": "PUT",
                        "description": "上传该文件所用的 HTTP 方法"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "FileResponseV2": {
        "type": "object",
        "properties": {
          "status": {
            "type": "integer",
            "example": 200,
            "description": "响应状态"
          },
          "data": {
            "$ref": "#/components/schemas/BasicFileResponse"
          }
        }
      },
      "BasicRunTaskV2SrcFileUrl": {
        "title": "用源文件 URL 运行任务",
        "type": "object",
        "required": [
          "src_file_url"
        ],
        "properties": {
          "src_file_url": {
            "type": "string",
            "description": "用于运行任务的文件 URL，该 URL 需可公开访问。",
            "example": "https://example.com/selfie.jpg"
          }
        }
      },
      "BasicRunTaskV2SrcFileId": {
        "title": "用源文件 ID 运行任务",
        "type": "object",
        "required": [
          "src_file_id"
        ],
        "properties": {
          "src_file_id": {
            "type": "string",
            "description": "用于运行任务的文件 ID，取自上传文件接口返回的 file_id。",
            "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": "下载该结果的 URL，有效期 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 密钥无效、已停用或已过期",
        "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"
                  ]
                }
              }
            }
          }
        }
      }
    }
  }
}