> ## Documentation Index
> Fetch the complete documentation index at: https://apixo.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Suno API：生成帶人聲和歌詞的 AI 音樂

> AI 音樂生成 API，用於根據文字提示或自訂歌詞，透過 Suno V6 模式創建聲樂與器樂歌曲。

## 概覽

Suno 可以根據文字描述或按段落編排的歌詞，生成完整的音樂作品。在 APIXO Playground 試用後，可依本頁範例呼叫 API。

| 功能 | 值 |
| - | - |
| 模型 ID | `suno` |
| 輸出 | 帶有封面圖片的音軌 |
| 送貨 | 非同步輪詢或 webhook 回呼 |
| 支援的模式 | `V6`, `V6_MINI`, `V6_WILD` |
| 非自訂提示長度 | 1 至 500 個字元 |
| 自訂提示長度 | 1 至 5000 個字元 |
| 訂製款式長度 | 最多 1000 個字元 |

## V6 遷移和傳統模式相容性

目前只有 V6 模式系列可用於新整合。在新請求中使用 `V6`、`V6_MINI` 或 `V6_WILD`。

所有 V3、V4 和 V5 模式均已停用。為了保持現有整合的兼容性，在處理任務之前接受並映射已停用的模式，如下所示：

| 退休模式已提交 | 用於任務的模式 |
| - | - |
| `V3.5`, `V3_5`, `V4.5 All`, `V4_5ALL` | `V6_MINI` |
| 任何其他 V3、V4 或 V5 模式或別名 | `V6` |

將用戶端更新為 V6 模式之一。相容性行為適用於現有請求，不會使已停用模式支援新整合的值。

## 端點與身分驗證

API 基底網址：

```text theme={null}
https://api.apixo.ai/api/v1
```

| 方法 | 端點 | 用途 |
| - | - | - |
| `POST` | `/generateTask/suno` | 提交音樂生成任務 |
| `GET` | `/statusTask/suno?taskId={taskId}` | 查詢任務狀態並取得結果 |

每個請求都必須附上 APIXO API 金鑰：

```http theme={null}
Authorization: Bearer YOUR_API_KEY
```

送出任務時，還需設定以下請求標頭：

```http theme={null}
Content-Type: application/json
```

## 非同步請求範例

此最小請求提交一個簡單的文字到音樂任務並傳回 `taskId`。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/suno" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "V6",
      "prompt": "upbeat pop song about a summer road trip",
      "customMode": false,
      "instrumental": false
    }
  }'
```

成功回應：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678"
  }
}
```

請保留 `taskId`，後續輪詢結果時會用到。

## 輪詢結果

```bash theme={null}
curl -X GET "https://api.apixo.ai/api/v1/statusTask/suno?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

任務處理中的回應範例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "processing",
    "createTime": 1767965610929
  }
}
```

成功回應：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[{\"audio_url\":\"https://file.apixo.ai/track1.mp3\",\"image_url\":\"https://file.apixo.ai/cover1.jpg\"},{\"audio_url\":\"https://file.apixo.ai/track2.mp3\",\"image_url\":\"https://file.apixo.ai/cover2.jpg\"}]}",
    "lyrics": "[Verse 1]\nRolling down the highway...",
    "createTime": 1767965610929,
    "completeTime": 1767965700929,
    "costTime": 90000
  }
}
```

任務失敗時的回應範例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "PromptInvalid",
    "failMsg": "Prompt is invalid or rejected",
    "createTime": 1767965610929,
    "completeTime": 1767965620132,
    "costTime": 9203
  }
}
```

等 `state` 變為 `success` 後，再解析 `resultJson`：

```javascript theme={null}
const payload = JSON.parse(data.resultJson);
const tracks = payload.resultUrls;

for (const track of tracks) {
  console.log(track.audio_url, track.image_url);
}
```

> [!WARNING]
>
> Suno `resultJson` 包含 `resultUrls` 作為物件陣列。每個項目可以包括 `audio_url` 用於生成的 MP3 和 `image_url` 用於封面圖片。不要將其解析為純字串 URL 陣列。

## 請求體

### 簡單模式

使用 `customMode: false` 時，Suno 將根據簡短描述生成歌曲。

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "V6",
    "prompt": "upbeat pop song about a summer road trip",
    "customMode": false,
    "instrumental": false
  }
}
```

### 自訂歌詞模式

當您想要提供歌詞、風格和標題時，請使用 `customMode: true`。

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "V6_WILD",
    "prompt": "[Verse 1]\nWalking down an empty street\nEchoes of your laughter sweet\n\n[Chorus]\nI miss you more than words can say",
    "customMode": true,
    "instrumental": false,
    "style": "orchestral, emotional, film score",
    "title": "Dawn of Hope",
    "vocalGender": "f",
    "styleWeight": 0.6,
    "weirdnessConstraint": 0.2,
    "audioWeight": 0.5,
    "negativeTags": "noise, distortion"
  }
}
```

