{
  "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 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  上傳完成後，AI 將使用您的檔案 ID 檢查您嘴唇、眼睛、眉毛、皮膚與頭髮的色調。請參考**[輸入與輸出](#section/overview/Inputs-and-Outputs)**。</br>\n  接著，使用\n  檔案 ID 執行增強任務，並取得 ***task_id***。\n\n4. **輪詢以查詢任務狀態直到成功或錯誤**</BR>\n這個 ***task_id*** 用於透過輪詢 GET 'task/skin-tone-analysis' 監控任務狀態，以取得目前的引擎狀態。在引擎完成任務之前，狀態會維持為 'running'，此階段不會消耗點數。\n\n    **警告：** 請注意，依據任務的保留期間**輪詢**以查詢任務狀態是強制性的。若在保留期間內沒有輪詢請求，任務將被逾時，即使任務已成功處理（您的點數仍會被消耗）。\n\n    > **警告：** 一旦您查詢已逾時任務的狀態，會得到 ***InvalidTaskId*** 錯誤。因此，執行 AI 任務後，您需要在保留期間內**輪詢**以查詢狀態，直到狀態變為 *success* 或 *error*。\n\n5. **成功後取得 AI 任務的結果**</BR>\n引擎成功處理您的輸入檔案並生成結果影像後，任務會變為 'success' 狀態。您會取得處理後影像的網址，以及一個 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` 來控制輸入臉部角度的檢查嚴格程度，範圍從 strict、high、medium、low 到 flexible。嚴格程度適用於臉部角度偵測，包括 pitch、yaw 與 roll。較嚴格的等級可確保更準確的臉部特徵結果。預設設定為 high。\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` | 琥珀色、棕色、綠色、藍色、灰色、其他 |\n| `lip_color` | 十六進位值 |\n| `eyebrow_color` | 十六進位值 |\n| `hair_color` | 十六進位值 |\n| `color.hair_color_name` | 紅棕色、黑色、金色、棕色、灰白、紅色 |\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，僅限單人。邊長超過 1080px 的圖片會自動調整尺寸以進行分析。 | < 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（現代 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 | 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": "執行膚色分析任務。",
        "description": "這個端點啟動膚色分析流程。您必須提供來源檔案（透過網址或檔案 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": "查詢膚色分析任務的狀態。",
        "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 authentication'。請在標頭中放入您的 'API Key'：`Authorization:Bearer YOUR_API_KEY`。請注意 'Bearer' 與 'YOUR_API_KEY' 之間有一個空格。"
      }
    },
    "schemas": {
      "RunSkinToneAnalysisTaskV2": {
        "title": "執行膚色分析任務 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": "眼色的 hex 值",
            "example": "#293F9B"
          },
          "eye_color_name": {
            "type": "string",
            "enum": [
              "Amber",
              "Brown",
              "Green",
              "Blue",
              "Gray",
              "Other"
            ],
            "example": "Blue"
          },
          "lip_color": {
            "type": "string",
            "description": "唇色的 hex 值",
            "example": "#D23245"
          },
          "eyebrow_color": {
            "type": "string",
            "description": "眉色的 hex 值",
            "example": "#5B2B31"
          },
          "skin_color": {
            "type": "string",
            "pattern": "^#([A-Fa-f0-9]{6})$",
            "description": "Hex 色碼",
            "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": "要執行任務的檔案網址。該網址應可公開存取。",
            "example": "https://example.com/selfie.jpg"
          }
        }
      },
      "BasicRunTaskV2SrcFileId": {
        "type": "object",
        "required": [
          "src_file_id"
        ],
        "properties": {
          "src_file_id": {
            "type": "string",
            "description": "要執行任務的檔案 ID。檔案 ID 來自上傳檔案 API。",
            "example": "pfNK5PuRe0MrwLHcGA3DOmB1ahwfXTbYHjv+KoBIxbE="
          }
        }
      },
      "BasicRunTaskV2": {
        "title": "BasicRunTaskV2",
        "anyOf": [
          {
            "title": "Run task with src file url",
            "allOf": [
              {
                "$ref": "#/components/schemas/BasicRunTaskV2SrcFileUrl"
              }
            ]
          },
          {
            "title": "Run task with src file 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\\` - 超過重試上限以避免產生 NSFW 圖片\n- \\`error_upload\\` - 上傳結果圖片錯誤\n- \\`unknown_internal_error\\` - 其他"
      }
    },
    "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"
                }
              }
            }
          }
        }
      }
    }
  }
}