# Lyria 3.5 生成音乐
> 用 Lyria 3.5 模型生成音乐，异步任务
> 与 Flow Music 主接口同一端点，靠 `version` 字段区分
> 单次只出一首
`POST /v1/music/generations`
## 认证
- `Authorization` (string / 必填) — 所有接口均使用 Bearer Token 进行认证。 获取 API Key：[访问控制台](https://api.oairoute.com/keys) 创建。 请求时在请求头中添加： ```http Authorization: Bearer YOUR_OAIRoute_KEY ```
## 请求参数
- `model` (string / 必填) — 固定传 `flowmusic`，大小写不敏感。
- `version` (string / 必填) — 固定传 `lyria-3.5`。这是与普通 Flow Music 生成的关键区别——那边不传或传其他值。
- `sound_prompt` (string / 条件必填) — 风格与音色的描述提示词。 `sound_prompt` 与 `lyrics` **不能都不传**。
- `lyrics` (string / 条件必填) — 歌词文本。可以先调「生成歌词」接口拿到再回填。 与 `sound_prompt` 至少传一个。
- `title` (string / 可选) — 作品标题。
- `bpm` (string / 可选) — 每分钟节拍数，取值须不小于 1。**类型是字符串**，例如 `"96"`。
- `length` (integer / 可选) — 时长，单位秒，范围 1 到 240。
- `seed` (string / 可选) — 随机种子。同请求同种子结果相似但不保证一致。
> **Note:** 
> 每次请求**只生成一首**。与 Suno 那边一次出两首不同，这里的 `audio_index` 永远是 1。
## 提交响应
- `code` (integer) — 状态码，成功为 200。
- `data[].status` (string) — 提交时为 `submitted`。
- `data[].task_id` (string) — 任务标识，用于查询。
## 任务查询响应
- `data.id` (string) — 任务 ID。
- `data.status` (string) — 如 `completed`。
- `data.progress` (integer) — 进度百分比。
- `data.created` (integer) — 创建时间戳。
- `data.completed` (integer) — 完成时间戳。
- `data.actual_time` (integer) — 实际耗时，单位秒。
- `data.cost` (number) — 计费金额。
- `data.credits_cost` (number) — 积分消耗。
- `data.result.music[]` (array) — 音频结果列表。
### music[] 元素字段
- `clip_id` (string) — 片段 ID。
- `title` (string) — 标题。
- `duration_seconds` (string) — 时长，字符串形式的数值。
- `create_time` (string) — 创建时间，ISO 8601 格式。
- `lyrics` (string) — 歌词内容。
- `lyrics_id` (string) — 歌词 ID。
- `lyrics_timing_markers` (array) — 歌词时间标记对。
- `audio_url` (string) — 音频链接，m4a 格式。
- `wav_url` (string) — WAV 链接。
- `image_url` (string) — 封面图链接。
## 与普通 Flow Music 的差异
| 项目 | 普通生成 | Lyria 3.5 |
|---|---|---|
| 端点 | `/v1/music/generations` | 同一个端点 |
| `version` | 不传或传其他值 | **必须传 `lyria-3.5`** |
| 单次产出 | 1 首 | 1 首 |
两条路共用端点，靠 `version` 分流。忘了传 `version` 就会走普通模型，产出结果与预期不同，但不报错——这是最容易忽略的一点。
## 错误
| code | 说明 |
|---|---|
| `invalid_request` | 参数校验失败 |
常见 `code`：
更多状态码与重试建议见[错误码与限流](../../../support/errors.html)，常见报错的排查步骤见[常见问题](../../../support/faq.html)。
## 使用示例
提交一个任务并拿到 `task_id`：
> **Note:** 
> 提交成功只表示任务已受理。真正的产物要拿返回的 `task_id` 去任务查询接口轮询，`status` 变成 `completed` 之后才有结果。
**Lyria 3.5 生成音乐{Lyria 3.5 generate music}::cURL**
```
curl -X POST https://api.oairoute.com/v1/music/generations \
  -H 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  -H 'Content-Type: application/json' \
  --data '{
    "model": "flowmusic",
    "version": "lyria-3.5",
    "sound_prompt": "温暖的钢琴与弦乐，慢板，黄昏氛围",
    "bpm": "72",
    "length": 150
  }'
```
**Lyria 3.5 生成音乐{Lyria 3.5 generate music}::Python**
```
import requests
res = requests.post(
    "https://api.oairoute.com/v1/music/generations",
    headers={
        "Authorization": "Bearer YOUR_OAIRoute_KEY",
        "Content-Type": "application/json",
    },
    json={
        "model": "flowmusic",
        "version": "lyria-3.5",
        "sound_prompt": "温暖的钢琴与弦乐，慢板，黄昏氛围",
        "bpm": "72",
        "length": 150,
    },
)
print(res.json()["data"][0]["task_id"])
```
**Lyria 3.5 生成音乐{Lyria 3.5 generate music}::JavaScript**
```
const url = "https://api.oairoute.com/v1/music/generations";
const options = {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "model": "flowmusic",
    "version": "lyria-3.5",
    "sound_prompt": "温暖的钢琴与弦乐，慢板，黄昏氛围",
    "bpm": "72",
    "length": 150
  }),
};
fetch(url, options)
  .then((res) => res.json())
  .then((json) => console.log(json))
  .catch((err) => console.error(err));
```
**200 Lyria 3.5 生成音乐{Lyria 3.5 generate music}**
```
{
  "code": 200,
  "data": [
    { "status": "submitted", "task_id": "task_01K8F22M0HP1GJWBJYZMKX1XS1" }
  ]
}
```
**带歌词{With lyrics}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/music/generations' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "flowmusic",
  "version": "lyria-3.5",
  "sound_prompt": "民谣，木吉他，温柔",
  "lyrics": "窗外的雨停了\n光线慢慢进来",
  "title": "雨后",
  "bpm": "88",
  "length": 180
}'
```
**带歌词{With lyrics}::Python**
```
import requests
url = "https://api.oairoute.com/v1/music/generations"
headers = {
    "Authorization": "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
}
payload = {
      "model": "flowmusic",
      "version": "lyria-3.5",
      "sound_prompt": "民谣，木吉他，温柔",
      "lyrics": "窗外的雨停了\n光线慢慢进来",
      "title": "雨后",
      "bpm": "88",
      "length": 180
    }
res = requests.post(url, headers=headers, json=payload)
print(res.json())
```
**带歌词{With lyrics}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/v1/music/generations", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "model": "flowmusic",
    "version": "lyria-3.5",
    "sound_prompt": "民谣，木吉他，温柔",
    "lyrics": "窗外的雨停了\n光线慢慢进来",
    "title": "雨后",
    "bpm": "88",
    "length": 180
  }),
});
console.log(await res.json());
```
**200 带歌词{With lyrics}**
```
{
  "code": 200,
  "data": [
    { "status": "submitted", "task_id": "task_01K8F22M0HP1GJWBJYZMKX1XS1" }
  ]
}
```
