{
  "openapi": "3.0.0",
  "info": {
    "title": "AI 音樂生成",
    "description": "# 概述 (Overview)\n主題、歌詞和／或音樂風格，任給一樣就能完成一首歌。每個 AI 音樂生成任務會作曲一首成品歌曲（mp3），並一併回傳封面圖、歌名、定稿歌詞與歌詞同步時間軸。\n\n* 有聲樂、純音樂皆可：生成帶人聲的歌曲，或無人聲、無歌詞的純音樂（`instrumental: true`）。\n* 手上有什麼就從什麼開始：主題（`idea`）、自己的歌詞（`lyrics`），或兩者都給。純音樂歌曲必須給 `idea`。\n* 歌詞語言：在 `idea` 文字裡直接要求（例如 \"with Japanese lyrics\"）。支援的歌詞語言：英文、日文、韓文、葡文、西班牙文、德文、法文、義文、繁體中文、簡體中文、印地文、土耳其文。\n\n使用示例：\n\n![](https://plugins-media.makeupar.com/smb/blog/post/2026-10-15/webp_b29b16b3-6f1f-4f94-b0f3-ef7955d1b3e0.webp)\n\n![](https://plugins-media.makeupar.com/smb/blog/post/2026-09-24/webp_90715cdb-e955-4501-9290-0869981b3f43.webp)\n\n---\n\n## 整合指南 (Integration Guide)\n\n* AI 音樂生成使用指南\n\n本指南說明如何執行 AI 音樂生成任務並解讀結果。\n\n不需要上傳圖像或音訊，所以不必用 File API：跑任務前沒有「建立新檔案」這一步。輸入您的 `idea` 或 `lyrics`，選好 `music_style`，就能創造出令人驚豔的歌曲。\n\n***\n\n   * 步驟 1. 建立任務\n\n用 **AI 任務 API**（`/s2s/v2.0/task/ai-song`），傳入主題、歌詞和／或音樂風格：\n\n```bash\ncurl --request POST \\\n  --url https://yce-api-01.makeupar.com/s2s/v2.0/task/ai-song \\\n  --header 'Authorization: Bearer YOUR_API_KEY' \\\n  --header 'content-type: application/json' \\\n  --data '{\"idea\":\"A song about a small cafe that stays open late for people who cannot sleep\",\"music_style\":{\"genre\":\"Acoustic Pop\",\"mood\":\"Calm, hopeful\",\"vocal\":\"female\",\"description\":\"soft piano, brushed drums\"},\"instrumental\":false}'\n```\n\n回應會返回這個任務的 `task_id`：\n\n```json\n{\n  \"status\": 200,\n  \"data\": {\n    \"task_id\": \"grH0CvsgXuAIHLUzD0V1Ol34hoet3R1tvdbtiVHrDb6_UqCLKIejAIajwxrhOAfe\"\n  }\n}\n```\n\n***\n\n   * 步驟 2. 輪詢任務結果\n\n用建立任務回應裡的 `task_id` 查詢狀態，直到 `task_status` 變成 `success` 或 `error`：\n\n```bash\ncurl --request GET \\\n  --url https://yce-api-01.makeupar.com/s2s/v2.0/task/ai-song/YOUR_TASK_ID \\\n  --header 'Authorization: Bearer YOUR_API_KEY' \\\n  --header 'content-type: application/json'\n```\n\n***\n\n   * 步驟 3. 取得結果\n\n成功的回應會包含歌曲，以及封面圖、標題、定稿歌詞與歌詞同步時間戳：\n\n```json\n{\n  \"status\": 200,\n  \"data\": {\n    \"error\": null,\n    \"results\": {\n      \"url\": \"https://example.com/sample-song-url\",\n      \"cover_urls\": [\n        \"https://example.com/sample-cover-url\"\n      ],\n      \"title\": \"Leave the Light On\",\n      \"lyrics\": \"[verse]\\nTwo a.m., the neon hums\\nSteam on the glass, the night still runs\",\n      \"duration\": 154.3,\n      \"timestamps\": \"{\\\"lyrics_lrc_timestamps\\\": \\\"[00:23.98]Two a.m., the neon hums\\\"}\"\n    },\n    \"task_status\": \"success\"\n  }\n}\n```\n\n---\n\n## 輸入與輸出 (Inputs & Outputs)\n\n* 請求主體\n\n| 欄位 | 型別 | 說明 |\n|---|---|---|\n| idea | string（最多 500 字元） | 歌曲主題。`instrumental` 為 `true` 時必填。有人聲的歌曲請提供 `idea`、`lyrics` 或兩者。 |\n| lyrics | string（最多 3000 字元） | 歌曲歌詞。支援 `[intro]`、`[verse]`、`[chorus]`、`[outro]` 等段落標籤。 |\n| music_style | object | 歌曲音樂風格：`genre`（最多 100）、`mood`（最多 100）、`vocal`（`female` 或 `male`，純音樂時忽略），以及放樂器、節奏等其他細節的 `description`（最多 300）。全部欄位皆可選。 |\n| instrumental | boolean | `true` 表示生成無人聲、無歌詞的純音樂。預設 `false`。 |\n\n每個請求必須以以下其中一種方式描述歌曲：從主題出發（`idea` 不為空），或從有人聲歌曲的歌詞出發（`lyrics` 不為空且 `instrumental` 不是 `true`）。\n\n* 結果（`data.results`）\n\n| 欄位 | 型別 | 說明 |\n|---|---|---|\n| url | string | 下載生成歌曲（mp3）的 URL。有效 2 小時 |\n| cover_urls | string 陣列 | 下載封面圖（jpg）的 URL。目前為一張。有效 2 小時 |\n| title | string | 生成出來的歌曲標題 |\n| lyrics | string | 歌曲定稿歌詞。純音樂時為空 |\n| duration | number | 歌曲長度（秒） |\n| timestamps | string | 一個物件 JSON 編碼後的字串，其中 `lyrics_lrc_timestamps` 欄位放 LRC 格式的歌詞同步內容，例如 `[00:08.54]Lyrics text`。純音樂時 LRC 內容為空 |\n\n---\n\n## 檔案規格與錯誤 (File Specs & Errors)\n\n* 支援上限\n\n| 類型 | 上限 |\n|---|---|\n| idea（主題） | 最多 500 字元。`instrumental` 為 `true` 時必填 |\n| lyrics | 最多 3000 字元。支援 `[intro]`、`[verse]`、`[chorus]`、`[outro]` 等段落標籤 |\n| music_style `genre` / `mood` | 各自最多 100 字元 |\n| music_style `description` | 最多 300 字元 |\n| 輸入檔案 | 無。不需要圖像或音訊輸入，因此不必走 File API 步驟 |\n| 輸出 | 歌曲：mp3。封面圖：jpg。結果 URL 有效 2 小時 |\n\n* 錯誤碼\n\n| 錯誤碼 | 說明 |\n|---|---|\n| invalid_parameter | 參數值無效，例如 `idea` 與 `lyrics` 都沒給、純音樂任務少了 `idea`、或欄位超過長度上限 |\n\n    > 任務層級的失敗會在狀態回應中呈現：`data.error` 是錯誤碼，`data.error_message` 是錯誤的詳細說明。\n\n---\n\n## 點數消耗 (Unit Consumption)\n\n依歌曲類型計價。\n\n| 歌曲類型 | 消耗點數 |\n|---|---|\n| 有人聲的歌曲（`instrumental: false`） | 每首 10 點 |\n| 純音樂（`instrumental: true`） | 每首 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"
    }
  ],
  "tags": [
    {
      "name": "V1.0",
      "description": "AI 音樂生成 API 把主題、歌詞和／或音樂風格變成一首完整的歌。每個任務回傳一首成品歌曲（mp3），附封面圖、標題、歌詞與歌詞同步時間戳。"
    }
  ],
  "paths": {
    "/s2s/v2.0/task/ai-song": {
      "post": {
        "summary": "執行 AI 音樂生成任務。",
        "description": "AI 任務是非同步的。當功能支援 webhook 時，請優先使用以 webhook 為基礎的完成處理。設定您的 webhook 端點、驗證 webhook 簽章，並在收到 `success` 或 `error` 通知後，使用收到的 `task_id` 查詢任務結果。設定與驗證細節請見 [webhook 整合指南](/develop/webhook.md)。\n\n若您的整合不支援 webhook 或無法使用 webhook，請實作輪詢。送出 AI 任務後，以固定間隔（例如每 10 秒）輪詢狀態端點，直到任務狀態為 `success` 或 `error`。\n",
        "tags": [
          "V1.0"
        ],
        "security": [
          {
            "BearerAuthenticationV2": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "idea": {
                    "type": "string",
                    "maxLength": 500,
                    "default": "",
                    "description": "歌曲主題。instrumental 為 true 時必填。有人聲的歌曲請提供 idea、lyrics 或兩者。 想要特定語言的歌詞，就在這裡提出（例如 \"with Japanese lyrics\"）。",
                    "example": "A song about a small café that stays open late for people who can't sleep"
                  },
                  "lyrics": {
                    "type": "string",
                    "maxLength": 3000,
                    "default": "",
                    "description": "歌曲歌詞。支援 [intro]、[verse]、[chorus]、[outro] 等段落標籤。支援的歌詞語言： 英文、日文、韓文、葡文、西班牙文、德文、法文、義文、繁體中文、簡體中文、印地文、土耳其文。",
                    "example": "[verse]\nTwo a.m., the neon hums\nSteam on the glass, the night still runs\n\n[chorus]\nLeave the light on, leave the light on\nFor the ones who don't go home"
                  },
                  "music_style": {
                    "type": "object",
                    "description": "歌曲的音樂風格。所有欄位皆可選。",
                    "properties": {
                      "genre": {
                        "type": "string",
                        "maxLength": 100,
                        "description": "歌曲曲風，例如 Pop、Lo-fi Hip Hop",
                        "example": "Acoustic Pop"
                      },
                      "mood": {
                        "type": "string",
                        "maxLength": 100,
                        "description": "歌曲情緒，例如 Calm、Uplifting",
                        "example": "Calm, hopeful"
                      },
                      "vocal": {
                        "type": "string",
                        "enum": [
                          "female",
                          "male"
                        ],
                        "description": "人聲類型。instrumental 為 true 時忽略。",
                        "example": "female"
                      },
                      "description": {
                        "type": "string",
                        "maxLength": 300,
                        "description": "其他細節，例如樂器或節奏。",
                        "example": "soft piano, brushed drums"
                      }
                    }
                  },
                  "instrumental": {
                    "type": "boolean",
                    "default": false,
                    "description": "設為 true 生成無人聲、無歌詞的純音樂。",
                    "example": false
                  }
                },
                "anyOf": [
                  {
                    "title": "從主題生成歌曲",
                    "required": [
                      "idea"
                    ],
                    "properties": {
                      "idea": {
                        "minLength": 1
                      }
                    }
                  },
                  {
                    "title": "從歌詞生成有人聲歌曲",
                    "required": [
                      "lyrics"
                    ],
                    "properties": {
                      "lyrics": {
                        "minLength": 1
                      },
                      "instrumental": {
                        "enum": [
                          false
                        ]
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "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/ai-song/{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": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/TaskStatusResponseV2"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "results": {
                              "type": "object",
                              "properties": {
                                "cover_urls": {
                                  "type": "array",
                                  "description": "下載封面圖（jpg）的 URL。目前為一張。有效 2 小時",
                                  "items": {
                                    "type": "string",
                                    "example": "https://example.com/sample-cover-url"
                                  }
                                },
                                "title": {
                                  "type": "string",
                                  "description": "生成出來的歌曲標題",
                                  "example": "Leave the Light On"
                                },
                                "lyrics": {
                                  "type": "string",
                                  "description": "歌曲定稿歌詞。純音樂時為空"
                                },
                                "duration": {
                                  "type": "number",
                                  "description": "歌曲長度（秒）",
                                  "example": 154.3
                                },
                                "timestamps": {
                                  "type": "string",
                                  "description": "一個物件 JSON 編碼後的字串，其中 lyrics_lrc_timestamps 欄位放 LRC 格式的同步歌詞，例如 [00:08.54]Lyrics text。純音樂時 LRC 內容為空",
                                  "example": "{\"lyrics_lrc_timestamps\": \"[00:23.98]Two a.m., the neon hums\\n[00:28.26]Steam on the glass, the night still runs\"}"
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "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": {
      "BasicRunTaskResponseV2": {
        "type": "object",
        "properties": {
          "status": {
            "type": "integer",
            "description": "回應狀態",
            "example": 200
          },
          "data": {
            "type": "object",
            "properties": {
              "task_id": {
                "type": "string",
                "description": "這個任務的 ID。任務結果可以此 ID 查詢，有效期限 30 天。",
                "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\\` - 其他"
      },
      "TaskStatusResponseBodySingleUrlResultsV2": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "description": "下載這個結果的網址。有效期限 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": null
            }
          }
        },
        "$ref": "#/components/schemas/TaskStatusResponseBodySingleUrlResultsV2"
      }
    },
    "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"
                }
              }
            }
          }
        }
      }
    }
  }
}