# 執行 AI 音樂生成任務。

AI 任務是非同步的。當功能支援 webhook 時，請優先使用以 webhook 為基礎的完成處理。設定您的 webhook 端點、驗證 webhook 簽章，並在收到 `success` 或 `error` 通知後，使用收到的 `task_id` 查詢任務結果。設定與驗證細節請見 [webhook 整合指南](/develop/webhook)。
若您的整合不支援 webhook 或無法使用 webhook，請實作輪詢。送出 AI 任務後，以固定間隔（例如每 10 秒）輪詢狀態端點，直到任務狀態為 `success` 或 `error`。

Endpoint: POST /s2s/v2.0/task/ai-song
Security: BearerAuthenticationV2

## Security:

  - `BearerAuthenticationV2` (unknown)
    http bearer

## Request fields (application/json):

  - `idea` (string)
    歌曲主題。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` (string)
    歌曲歌詞。支援 [intro]、[verse]、[chorus]、[outro] 等段落標籤。支援的歌詞語言： 英文、日文、韓文、葡文、西班牙文、德文、法文、義文、繁體中文、簡體中文、印地文、土耳其文。
    Example: [verse]
Two a.m., the neon hums
Steam on the glass, the night still runs

[chorus]
Leave the light on, leave the light on
For the ones who don't go home

  - `music_style` (object)
    歌曲的音樂風格。所有欄位皆可選。

  - `music_style.genre` (string)
    歌曲曲風，例如 Pop、Lo-fi Hip Hop
    Example: Acoustic Pop

  - `music_style.mood` (string)
    歌曲情緒，例如 Calm、Uplifting
    Example: Calm, hopeful

  - `music_style.vocal` (string)
    人聲類型。instrumental 為 true 時忽略。
    Enum: "female", "male"

  - `music_style.description` (string)
    其他細節，例如樂器或節奏。
    Example: soft piano, brushed drums

  - `instrumental` (boolean)
    設為 true 生成無人聲、無歌詞的純音樂。
    Example: false

  - `idea` (any, required)

  - `lyrics` (any, required)

  - `instrumental` (string)
    Enum: "false"

## Response 200:

  - `200` (unknown)
    任務執行成功

## Response 200 fields (application/json):

  - `status` (integer)
    回應狀態
    Example: 200

  - `data` (object)

  - `data.task_id` (string)
    這個任務的 ID。任務結果可以此 ID 查詢，有效期限 30 天。
    Example: grH0CvsgXuAIHLUzD0V1Ol34hoet3R1tvdbtiVHrDb6_UqCLKIejAIajwxrhOAfe

## Response 400:

  - `400` (unknown)
    任務執行失敗

## Response 400 fields (application/json):

  - `status` (integer)
    回應狀態
    Example: 400

  - `error` (string)
    錯誤訊息
    Example: The operation could not be completed

  - `error_code` (string)
    錯誤代碼：
* InvalidParameters - 請求參數無效
* CreditInsufficiency - 點數不足，無法執行
* BadRequest - 非預期的請求參數
* InvalidStyleGroup - 風格群組 id 無效
* InvalidStyle - 風格 id 無效
    Enum: "InvalidParameters", "CreditInsufficiency", "InvalidStyleGroup", "InvalidStyle", "BadRequest"

## Response 401:

  - `401` (unknown)
    API 金鑰無效或缺失

## Response 401 fields (application/json):

  - `status` (integer)
    回應狀態
    Example: 401

  - `error` (string)
    Example: Invalid API key

## Response 429:

  - `429` (unknown)
    請求過多

## Response 429 fields (application/json):

  - `status` (integer)
    回應狀態
    Example: 429

  - `error` (string)
    Example: Too many requests