### 器樂模式

當您想要沒有人聲的音樂時，請設定 `instrumental: true`。

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "V6_WILD",
    "prompt": "cinematic orchestral track with gentle piano and strings",
    "customMode": true,
    "instrumental": true,
    "style": "orchestral, cinematic, ambient",
    "title": "Peaceful Morning",
    "styleWeight": 0.7
  }
}
```

## 參數

**request\_type** `string` (default: async)

取得結果的方式。選擇 `async` 時，透過 `statusTask` 輪詢結果；選擇 `callback` 時，透過 Webhook 接收結果。

**callback\_url** `string`

當`request_type`為`callback`時需要。必須是可以接收任務負載的公開 HTTPS URL。請參閱 [Webhooks](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)。

**input** `object` *required*

Suno 的輸入參數。

**屬性**

**mode** `string` *required*

Suno 生成模式，可設為 `V6`、`V6_MINI` 或 `V6_WILD`。已停用的 V3、V4 和 V5 模式仍可按[遷移到 V6 與舊模式相容說明](#v6-migration-and-legacy-mode-compatibility)中的規則呼叫。

**prompt** `string` *required*

歌曲描述或歌詞。必須是非空字串。非自訂模式下，支援1-500個字元。自訂模式下，支援1-5000個字元。

**customMode** `boolean` *required*

支援的值：`true` 表示自訂歌詞模式，`false` 表示歌曲描述。自訂歌詞模式需要樣式和標題。

**instrumental** `boolean` *required*

是否生成不含人聲的純器樂曲。

**style** `string`

自訂歌詞模式下需要。音樂風格描述，最多 1000 個字元。

**title** `string`

自訂歌詞模式下需要。歌曲標題，最多 80 個字元。

**vocalGender** `string`

選填的聲音性別提示。支援的值：`m` 為男聲，`f` 為女聲。

**styleWeight** `number`

可選樣式粗細從 `0` 到 `1`。

**weirdnessConstraint** `number`

從 `0` 到 `1` 的可選創造力限制。

**audioWeight** `number`

可選音訊權重從 `0` 到 `1`。

**negativeTags** `string`

選填的負標籤，最多 200 個字元。

## 回應格式

### 送出任務時的回應

任務受理後，`POST /generateTask/suno` 會傳回任務 ID：

**code** `integer`

API 狀態碼。`200` 表示任務已受理。

**message** `string`

狀態說明。

**data.taskId** `string`

任務的唯一 ID，用於查詢任務狀態。

### 狀態回應欄位

**taskId** `string`

任務的唯一識別碼。

**state** `string`

目前的任務狀態，可能的值為 `pending`、`processing`、`success`、`failed`。

**resultJson** `string`

JSON 包含產生的軌跡物件的字串。當 `state` 為 `success` 時存在。

**lyrics** `string`

結果中包含歌詞或提示文字。僅在可用時呈現。

**failCode** `string`

供程式判讀的錯誤碼，僅在 `state` 為 `failed` 時傳回。

**failMsg** `string`

失敗原因說明，僅在 `state` 為 `failed` 時傳回。

**createTime** `integer`

任務建立時的 Unix 時間戳記，單位為毫秒。

**completeTime** `integer`

任務完成時的 Unix 時間戳記，單位為毫秒。任務完成後才會傳回。

**costTime** `integer`

處理時間，以毫秒為單位。任務完成且有這項資料時傳回。

解析的`resultJson`結構：

```json theme={null}
{
  "resultUrls": [
    {
      "audio_url": "https://file.apixo.ai/track1.mp3",
      "image_url": "https://file.apixo.ai/cover1.jpg"
    },
    {
      "audio_url": "https://file.apixo.ai/track2.mp3",
      "image_url": "https://file.apixo.ai/cover2.jpg"
    }
  ]
}
```

| 每個項目中的欄位 | 型別 | 說明 |
| - | - | - |
| `audio_url` | string | 產生 MP3 音訊檔 URL |
| `image_url` | string | 產生的封面圖片 URL |

## Webhook 回呼模式

當您的後端應自動接收任務負載而不是輪詢時，請使用回呼模式。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/suno" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "callback",
    "callback_url": "https://your-server.com/webhooks/apixo",
    "input": {
      "mode": "V6",
      "prompt": "warm acoustic song about coming home",
      "customMode": false,
      "instrumental": false
    }
  }'
```

只解析 `resultJson` 當回呼有效負載有 `state: "success"`。看 [Webhook](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md) 用於交付要求和重試行為。

