{
  "openapi": "3.0.0",
  "info": {
    "title": "AI 发型毛躁度检测",
    "description": "# 概览\n三张照片，180° 全景看头发毛躁\n\nAI 毛躁分析只需上传三张照片——头发的正面、左侧、右侧视角——几秒钟就能给出精准的毛躁程度分析。\n\n这套流程效率很高，几秒钟就出结果，商家可依据头发毛躁等级提供针对性护发方案与抗毛躁产品，不必花时间去线下咨询，不用做复杂的头发问卷，也不需要装专业设备。\n![](https://bcw-media.s3.ap-northeast-1.amazonaws.com/hair_frizzy_S_02_enu_b80c238858.jpg)\n\n## 接入指南\n\n1. **上传自拍**\n  源图有两种提供方式：\n\n  - **使用已有的公开图片 URL**\n    不必上传，发起 AI 任务时直接给一个可公开访问的图片 URL 即可。\n\n  - **通过 File 接口上传**\n    接口地址：\n    ```\n    POST /s2s/v2.0/file\n    ```\n    这会返回一个 `file_id`，供后续执行任务时使用。\n\n    - ***重要***：只调用 File 接口并不等于上传了文件。您必须**手动把文件上传到 File 接口响应中给出的那个 URL**，那个 URL 就是您的上传目标，务必确认文件已成功传过去，再继续往下做。\n\n    调用 AI 接口之前，请确认文件已上传成功。先用 File 接口取到一个上传 URL，把文件上传到该位置。上传完成后，您会在响应中收到一个 ***file_id***，调用与该文件相关的 AI 功能时就用它。\n\n      > **警告：** 请注意，若未把文件上传到 File 接口响应中给出的 URL，调用 AI 接口时会得到 500 Server Error / unknown_internal_error 或 404 Not Found 错误。\n\n2.  **执行 AI 任务并取得 Task ID**\n    用 /s2s/v2.0/task/hair-frizziness-detection 执行 AI 任务。目标用户图请提供 ``src_file_url`` 或 ``src_file_id``，再给出要套用的风格 ``template_id``，即可取得 ``task_id``。\n\n3.  **轮询任务状态，直到成功或失败**\n    用 ``task_id`` 轮询 GET /s2s/v2.0/task/hair-frizziness-detection 监控任务状态，取得引擎当前的处理进度。引擎完成任务之前，状态会一直是 running，这一阶段不消耗点数。\n    您也可以实现 Webhook，在 AI 任务成功或失败时收到通知。细节见 **[Webhook](../../../../develop/webhook)** 一节。\n\n    > **警告：** 在任务保留期内轮询任务状态是必须做的。保留期内没有任何轮询请求，任务就会超时，即使任务已处理成功也一样，而您的点数照样会被消耗。\n\n    > **警告：** 若去查询已超时任务的状态，会收到 InvalidTaskId 错误。因此，执行 AI 任务之后，必须在保留期内持续轮询，直到状态变为 success 或 error。\n\n4.  **任务成功后取回结果**\n    引擎处理完您的输入文件、生成出图后，任务状态会变为 success，您会收到一张处理后图片的 URL。\n\n## 输入与输出\n* 输入格式\n![](https://bcw-media.s3.ap-northeast-1.amazonaws.com/hair_frizzy_step_01_ac5c651ea4.png)\n上传三张照片——头发的正面、左侧、右侧视角。\n您也可以用 JS Camera Kit 实现一个网页相机模块，拍出三张合格的图片。\n\n\n* 输出格式\nAI 毛躁分析会评估发质类型，并识别出四档毛躁程度——从顺滑头发到极度毛躁，把头发毛躁状况讲得明明白白。\n\n| **Mapping（0–3）** | **Term**            | **说明**                                           |\n| ----------------- | ------------------- | --------------------------------------------------------- |\n| 0             | 不毛躁      | 头发看起来顺滑，几乎看不到毛躁。     |\n| 1            | 轻微毛躁 | 可见轻度毛躁；表面质感略有毛糙。 |\n| 2             | 毛躁         | 整体可见毛躁；质感明显紊乱。   |\n| 3             | 极度毛躁  | 毛躁明显且范围大；头发质感高度紊乱。  |\n\n![](https://bcw-media.s3.ap-northeast-1.amazonaws.com/hair_frizzy_S_01_enu_fcd10905ff.jpg)\n\n* 输出示例\n```json\n{\n  \"mapping\": 1, // number; the key to map of result, alternatives: [0, 1, 2, 3]\n  \"term\": \"Slightly Frizzy\" // string; 1-1 map to the \"mapping\", alternatives: [\"Not Frizzy\", \"Slightly Frizzy\", \"Frizzy\", \"Extreme Frizzy\"]\n}\n```\n\n## 文件规格与错误码\n* 支持的格式与尺寸\n\n|类型|支持尺寸|支持文件大小|支持格式|\n|  ----  | ----  | ----  | ----  |\n|AI 发型毛躁度检测|图片宽高至少 320 像素，任一维度不超过 4096 像素。若某一边超过 1080 像素，会自动缩放到该上限以内进行分析。|< 10MB|jpg/png|\n\n* 错误码\n\n|错误码|说明|\n|  ----  | ----  |\n|error_mismatch_image_size|请确保正脸、左侧、右侧三张人脸照片尺寸一致|\n|error_below_min_image_size|图片宽或高小于 320 像素，尺寸过小，无法使用|\n|error_face_position_invalid|脸部需完整可见，不能被裁掉一部分|\n|error_face_position_too_small|照片中的人脸过小，无法准确分析|\n|error_face_position_out_of_boundary|脸部过大，或部分超出照片边缘|\n|error_insufficient_lighting|光线太暗，分析起来很困难|\n|error_face_angle_invalid|脸部角度不太对。正脸拍摄时，头部偏离正向请在 10 度以内；侧脸拍摄时，角度应大于 15 度|\n\n* 运行环境与依赖\n\n| 示例代码语言 / 工具 | 建议运行时版本 |\n|---|---|\n| cURL | - bash >= 3.2</br>   - curl >= 7.58 (modern TLS/HTTP support)</br>   - jq >= 1.6 (robust JSON parsing) |\n| Node.js (JavaScript) | Node >= 18 (for global fetch) |\n| JavaScript | - Chrome / Edge >= 80</br>   - Firefox >= 74</br>   - Safari >= 13.1 |\n| PHP | PHP >= 7.4 (for modern TLS/compat), ext-curl (recommended) or allow_url_fopen=On + ext-openssl, ext-json |\n| Python | Python >= 3.10 (for f-strings), requests >= 2.20.0 |\n| Java | Java 11+ (for HttpClient), Jackson Databind >= 2.12.0 |\n\n---\n\n## JS Camera Kit\n{% partial file=\"/_partials/js-camera-kit.md\" /%}\n\n---\n\n## 点数消耗\n\n| AI 功能 | 消耗点数 |\n|---|---|\n| AI 发型毛躁度检测 V1.0 | 2 |\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/hair-frizziness-detection": {
      "post": {
        "summary": "执行 AI 发型毛躁度检测任务。",
        "description": "查询任务状态的方法，请参见轮询指南。",
        "tags": [
          "V1.0"
        ],
        "security": [
          {
            "BearerAuthenticationV2": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BasicFaceAttrReqFaceThreeAngle"
              }
            }
          }
        },
        "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": {
            "description": "单位时间内请求过多",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/s2s/v2.0/task/hair-frizziness-detection/{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/TaskStatusResponseHairFrizz"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidTaskId"
          },
          "401": {
            "$ref": "#/components/responses/InvalidApiKey"
          },
          "500": {
            "$ref": "#/components/responses/TaskTimeout"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "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"
          }
        }
      },
      "BasicFaceAttrReqFaceThreeAngleWithSrcFileUrls": {
        "title": "用三个角度的源文件 URL 运行任务",
        "type": "object",
        "required": [
          "src_file_urls"
        ],
        "properties": {
          "src_file_urls": {
            "type": "array",
            "minItems": 3,
            "maxItems": 3,
            "description": "取自上传文件接口的文件 URL。源图片按顺序对应的文件标识依次为 'frontFace'、'rightFace'、'leftFace'。请提供 'src_file_urls' 或 'src_file_ids' 二者之一。",
            "example": [
              "https://example.com/selfie.jpg",
              "https://example.com/selfie.jpg",
              "https://example.com/selfie.jpg"
            ],
            "items": {
              "type": "string"
            }
          }
        }
      },
      "BasicFaceAttrReqFaceThreeAngleWithSrcFileIds": {
        "title": "用三个角度的源文件 ID 运行任务",
        "type": "object",
        "required": [
          "src_file_ids"
        ],
        "properties": {
          "src_file_ids": {
            "type": "array",
            "minItems": 3,
            "maxItems": 3,
            "description": "取自上传文件接口的文件 ID。源图片按顺序对应的文件标识依次为 'frontFace'、'rightFace'、'leftFace'。请提供 'src_file_urls' 或 'src_file_ids' 二者之一。",
            "example": [
              "pfNK5PuRe0MrwLHcGA3DOmB1ahwfXTbYHjv+KoBIxbE=",
              "pkVzplMv8Y1QPgHbqtKfyJmg+xJDUbTP16YijZ3qARNf",
              "B5LNohvvO+7d/78Ymuhp6vMiSooN/5DX9oVuupzkKctf"
            ],
            "items": {
              "type": "string"
            }
          }
        }
      },
      "BasicFaceAttrReqFaceThreeAngle": {
        "anyOf": [
          {
            "$ref": "#/components/schemas/BasicFaceAttrReqFaceThreeAngleWithSrcFileUrls"
          },
          {
            "$ref": "#/components/schemas/BasicFaceAttrReqFaceThreeAngleWithSrcFileIds"
          }
        ]
      },
      "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"
              }
            }
          }
        }
      },
      "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- `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` - 为避免生成不适宜内容， 重试次数已用尽\n- `error_upload` - 上传结果图片出错\n- `unknown_internal_error` - 其他错误\n"
      },
      "BasicFaceAttrRespHairFrizziness": {
        "type": "object",
        "properties": {
          "mapping": {
            "type": "number",
            "description": "结果映射的键",
            "enum": [
              0,
              1,
              2,
              3
            ]
          },
          "term": {
            "type": "string",
            "description": "与 \"mapping\" 一一对应",
            "enum": [
              "Not Frizzy",
              "Slightly Frizzy",
              "Frizzy",
              "Extreme Frizzy"
            ]
          }
        }
      },
      "TaskStatusResponseHairFrizz": {
        "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": {
                "allOf": [
                  {
                    "type": "object",
                    "properties": {
                      "hair_frizziness": {
                        "$ref": "#/components/schemas/BasicFaceAttrRespHairFrizziness"
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      }
    },
    "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"
                  ],
                  "description": "错误码：\n  * InvalidParameters - 请求参数或请求体无效\n"
                }
              }
            }
          }
        }
      },
      "InvalidApiKey": {
        "description": "API 密钥无效、已停用或已过期",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "integer",
                  "example": 401,
                  "description": "响应状态"
                },
                "error_code": {
                  "type": "string",
                  "enum": [
                    "InvalidApiKey",
                    "InactiveApiKey",
                    "ExpiredApiKey"
                  ],
                  "description": "错误码：\n  * InvalidApiKey - 未提供 API 密钥，或密钥无效\n  * InactiveApiKey - API 密钥已被停用\n  * ExpiredApiKey - API 密钥已过期\n"
                }
              }
            }
          }
        }
      },
      "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"
            ],
            "description": "错误码：\n  * CreditInsufficiency - 点数不足，无法运行\n  * BadRequest - 请求参数不符合预期\n  * InvalidStyleGroup - 风格分组 ID 无效\n  * InvalidStyle - 风格 ID 无效\n  * InvalidParameters - 请求参数无效\n"
          }
        }
      },
      "InvalidTaskId": {
        "description": "任务 ID 无效",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "integer",
                  "description": "响应状态",
                  "example": 400
                },
                "error_code": {
                  "type": "string",
                  "enum": [
                    "InvalidTaskId"
                  ],
                  "description": "错误码：\n  * InvalidTaskId - 任务 ID 无效\n"
                }
              }
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "单位时间内请求过多"
      },
      "TaskTimeout": {
        "description": "任务在预期时间内没有响应",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "integer",
                  "description": "响应状态",
                  "example": 500
                },
                "error_code": {
                  "type": "string",
                  "enum": [
                    "TaskTimeout"
                  ],
                  "description": "错误码：\n  * TaskTimeout - 任务在预期时间内没有响应\n"
                }
              }
            }
          }
        }
      }
    },
    "securitySchemes": {
      "BearerAuthenticationV2": {
        "type": "http",
        "scheme": "bearer",
        "description": "使用标准的 Bearer 鉴权。把您的 API 密钥放进请求头： `Authorization:Bearer YOUR_API_KEY`。请注意 'Bearer' 与 'YOUR_API_KEY' 之间有一个空格。"
      }
    }
  }
}