# 音乐

`/v1/audio/generations` 是 OpenAI audio 系列的扩展（OpenAI 没有音乐接口），异步。Suno 的全部能力都从这一个入口调用，用 `task` 字段选择要做什么。

## 创建歌曲

`model` 为 `suno`（默认版本 v6），或带版本的 `suno-v6`、`suno-v6-mini`、`suno-v6-wild`、`suno/v6`；`suno-v55`、`suno-v45` 等其它版本号也接受，按 v6 执行。其他值返回 400 `model_not_found`。`task` 缺省为 `create`。传 `prompt`（描述）或 `lyrics`（歌词），可选 `style`、`title`、`instrumental`；`prompt` 与 `lyrics` 至少要有一个。未识别的字段会原样传给音乐渠道。

```bash
curl https://api.novapi.ai/v1/audio/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "suno",
  "prompt": "A calm lo-fi instrumental with vinyl crackle, 78 BPM"
}'
```

Python：

```python
import os, requests

r = requests.post(
    "https://api.novapi.ai/v1/audio/generations",
    headers={"Authorization": "Bearer " + os.environ["API_KEY"]},
    json={
      "model": "suno",
      "prompt": "A calm lo-fi instrumental with vinyl crackle, 78 BPM"
    },
)
print(r.json())  # poll GET /v1/audio/generations/{id} until status is completed
```

## 其它 task

同一个入口，加上 `task` 就能做其它事，例如续写一首歌：

```bash
# extend a song: the same endpoint, just add task
curl https://api.novapi.ai/v1/audio/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "suno-v6",
    "task": "extend",
    "clip_id": "<clip-id>",
    "continue_at": 60,
    "prompt": "a big final chorus"
  }'
```

`task` 的取值与 Suno 文档页的 task 一致，大小写、连字符、下划线都不敏感（`upload-extend`、`upload_extend` 都行，页面里的 `midi` 就是 `mdi`，`export` 就是 `mp4`）；取值不认识时返回 400。其余字段就是该 task 页「请求体」里的参数，原样写；snake_case 写法（`continue_at`）会自动转成原生的 camelCase（`continueAt`），两种都给时以 camelCase 为准。需要填任务 ID（`taskId`）的地方，可以直接填创建时拿到的 `audio_…` id。

| 分组 | task |
| --- | --- |
| 生成 | `create`、`extend`、`cover`、`upload_extend`、`upload_cover`、`use_styles_lyrics`、`replace_section`、`replace_auto`、`add_instrumental`、`add_vocals`、`mashup`、`sample`、`sound`、`inspiration`、`gen_stem_two`、`gen_stem_all`、`remaster` |
| 辅助 | `replace_merge`、`upload`、`lyrics`、`upsample_tags`、`persona`、`playlist_create`、`mp4`、`wav`、`timeline`、`downbeats` |
| 扩展 | `mashupLyrics`、`adjustSpeed`、`audioCrop`、`audioFade`、`mdi`、`imageGenerate`、`videoStandaloneGenerate`、`voicePersona`（含 `_init` / `_complete`）、`customModel`（含 `_prepare` / `_upload` / `_create`） |
| 同步 | `download`（直接返回结果，不用轮询） |

## 轮询

`GET /v1/audio/generations/{id}`。`status` 取值与视频一致：`queued`、`in_progress`、`completed`、`failed`。完成后 `data[]` 列出生成的音频（Suno 一次通常出两首）；`result` 是该 task 的原生结果。

```json
{
  "id": "audio_<task-id>",
  "object": "audio.generation",
  "model": "suno",
  "task": "create",
  "status": "completed",
  "created_at": <unix-seconds>,
  "completed_at": <unix-seconds>,
  "error": null,
  "data": [
    {
      "id": "...",
      "audio_url": "https://...",
      "video_url": "https://...",
      "image_url": "https://...",
      "title": "...",
      "duration": <seconds>,
      "tags": "..."
    }
  ],
  "result": [ ... the task's native result ... ]
}
```

没有音频的 task（歌词、persona、时间轴、节拍、音轨分离等）`data` 为空数组，结果读 `result`：

```bash
# task = lyrics: no audio, so data is [] and the lyrics are in result
{
  "id": "audio_<task-id>",
  "object": "audio.generation",
  "model": "suno",
  "task": "lyrics",
  "status": "completed",
  "data": [],
  "result": [
    { "title": "...", "text": "[Verse] ...", "tags": ["..."], "status": "complete" }
  ]
}
```

## 下载单曲（同步）

`task: "download"` 把一首歌还原成完整音频并转存，同步返回，已经是 `completed`，没有 id 可轮询。用 `clip_id`、`url` 或 `task_id`（可直接填 `audio_…` id，配合 `clip_index` 选第几首）三选一指定要下载的歌。

```bash
# task = download is synchronous: the reply is already completed, there is nothing to poll
curl https://api.novapi.ai/v1/audio/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "model": "suno", "task": "download", "task_id": "audio_<task-id>", "clip_index": 0 }'

{
  "id": "audio_dl_<clip-id>",
  "object": "audio.generation",
  "task": "download",
  "status": "completed",
  "data": [{ "id": "<clip-id>", "audio_url": "https://...", "title": "..." }],
  "result": { "clipId": "<clip-id>", "url": "https://...", "format": "m4a", "bytes": <int>, "cached": false }
}
```

## Suno v1（suno_v1）