## 計費

新提交的非 LLM 請求按 **1 點 = `$0.001`** 計費。先依用量和加購項目計算總額，再套用帳戶折扣，最後將請求總額無條件進位至整數點數。若已約定固定單價，則保留該單價的精度，不再使用標準價或另行打折；最終點數仍須進位。詳見[積分換算與進位](https://apixo.ai/docs/zh-hant/pricing.md#credit-conversion-and-rounding)。

Suno 按產生請求計費。目前公開的 APIXO 目錄將 Suno 列為 `$0.18 / use`。

| 模型 | 路線 | APIXO 價格 | 單位 |
| - | - | - | - |
| Suno V6 | 獨家的 | `$0.18` | 每次使用 |
| SunoV6迷你 | 獨家的 | `$0.18` | 每次使用 |
| Suno V6 百搭 | 獨家的 | `$0.18` | 每次使用 |

有關當前定價，請參閱 [API 定價](https://apixo.ai/pricing/api)。

## 耗時與輪詢

實際延遲可能會因提示複雜性、所選模式、提供者佇列和目前負載而異。

| 工作流程 | 一般生成時間 | 建議首次查詢時間 | 輪詢間隔 |
| - | - | - | - |
| Suno 音樂生成 | 60s-90s | 任務建立 60 秒後 | 60s |

> [!TIP]
>
> 對於生產工作負載，使用回呼模式來減少輪詢流量。結果 URL 預設儲存 15 天；帳戶級儲存設定可能會變更保留期限。

如果收到 `429`，請放慢請求速度並透過退避重試。有關帳戶層級的詳細信息，請參閱 [系統 API](https://apixo.ai/docs/zh-hant/api-reference/system.md)。

## 錯誤與排查

### HTTP 錯誤

| 代碼 | 含義 | 處理方式 |
| - | - | - |
| `400` | 缺少必需參數、參數類型無效、值無效或超出長度 | 修正請求後再試 |
| `401` | 缺少 API 金鑰，或金鑰無效 | 檢查 `Authorization` 請求標頭 |
| `402` | 餘額不足 | 重試前加結餘額 |
| `422` | 計費計算失敗 | 如果該模型應在您的帳戶上可用，請聯絡支援人員 |
| `429` | 已達到速率或並行限制 | 以指數退避方式重試 |
| `500` | 伺服器錯誤或未知任務失敗 | 逐步拉長間隔後重試 |
| `502` | 服務或網路錯誤 | 逐步拉長間隔後重試 |
| `504` | 服務超時 | 重新嘗試；耗時較長的任務可改用回呼模式 |

### 任務失敗欄位

當任務到達 `state: "failed"` 時，檢查狀態回應中的 `failCode` 和 `failMsg`。

| 失敗程式碼範例 | 含義 | 處理方式 |
| - | - | - |
| `PromptInvalid` | 提示被拒絕或格式錯誤 | 重寫提示或歌詞 |
| `SensitiveContent` / `SensitiveContentDetected` | 提示或輸出被安全檢查標記 | 更改提示、歌詞或風格 |
| `MissingParameter` | 該服務報告缺少所需數據 | 檢查`mode`、`prompt`、`customMode`、`instrumental`和自訂模式欄位 |
| `RateLimited` / `RateLimitExceeded` | 請求頻率已達上限 | 逐步拉長間隔後重試 |
| `Timeout` | 任務逾時 | 稍後重試或使用回呼模式 |
| `Unknown error` | 任務因不明原因失敗 | 重試並退避；如果重複出現，請聯絡支援人員 |

完整列表見[錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)。

## MCP 整合

[完整模型 Schema](https://apixo.ai/docs/models/schemas/audio/suno.json) 中的 `mcp.result` 指定結果的解析方式，`mcp.attachments` 列出可繫結檔案的欄位。這些中繼資料供用戶端整合使用，無須當作生成參數提交。模型參數由 API 驗證。

## 相關連結

* [生成 API 總覽](https://apixo.ai/docs/zh-hant/models.md)
* [音訊模型](https://apixo.ai/docs/zh-hant/models/audio)
* [送出生成任務](https://apixo.ai/docs/zh-hant/api-reference/generate-task.md)
* [查詢任務狀態](https://apixo.ai/docs/zh-hant/api-reference/status-task.md)
* [Webhook](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)
* [錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)
* [參數規範](https://apixo.ai/docs/zh-hant/api-reference/parameters.md)
* [路由策略](https://apixo.ai/docs/zh-hant/concepts/routing-strategies.md)
* [嘗試 Suno 在 APIXO Playground](https://apixo.ai/models/suno)
* [API定價](https://apixo.ai/pricing/api)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.