{
  "openapi": "3.0.0",
  "info": {
    "title": "AI 面部色调分析器",
    "description": "# 概览\nAI 面部色调分析器可检测脸部肤色，以及眼睛、眉毛、嘴唇和头发的颜色。这套包容性技术能让各种肤色的顾客都有量身定制的购物体验。\n\n![](https://bcw-media.s3.ap-northeast-1.amazonaws.com/img_Face_Ratio_sec_02_02_enu_21a3d8d423.jpg)\n\n![](https://bcw-media.s3.ap-northeast-1.amazonaws.com/shade_finder_s5_poster_2_8a8f9307d2.png)\n\n\n## 接入指南\n* AI 面部色调分析器怎么拍照\n\n  正脸自拍一张\n  - 拍一张清楚的照片即可，正对镜头。头发散下放下来、垂到胸前，视线直视前方，做出正对镜头的角度。\n  - 也可以用 JS Camera Kit 拍照。同样把头发散下放下来、垂到胸前，不要扎起来。\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  上传完成后，AI 会用您的文件 ID 分析嘴唇、眼睛、眉毛、皮肤与头发的色调，详见 **[输入与输出](#section/overview/Inputs-and-Outputs)**。</br>\n  随后用文件 ID 调用 POST 'task/skin-tone-analysis' 执行任务，\n  并取得 ***task_id***。\n\n4. **轮询任务状态，直到成功或报错**</BR>\n用这个 ***task_id*** 轮询 GET 'task/skin-tone-analysis' 监控任务状态，取得引擎当前的处理进度。引擎完成任务之前，状态会一直是 'running'，这一阶段不消耗点数。\n\n    **警告：** 请注意，**轮询**任务状态必须按任务保留期来执行，是强制要求。保留期内没有任何轮询请求，任务就会超时，即使任务已处理成功也一样（您的点数照样会被消耗）。\n\n    > **警告：** 若去查询已超时任务的状态，会收到 ***InvalidTaskId*** 错误。因此，执行 AI 任务之后，必须在保留期内持续**轮询**，直到状态变为 *success* 或 *error*。\n\n5. **任务成功后取回结果**</BR>\n引擎成功处理您的输入文件、生成出图后，任务状态会变为 'success'。您会得到处理后图片的 URL 以及一个 dst_id，可直接串联下一个 AI 任务，不必把结果图重新上传。\n只有这种情况才会消耗点数。若引擎处理失败，任务状态会变为 'error'，不消耗点数。</BR>\n扣除点数时，系统优先扣除临近到期的点数；到期日相同时，优先扣除最早取得的点数。\n\n![](https://plugins-media.makeupar.com/smb/blog/post/2022-08-19/2a1af800-7c69-44a5-a94c-70a4a9c4d2b0.jpg)\n\n---\n\n## 输入与输出\n* 输入\nAI 会分析您皮肤的色调。您可以调整 `face_angle_strictness_level`，控制对输入脸部角度的校验严格度，档位从严格、高、中、低到宽松。该严格度作用于脸部角度检测，包括俯仰角、偏航角与翻滚角。档位越严，脸部属性结果越准。默认设置为高。\n\n![](https://bcw-media.s3.ap-northeast-1.amazonaws.com/shade_finder_s4_poster_399f34c6ef.jpg)\n\n* 输出\n```json\n{\n  \"status\": 200,\n  \"data\": {\n    \"task_status\": \"success\",\n    \"results\": {\n      \"color\": {\n        \"eye_color\": \"#293F9B\",\n        \"eye_color_name\": \"Blue\",\n        \"lip_color\": \"#D23245\",\n        \"eyebrow_color\": \"#5B2B31\",\n        \"skin_color\": \"#b9947c\",\n        \"hair_color\": \"#a0a0a0\",\n        \"hair_color_name\": \"Auburn\"\n      }\n    }\n  }\n}\n```\n\n| **结果参数** | **结果类型** |\n|  --- | --- |\n| `skin_color` | 十六进制色值 |\n| `eye_color`| 十六进制色值 |\n| `eye_color_name` | Amber、Brown、Green、Blue、Gray、Other |\n| `lip_color` | 十六进制色值 |\n| `eyebrow_color` | 十六进制色值 |\n| `hair_color` | 十六进制色值 |\n| `color.hair_color_name` | Auburn、Black、Blonde、Brown、Grey/White、Red |\n\n\n* 拍摄建议：\n![](https://bcw-media.s3.ap-northeast-1.amazonaws.com/strapi/assets/webp_AI%20Skin%20Analysis_camera_f93315b088.png)\n\n> **警告：** 脸部宽度需大于图片宽度的 60%。\n\n---\n\n## 文件规格与错误码\n* 支持的格式与尺寸\n\n| AI 功能 | 支持尺寸 | 支持文件大小 | 支持格式 |\n| ---- | ---- | ----  | ---- |\n| AI 面部色调分析器 | 长边 <= 4096，仅支持单人。任一维度超过 1080 像素的图片会自动缩放后进行分析。 | < 10MB | jpg/jpeg/png |\n\n* 错误码\n\n|错误码|说明|\n|  ----  | ----  |\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_face_not_forward_facing | 人脸必须正对镜头。 |\n| error_face_angle_upward | 脸部过度朝上——请把头略微低一点。 |\n| error_face_angle_downward | 脸部过度朝下——请把头略微抬一点。 |\n| error_face_angle_leftward | 脸部过度朝左——请把头略微向右转。 |\n| error_face_angle_rightward | 脸部过度朝右——请把头略微向左转。 |\n| error_face_angle_left_tilt | 脸部向左侧倾斜过多——请把头轻轻向右扶正。 |\n| error_face_angle_right_tilt | 脸部向右侧倾斜过多——请把头轻轻向左扶正。 |\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 | 20 |\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"
    }
  ],
  "paths": {
    "/s2s/v2.0/task/skin-tone-analysis": {
      "post": {
        "summary": "执行 AI 面部色调分析器 任务。",
        "description": "本接口用于发起 AI 面部色调分析器流程。您需要提供源文件（URL 或文件 ID），并可选指定脸部角度的严格程度。任务会异步处理，您可以使用本响应返回的 task_id 查询其状态。\n",
        "tags": [
          "V1.0"
        ],
        "security": [
          {
            "BearerAuthenticationV2": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RunSkinToneAnalysisTaskV2"
              }
            }
          }
        },
        "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/skin-tone-analysis/{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/SkinToneAnalysisTaskStatusResponseV2"
                }
              }
            }
          },
          "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": {
      "RunSkinToneAnalysisTaskV2": {
        "title": "Run Skin Tone Analysis Task V2",
        "allOf": [
          {
            "$ref": "#/components/schemas/BasicRunTaskV2"
          },
          {
            "type": "object",
            "properties": {
              "face_angle_strictness_level": {
                "$ref": "#/components/schemas/BasicFaceAttrReqFaceAngleStrictnessLevel"
              }
            }
          }
        ]
      },
      "BasicFaceAttrReqFaceAngleStrictnessLevel": {
        "type": "string",
        "description": "脸部角度检测的严格程度（俯仰角 pitch、偏航角 yaw、翻滚角 roll）。\n要求越严格，五官分析结果越准确。\n默认为 'high'。\n可选值：\n  - strict：pitch <= 4 度，yaw <= 6 度，roll <= 4 度\n  - high：pitch、yaw、roll <= 10 度\n  - medium：pitch、yaw、roll <= 15 度\n  - low：pitch、yaw、roll <= 20 度\n  - flexible：pitch、yaw、roll <= 30 度\n",
        "enum": [
          "strict",
          "high",
          "medium",
          "low",
          "flexible"
        ],
        "example": "high"
      },
      "BasicFaceAttrRespFaceQuality": {
        "type": "object",
        "properties": {
          "has_face": {
            "type": "boolean",
            "example": true
          },
          "area": {
            "type": "string",
            "example": "good"
          },
          "frontal": {
            "type": "string",
            "example": "good"
          },
          "lighting": {
            "type": "string",
            "example": "good"
          },
          "faceangle": {
            "type": "string",
            "example": "good"
          }
        }
      },
      "BasicFaceAttrRespColor": {
        "type": "object",
        "properties": {
          "eye_color": {
            "type": "string",
            "description": "瞳色的十六进制值",
            "example": "#293F9B"
          },
          "eye_color_name": {
            "type": "string",
            "enum": [
              "Amber",
              "Brown",
              "Green",
              "Blue",
              "Gray",
              "Other"
            ],
            "example": "Blue"
          },
          "lip_color": {
            "type": "string",
            "description": "唇色的十六进制值",
            "example": "#D23245"
          },
          "eyebrow_color": {
            "type": "string",
            "description": "眉色的十六进制值",
            "example": "#5B2B31"
          },
          "skin_color": {
            "type": "string",
            "pattern": "^#([A-Fa-f0-9]{6})$",
            "description": "十六进制色值",
            "example": "#b9947c"
          },
          "hair_color": {
            "type": "string",
            "format": "color",
            "enum": [
              "#a0a0a0",
              "#722626",
              "#000000",
              "#FAF0BE",
              "#42280E",
              "#808080",
              "#B56637"
            ]
          },
          "hair_color_name": {
            "type": "string",
            "enum": [
              "Auburn",
              "Black",
              "Blonde",
              "Brown",
              "Grey/White",
              "Red"
            ]
          }
        }
      },
      "SkinToneAnalysisTaskStatusResponseV2": {
        "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": {
                      "face_quality": {
                        "$ref": "#/components/schemas/BasicFaceAttrRespFaceQuality"
                      },
                      "color": {
                        "$ref": "#/components/schemas/BasicFaceAttrRespColor"
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      },
      "BasicRunTaskV2SrcFileUrl": {
        "type": "object",
        "required": [
          "src_file_url"
        ],
        "properties": {
          "src_file_url": {
            "type": "string",
            "description": "用于运行任务的文件 URL，该 URL 需可公开访问。",
            "example": "https://example.com/selfie.jpg"
          }
        }
      },
      "BasicRunTaskV2SrcFileId": {
        "type": "object",
        "required": [
          "src_file_id"
        ],
        "properties": {
          "src_file_id": {
            "type": "string",
            "description": "用于运行任务的文件 ID，取自上传文件接口返回的 file_id。",
            "example": "pfNK5PuRe0MrwLHcGA3DOmB1ahwfXTbYHjv+KoBIxbE="
          }
        }
      },
      "BasicRunTaskV2": {
        "title": "BasicRunTaskV2",
        "anyOf": [
          {
            "title": "用源文件 URL 运行任务",
            "allOf": [
              {
                "$ref": "#/components/schemas/BasicRunTaskV2SrcFileUrl"
              }
            ]
          },
          {
            "title": "用源文件 ID 运行任务",
            "allOf": [
              {
                "$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"
              }
            }
          }
        }
      },
      "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\\` - 为避免生成不适宜内容， 重试次数已用尽\n- \\`error_upload\\` - 上传结果图片出错\n- \\`unknown_internal_error\\` - 其他错误\n"
      }
    },
    "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"
                }
              }
            }
          }
        }
      }
    }
  }
}