Suno v1 也从这个入口调用：`model` 取 `suno_v1`（缺省版本 v55），或带版本的 `suno_v1-v55`、`suno_v1-v50`、`suno_v1-v45-plus`、`suno_v1-v45`、`suno_v1-v45-lite`、`suno_v1-v40`、`suno_v1-v35`，所有版本同价；API Key 的可用范围里写 `suno_v1`（渠道组名）。它与上面的 `suno`（v2）是两套互不相通的接口，任务 ID、`clip_id` 不通用。

音乐类 task（`create`、`extend`、`cover`、`replace_section` 等）可以用友好别名：`prompt` = 歌曲描述，`lyrics` = 歌词（自定义模式），`style` = 风格标签，`title`，`instrumental`（布尔）。`clip_id` 会按 task 映射成接口要的歌曲 ID 字段：`extend` → `continue_clip_id`，`cover`、`replace_section` → `cover_clip_id`，分轨 → `continue_clip_id`，`mp4`、`persona`、`timeline`、`downbeats`、`wav` → `songId`。其余字段用 v1 原生字段名（见 Suno v1 文档页，如 `continue_at`、`cover_start_s`、`infill_lyrics`、`make_instrumental`、`vocal_gender`、`style_weight`），原生字段与别名同时给时以原生字段为准。需要 `taskId` 的地方可以直接填返回的 `audio_v1_<数字>` id。

```bash
# legacy Suno (suno_v1), create: describe the song in one line
curl https://api.novapi.ai/v1/audio/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "model": "suno_v1-v50", "prompt": "a catchy upbeat pop song about summer" }'

# custom mode: lyrics + style + title
curl https://api.novapi.ai/v1/audio/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "suno_v1",
    "lyrics": "[Verse] ...",
    "style": "pop, upbeat",
    "title": "Summer"
  }'

# extend a song: task + clip_id (a data[].id from an earlier result) + the v1 native continue_at
curl https://api.novapi.ai/v1/audio/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "model": "suno_v1", "task": "extend", "clip_id": "<clip-id>", "continue_at": 60, "style": "pop, upbeat" }'

# poll with the id from the create reply
curl https://api.novapi.ai/v1/audio/generations/audio_v1_<number> \
  -H "Authorization: Bearer $API_KEY"
```

- [Suno v1文档](https://www.novapi.ai/zh/docs/suno-v1)

`task` 缺省为 `create`；v1 的接口名（如 `createMusicTask`）也认，大小写、连字符、下划线都不敏感。取值：

| 类型 | task |
| --- | --- |
| 异步（返回 `audio_v1_<数字>`，要轮询） | `create`、`extend`、`cover`、`replace_section`、`from_audio`、`from_audio_id`、`artist`、`remix_extend`、`generate`、`generate_extend`、`replace_merge`、`gen_stem_two`、`gen_stem_all`、`upload`、`lyrics`、`mp4` |
| 同步（创建响应已是 `completed`，不可轮询） | `persona`、`timeline`、`downbeats`、`wav`、`upsample_tags`、`image_generate`、`archive` |

创建响应 `status` 为 `queued`，id 是 `audio_v1_<数字>`；用 `GET /v1/audio/generations/{id}` 轮询，`status` 取值同上（`queued`、`in_progress`、`completed`、`failed`）。完成后 `data[]` 是歌曲列表（一次通常两首，每项含 `id`、`audio_url`、`video_url`、`image_url`、`title`、`duration`、`tags`），续写、翻唱要的 `clip_id` 就是这里的 `id`；`result` 是原生结果。失败时 `error.message` 是原因，积分自动退回。同步 task 的 id 形如 `audio_v1_<task>_<随机串>`，不能轮询，结果在 `result`。

```bash
# create reply: queued, poll with the id
{
  "id": "audio_v1_<number>",
  "object": "audio.generation",
  "model": "suno_v1",
  "task": "create",
  "status": "queued",
  "created_at": <unix-seconds>,
  "data": []
}

# poll, completed: data[] lists the songs (usually two), result is the native result
{
  "id": "audio_v1_<number>",
  "status": "completed",
  "data": [
    { "id": "<clip-id>", "audio_url": "https://...", "video_url": "...", "image_url": "...", "title": "...", "duration": <seconds>, "tags": "..." }
  ],
  "result": [ ... ]
}

# poll, failed: the reason is in error.message, credits are refunded
{
  "id": "audio_v1_<number>",
  "status": "failed",
  "error": { "code": "audio_generation_failed", "message": "..." }
}

# synchronous task (persona / timeline / downbeats / wav / upsample_tags / image_generate / archive):
# the create reply is already completed and the id is not pollable
{
  "id": "audio_v1_<task>_<random>",
  "task": "persona",
  "status": "completed",
  "data": [],
  "result": { ... }
}
```

错误是 OpenAI 错误体：402 积分不足，400 参数错误或该 task 没有配置价格，403 Key 的可用范围不含 `suno_v1`，502 上游错误。

## 说明

- 异步任务的 id 以 `audio_` 开头，只能由创建它的账号读取。
- 失败任务的 `error.code` 为 `audio_generation_failed`；`download` 的失败直接返回 HTTP 错误，已扣的费用会退回。
- 每个 task 的完整参数、响应字段与常见失败原因，见 Suno 文档页里对应 task 的说明；那里同时给出 OpenAI 写法与原生写法。价格以定价页为准。
- Suno v1 的上游目前没有可用的生成资源（2026-11-06 实测）：创建、续写、翻唱会以 `No available token` 失败并自动退款；成功后 `data[]` 的歌曲结构没有用真实数据核对过。详见 Suno v1 文档页的「实测情况」。
