{
  "openapi": "3.0.0",
  "info": {
    "title": "AI 頭髮密度分析",
    "description": "# 概述\nAI 頭髮密度分析提供快速、專業、以照片為基礎的評估，透過評估頭皮可見度與頭髮分布模式，將髮量密度精準分為四個等級，提供源自毛髮鏡的洞察而無需實體工具，並賦能企業僅從單張上傳的圖片，大規模提供專家級的個人化服務。\n\n![](https://bcw-media.s3.ap-northeast-1.amazonaws.com/strapi/assets/AI_hair_density_S3_02_b34f2db2ce.jpg)\n\n## 整合指南\n* 如何為 AI 頭髮密度分析拍攝照片\n* 自拍\n  - 請在適當光線下正對鏡頭，然後將頭低下至 45 度角。保持頭髮未綁起，並確保您的整條髮際線清晰可見。\n\n  ![](https://d3ss46vukfdtpo.cloudfront.net/static/media/img_popup_step_animated_02.aadf7a34.png)\n\n  - 或者，使用 JS Camera Kit 拍照。\n\n* 如何用 AI 偵測髮量密度\n* 使用 ***/s2s/v2.0/file*** API，請上傳以下資產：\n  - 您的自拍照片。\n\n* 執行 AI 任務 ***/s2s/v2.0/task/hair-density-detection*** </br>\n傳送一張正面、低頭 45 度的自拍圖片來執行偵測任務。使用其檔案 ID 作為 AI 的來源輸入。\n\n* 輪詢以查詢任務狀態直到成功或錯誤</br>\n這個 ***task_id*** 用於透過輪詢 GET 'task/hair-density-detection' 監控任務狀態，以取得目前的引擎狀態。在引擎完成任務之前，狀態會維持為 'running'，此階段不會消耗點數。\n\n\n## 髮量密度分級\n\n|縮略圖|髮量密度分級|說明|\n| ----  | ----  | ----  |\n|![](https://d3ss46vukfdtpo.cloudfront.net/static/media/dt_classification_LV01.5097a6c2.png)|等級 1<br>極低密度|頭髮明顯稀疏，大面積可見頭皮。髮絲細薄且覆蓋極少。|\n|![](https://d3ss46vukfdtpo.cloudfront.net/static/media/dt_classification_LV02.7966983d.png)|等級 2<br>低密度|明顯稀疏，頭皮清晰可見，尤其是頭頂與分線處。頭髮可能缺乏蓬度與支撐感。|\n|![](https://d3ss46vukfdtpo.cloudfront.net/static/media/dt_classification_LV03.c49dbfb7.png)|等級 3<br>中等密度|在直射光下頭皮部分可見，但頭髮仍維持適度的蓬度與覆蓋。頭髮可能感覺較細，但相對健康。|\n|![](https://d3ss46vukfdtpo.cloudfront.net/static/media/dt_classification_LV04.e467f2aa.png)|等級 4<br>高密度|頭髮看起來豐厚濃密，頭皮幾乎不可見。髮絲緊密排列，提供豐盈的蓬度與自然的覆蓋。|\n\n\n* 拍攝建議\n\n![拍攝建議](https://bcw-media.s3.ap-northeast-1.amazonaws.com/strapi/assets/icon_S2_step1_20d0a161da.png \"拍攝建議\")\n\n![](https://bcw-media.s3.ap-northeast-1.amazonaws.com/strapi/assets/AI_hair_density_S1_02_f60369b14d.jpg)\n\n## 檔案規格與錯誤\n* 支援的格式與尺寸\n\n|類型|支援的尺寸|支援的檔案大小|支援的格式|\n|  ----  | ----  | ----  | ----  |\n|AI 頭髮密度分析|圖片寬與高至少 100 像素，任一維度不超過 4096 像素。若您的圖片其中一邊超過 1080 像素，會自動調整尺寸以符合該限制進行分析。|< 10MB|jpg/png|\n\n* 錯誤代碼\n\n|錯誤代碼|說明|\n|  ----  | ----  |\n|error_below_min_image_size|若您的圖片寬度或高度小於 100 像素，則太小無法使用|\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（現代 TLS/HTTP 支援）</br>   - jq >= 1.6（穩健的 JSON 解析） |\n| Node.js（JavaScript） | Node >= 18（支援全域 fetch） |\n| JavaScript | - Chrome / Edge >= 80</br>   - Firefox >= 74</br>   - Safari >= 13.1 |\n| PHP | PHP >= 7.4（現代 TLS/相容性），ext-curl（建議）或 allow_url_fopen=On + ext-openssl、ext-json |\n| Python | Python >= 3.10（支援 f-strings），requests >= 2.20.0 |\n| Java | Java 11+（支援 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 | 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/hair-density-detection": {
      "post": {
        "summary": "執行 AI 頭髮密度分析任務。",
        "description": "必須輪詢以檢查任務狀態。細節請參考輪詢指南。",
        "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/hair-density-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": "成功查詢 AI 頭髮密度分析任務的狀態。",
            "content": {
              "application/json": {
                "schema": {
                  "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": {
                                "timed": {
                                  "type": "number"
                                },
                                "hair_density": {
                                  "$ref": "#/components/schemas/BasicHairDensityRespHairDensity"
                                }
                              }
                            }
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/InvalidTaskId"
          },
          "401": {
            "$ref": "#/components/responses/InvalidApiKey"
          },
          "500": {
            "$ref": "#/components/responses/TaskTimeout"
          }
        }
      }
    }
  },
  "components": {
    "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- `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` - 其他\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"
          }
        }
      },
      "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"
              }
            }
          }
        }
      },
      "BasicRunTaskV2SrcFileId": {
        "title": "以來源檔案 ID 執行任務",
        "type": "object",
        "required": [
          "src_file_id"
        ],
        "properties": {
          "src_file_id": {
            "type": "string",
            "description": "要執行任務的檔案 ID。檔案 ID 來自上傳檔案 API。",
            "example": "pfNK5PuRe0MrwLHcGA3DOmB1ahwfXTbYHjv+KoBIxbE="
          }
        }
      },
      "BasicRunTaskV2SrcFileUrl": {
        "title": "以來源檔案網址執行任務",
        "type": "object",
        "required": [
          "src_file_url"
        ],
        "properties": {
          "src_file_url": {
            "type": "string",
            "description": "要執行任務的檔案網址。該網址應可公開存取。",
            "example": "https://example.com/selfie.jpg"
          }
        }
      },
      "BasicRunTaskV2": {
        "title": "BasicRunTaskV2",
        "anyOf": [
          {
            "$ref": "#/components/schemas/BasicRunTaskV2SrcFileUrl"
          },
          {
            "$ref": "#/components/schemas/BasicRunTaskV2SrcFileId"
          }
        ]
      },
      "BasicHairDensityRespHairDensity": {
        "type": "object",
        "properties": {
          "mapping": {
            "type": "string",
            "description": "以字串格式表示的浮點數",
            "minimum": "0",
            "maximum": "3",
            "example": "2.16"
          },
          "term": {
            "type": "string",
            "enum": [
              "Extremely Low Density",
              "Low Density",
              "Medium Density",
              "High Density"
            ]
          }
        }
      }
    },
    "responses": {
      "BadRequestAndInvalidParameters": {
        "description": "因客戶端錯誤或請求參數無效，無法處理請求",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "integer",
                  "description": "回應狀態"
                },
                "error": {
                  "type": "string",
                  "description": "錯誤訊息",
                  "example": "The operation could not be completed"
                },
                "error_code": {
                  "type": "string",
                  "enum": [
                    "BadRequest",
                    "InvalidParameters"
                  ],
                  "description": "錯誤代碼：\n  * BadRequest - 請求參數或內容不如預期\n  * InvalidParameters - 請求參數或內容無效\n"
                }
              }
            }
          }
        }
      },
      "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"
                  ],
                  "description": "錯誤代碼：\n  * InvalidApiKey - 未提供 API Key，或 API Key 無效\n  * InactiveApiKey - API Key 已停用\n  * ExpiredApiKey - API Key 已到期\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 authentication'。請在標頭中放入您的 'API Key'：`Authorization:Bearer YOUR_API_KEY`。請注意 'Bearer' 與 'YOUR_API_KEY' 之間有一個空格。"
      }
    }
  }
}