歌曲生成接口
Suno 歌曲生成 API 对接说明
基本使用
想些什么歌曲,可以任意输入一段文字,比如我想生成一个关于新年快乐的歌曲,就可以输入 新年快乐
,下面使用apifox进行发送请求,具体的参数如图所示:
可以点击发送按钮直接测试 API,稍等 1-2 分钟,结果如下:
{
"success": true,
"task_id": "4226ba3a-c168-464e-b2db-18b32b17335a",
"trace_id": "cb108c23-1b32-4fa4-99c7-e1e15e6e542c",
"data": [
{
"id": "7b0df74e-09c6-4a84-845b-9a2cf2cbfbd4",
"title": "新年快乐",
"image_url": "https://cdn2.suno.ai/image_7b0df74e-09c6-4a84-845b-9a2cf2cbfbd4.jpeg",
"lyric": "[Verse]\n挂灯笼 照亮每个街头\n福字倒 福气满到家门口\n鞭炮响 震散旧年的哀愁\n烟花飞 夜空美到心头\n[Verse 2]\n舞龙起 红色翻跃天空\n狮鼓敲 热闹暖暖人心中\n笑开怀 送祝福到意浓\n团圆饭 温热全家梦\n[Chorus]\n新年快乐 心愿齐欢歌\n祝福今天照亮每一刻\n梦想点燃 像烟花的火\n新年到来 快乐你和我\n[Verse 3]\n瑞雪飘 给岁月涂上白\n花儿开 宛如新的期待\n手牵手 不论东西南北\n我们一起 把幸福年代彩排\n[Bridge]\n一年忙碌 此刻都抛开\n让喜悦在心中蔓延发芽开\n拥抱未来 我们种下爱\n新的一年 全世界盛开\n[Chorus]\n新年快乐 心愿齐欢歌\n祝福今天照亮每一刻\n梦想点燃 像烟花的火\n新年到来 快乐你和我",
"audio_url": "https://cdn1.suno.ai/7b0df74e-09c6-4a84-845b-9a2cf2cbfbd4.mp3",
"video_url": "",
"created_at": "2025-04-11T04:47:14.486Z",
"model": "chirp-v4",
"state": "succeeded",
"prompt": "新年快乐",
"style": "male vocals, chinese",
"duration": 134.8
},
{
"id": "b423fb9a-99e0-4e1b-97cd-54c62e5041bc",
"title": "新年快乐",
"image_url": "https://cdn2.suno.ai/image_b423fb9a-99e0-4e1b-97cd-54c62e5041bc.jpeg",
"lyric": "[Verse]\n挂灯笼 照亮每个街头\n福字倒 福气满到家门口\n鞭炮响 震散旧年的哀愁\n烟花飞 夜空美到心头\n[Verse 2]\n舞龙起 红色翻跃天空\n狮鼓敲 热闹暖暖人心中\n笑开怀 送祝福到意浓\n团圆饭 温热全家梦\n[Chorus]\n新年快乐 心愿齐欢歌\n祝福今天照亮每一刻\n梦想点燃 像烟花的火\n新年到来 快乐你和我\n[Verse 3]\n瑞雪飘 给岁月涂上白\n花儿开 宛如新的期待\n手牵手 不论东西南北\n我们一起 把幸福年代彩排\n[Bridge]\n一年忙碌 此刻都抛开\n让喜悦在心中蔓延发芽开\n拥抱未来 我们种下爱\n新的一年 全世界盛开\n[Chorus]\n新年快乐 心愿齐欢歌\n祝福今天照亮每一刻\n梦想点燃 像烟花的火\n新年到来 快乐你和我",
"audio_url": "https://cdn1.suno.ai/b423fb9a-99e0-4e1b-97cd-54c62e5041bc.mp3",
"video_url": "",
"created_at": "2025-04-11T04:47:14.486Z",
"model": "chirp-v4",
"state": "succeeded",
"prompt": "新年快乐",
"style": "male vocals, chinese",
"duration": 148.96
}
]
}
可以看到这时候我们就得到了两首歌的内容,包括标题、预览图、歌词、音频、视频等内容。
字段说明如下:
- success:生成是否成功,如果成功则为
true
,否则为false
- data:是一个列表,包含了生成的歌曲的详细信息。
- state: 歌曲生成状态,主要包含四种,具体的如下:
- succeeded:生成成功
- pending:队列中
- running:执行中
- error:失败
- id:歌曲 ID
- title:歌曲的标题
- image_url:歌曲的封面图片
- lyric:歌曲的歌词
- audio_url:歌曲的音频文件,打开就是一个 mp3 音频。
- video_url:歌曲的视频文件,打开就是一个 mp4 视频。
- created_at:创建的时间
- model:使用的模型,一般是最新的 v3 模型
- style:风格
- state: 歌曲生成状态,主要包含四种,具体的如下:
自定义生成
如果想自定义生成歌词,可以输入歌词:
这时候 lyric
字段可以传入类似如下内容:
[Verse]\nSnowflakes falling all around\nGlistening white\nCovering the ground\nChildren laughing\nFull of delight\nIn this winter wonderland tonight\nSanta's sleigh\nUp in the sky\nRudolph's nose shining bright\nOh my\nHear the jingle bells\nRinging so clear\nBringing joy and holiday cheer\n[Verse 2]\nRoasting chestnuts by the fire's glow\nChristmas lights\nThey twinkle and show\nFamilies gathering with love and cheer\nSpreading warmth to everyone near
注意,这里的歌词中
\n
是换行符,如果你不知道如何生成歌词,可以使用 SunoHub 提供的歌词生成 API 来通过 prompt 生成歌词。
接下来我们要根据歌词、标题、风格自定义生成歌曲,就可以指定如下内容:
- lyric:歌词文本
- custom:填写为
true
,代表自定义生成,该参数默认为 false,代表使用prompt
生成。 - file:歌曲的标题。
- style:歌曲的风格,选填。
填写样例如下:
最后发送请求,生成的效果是类似的。
继续生成功能
如果想对已经生成的Suno歌曲进行继续生成的话,可以将参数 action
设置为 extend
,并且输入需要继续生成歌曲的 ID,歌曲 ID 的获取是根据基本使用来获取,如下图所示:
这时候可以看到歌曲的 ID 为:
"id": "7b0df74e-09c6-4a84-845b-9a2cf2cbfbd4"
注意,这里的歌词中
id
是生成后歌曲的 ID,如果你不知道如何生成歌曲,可以参考上文的基本使用来生成歌曲。
接下来我们要必须填歌词、风格自定义生成歌曲,就可以指定如下内容:
- lyric:歌词文本
- custom:填写为
true
,代表自定义生成,该参数默认为 false,代表使用prompt
生成。 - style:歌曲的风格,选填。
- continue_at:以秒为单位继续现有音频的时间。例如,213.5 表示继续到 3 分 33.5 秒。
填写样例如下:
点击发送,可以发现会得到一个结果,如下:
{
"success": true,
"task_id": "d2a78118-6631-4c2d-97f6-9b95cb9624ca",
"trace_id": "2549ebb7-1d90-4f3c-9bd4-c8b2954fd830",
"data": [
{
"id": "19ba4bb9-c90a-41ba-874d-40e5942e7d26",
"title": "唱的更愉快一点",
"image_url": "https://cdn2.suno.ai/image_19ba4bb9-c90a-41ba-874d-40e5942e7d26.jpeg",
"lyric": "[Verse]\n天空飘着快乐的云彩\n脚下踩着跳跃的节拍\n阳光洒满大街每个角落\n心中冒出几朵好颜色\n[Verse 2]\n微风吹来像糖的味道\n每个人的脸上挂着微笑\n你伸出手牵着欢乐跑\n烦恼全都甩到很远的桥\n[Chorus]\n唱的更愉快一点 啦啦啦\n跳的更开心一点 嘿嘿嘿\n让每个瞬间都值千金\n快乐无敌 没有原因\n[Verse 3]\n日子像串糖葫芦那么甜\n迷路也能变成探险\n光影在手腕上画旋转\n每一个动作都像跳舞般\n[Bridge]\n闭上眼让音乐直入心灵\n转圈圈看世界悄悄微倾\n星星眨眼悄悄为你打气\n这感觉让人不愿暂停\n[Chorus]\n唱的更愉快一点 啦啦啦\n跳的更开心一点 嘿嘿嘿\n拥抱未来没有不可能\n快乐传染 一起狂奔",
"audio_url": "https://cdn1.suno.ai/19ba4bb9-c90a-41ba-874d-40e5942e7d26.mp3",
"video_url": "",
"created_at": "2025-04-11T04:52:44.490Z",
"model": "chirp-v4",
"state": "succeeded",
"prompt": "唱的更愉快一点,更高兴一点",
"style": "playful, chinese lyrics, pop",
"duration": 120
},
{
"id": "fa2273c4-894f-4445-be27-4a908a513ec5",
"title": "唱的更愉快一点",
"image_url": "https://cdn2.suno.ai/image_fa2273c4-894f-4445-be27-4a908a513ec5.jpeg",
"lyric": "[Verse]\n天空飘着快乐的云彩\n脚下踩着跳跃的节拍\n阳光洒满大街每个角落\n心中冒出几朵好颜色\n[Verse 2]\n微风吹来像糖的味道\n每个人的脸上挂着微笑\n你伸出手牵着欢乐跑\n烦恼全都甩到很远的桥\n[Chorus]\n唱的更愉快一点 啦啦啦\n跳的更开心一点 嘿嘿嘿\n让每个瞬间都值千金\n快乐无敌 没有原因\n[Verse 3]\n日子像串糖葫芦那么甜\n迷路也能变成探险\n光影在手腕上画旋转\n每一个动作都像跳舞般\n[Bridge]\n闭上眼让音乐直入心灵\n转圈圈看世界悄悄微倾\n星星眨眼悄悄为你打气\n这感觉让人不愿暂停\n[Chorus]\n唱的更愉快一点 啦啦啦\n跳的更开心一点 嘿嘿嘿\n拥抱未来没有不可能\n快乐传染 一起狂奔",
"audio_url": "https://cdn1.suno.ai/fa2273c4-894f-4445-be27-4a908a513ec5.mp3",
"video_url": "",
"created_at": "2025-04-11T04:52:44.490Z",
"model": "chirp-v4",
"state": "succeeded",
"prompt": "唱的更愉快一点,更高兴一点",
"style": "playful, chinese lyrics, pop",
"duration": 120
}
]
}
可以看出,结果内容与上文的是一致的,这也就实现歌曲的继续生成功能,但如果想获取继续生成的完整歌曲还需要使用下面的拼接功能来获取。
获取完整歌曲
当基于原有的歌曲继续生成歌曲之后,返回的歌曲并不包含原来的歌曲内容。如果要获得完整的歌曲内容,需要使用拼接功能,就可以指定如下内容:
- action:内容为
concat
。 - audio_id:最后一个片段的 ID。
比如扩展后的歌曲 ID 是:19ba4bb9-c90a-41ba-874d-40e5942e7d26,那么可以设置参数如下:
{
"action": "concat",
"audio_id": "19ba4bb9-c90a-41ba-874d-40e5942e7d26"
}
其他参数不变,返回的就是一首完整的歌曲,就是所有歌曲片段的拼接结果,但结果只有一首歌,样例如下:
{
"success": true,
"task_id": "ff73ed83-26d3-47bb-9793-825ac1172abc",
"trace_id": "98315862-fa60-4fa7-b4b8-788ce99fca26",
"data": [
{
"id": "3e78b952-075a-46e8-a9ef-01193a7942b6",
"title": "新年快乐",
"image_url": "https://cdn2.suno.ai/image_19ba4bb9-c90a-41ba-874d-40e5942e7d26.jpeg",
"lyric": "[Verse]\n挂灯笼 照亮每个街头\n福字倒 福气满到家门口\n鞭炮响 震散旧年的哀愁\n烟花飞 夜空美到心头\n[Verse 2]\n舞龙起 红色翻跃天空\n狮鼓敲 热闹暖暖人心中\n笑开怀 送祝福到意浓\n团圆饭 温热全家梦\n[Chorus]\n新年快乐 心愿齐欢歌\n祝福今天照亮每一刻\n梦想点燃 像烟花的火\n新年到来 快乐你和我\n[Verse 3]\n瑞雪飘 给岁月涂上白\n花儿开 宛如新的期待\n手牵手 不论东西南北\n我们一起 把幸福年代彩排\n[Bridge]\n一年忙碌 此刻都抛开\n让喜悦在心中蔓延发芽开\n拥抱未来 我们种下爱\n新的一年 全世界盛开\n[Chorus]\n新年快乐 心愿齐欢歌\n祝福今天照亮每一刻\n梦想点燃 像烟花的火\n新年到来 快乐你和我\n[Verse]\n天空飘着快乐的云彩\n脚下踩着跳跃的节拍\n阳光洒满大街每个角落\n心中冒出几朵好颜色\n[Verse 2]\n微风吹来像糖的味道\n每个人的脸上挂着微笑\n你伸出手牵着欢乐跑\n烦恼全都甩到很远的桥\n[Chorus]\n唱的更愉快一点 啦啦啦\n跳的更开心一点 嘿嘿嘿\n让每个瞬间都值千金\n快乐无敌 没有原因\n[Verse 3]\n日子像串糖葫芦那么甜\n迷路也能变成探险\n光影在手腕上画旋转\n每一个动作都像跳舞般\n[Bridge]\n闭上眼让音乐直入心灵\n转圈圈看世界悄悄微倾\n星星眨眼悄悄为你打气\n这感觉让人不愿暂停\n[Chorus]\n唱的更愉快一点 啦啦啦\n跳的更开心一点 嘿嘿嘿\n拥抱未来没有不可能\n快乐传染 一起狂奔",
"audio_url": "https://cdn1.suno.ai/3e78b952-075a-46e8-a9ef-01193a7942b6.mp3",
"video_url": "",
"created_at": "2025-04-11T04:56:41.409Z",
"model": "chirp-v4",
"state": "succeeded",
"style": "male vocals, chinese",
"duration": 120.99997916666666,
"concat_history": [
{
"id": "7b0df74e-09c6-4a84-845b-9a2cf2cbfbd4",
"continue_at": 1,
"type": "gen",
"source": "ios",
"infill": false
},
{
"id": "19ba4bb9-c90a-41ba-874d-40e5942e7d26"
}
]
}
]
}
自定义上传歌曲生成功能
如果想对自己上传的音乐进行生成的话,我们将上传歌曲与对上传扩展生成合并在一起了,因此需要将参数 action
设置为 upload_generate
,并且输入需要自己上传的音乐链接,接下来我们要必须填歌词、风格自定义生成歌曲,就可以指定如下内容:
- lyric:歌词文本
- custom:填写为
true
,代表自定义生成,该参数默认为 false,代表使用prompt
生成。 - style:歌曲的风格,选填。
- audio_url:自定义上传的歌曲链接,必填。
- prompt:生成的提示词。
- continue_at:表示从上传的音乐哪个时长开始生成,必须要大于0,必填。
填写样例如下:
点击发送,可以发现会得到一个结果,如下:
{
"success": true,
"task_id": "20735a95-90aa-497f-ba7d-f53cb870f19d",
"trace_id": "e4a085dd-e029-48f8-b182-04ad5c32962a",
"data": [
{
"id": "ab735d10-2708-4d5e-a8e9-61e14f1c5b12",
"title": "Lost and Found",
"image_url": "https://cdn2.suno.ai/image_ab735d10-2708-4d5e-a8e9-61e14f1c5b12.jpeg",
"lyric": "[Verse]\nRunning down the alley where the shadows play\nSearching for answers in the light of day\nGot a pocket full of dreams I refuse to lose\nLife’s a wild card and I gotta choose\n[Verse 2]\nSneakers hitting pavement like a heartbeat’s drum\nChasing down a vision where the wild ones run\nThe world’s a broken mirror but I see it clear\nI’m a storm in a bottle got nothing to fear\n[Chorus]\nLost and found I’m spinning around\nPicking up pieces from the ground\nHold your breath as the thunder pounds\nI’m the boy who’ll never back down\n[Verse 3]\nThe stars in the sky they whisper to me\nThey say you’re more than what they let you see\nI’m a rebel searching for where I belong\nChaos in my veins it fuels my song\n[Bridge]\nI’m a spark in the night a beacon of fire\nA dreamer with wings climbing higher and higher\nThey can try to cage me but I'm breaking free\nI’m the boy in the mirror the fighter in me\n[Chorus]\nLost and found I’m spinning around\nPicking up pieces from the ground\nHold your breath as the thunder pounds\nI’m the boy who’ll never back down",
"audio_url": "https://cdn1.suno.ai/ab735d10-2708-4d5e-a8e9-61e14f1c5b12.mp3",
"video_url": "",
"created_at": "2025-04-12T10:38:32.131Z",
"model": "chirp-v4",
"state": "succeeded",
"prompt": "boy",
"style": "male vocals, pop",
"duration": 200.16
},
{
"id": "7a61a147-0715-4cdd-b68e-cfd047e45251",
"title": "Lost and Found",
"image_url": "https://cdn2.suno.ai/image_7a61a147-0715-4cdd-b68e-cfd047e45251.jpeg",
"lyric": "[Verse]\nRunning down the alley where the shadows play\nSearching for answers in the light of day\nGot a pocket full of dreams I refuse to lose\nLife’s a wild card and I gotta choose\n[Verse 2]\nSneakers hitting pavement like a heartbeat’s drum\nChasing down a vision where the wild ones run\nThe world’s a broken mirror but I see it clear\nI’m a storm in a bottle got nothing to fear\n[Chorus]\nLost and found I’m spinning around\nPicking up pieces from the ground\nHold your breath as the thunder pounds\nI’m the boy who’ll never back down\n[Verse 3]\nThe stars in the sky they whisper to me\nThey say you’re more than what they let you see\nI’m a rebel searching for where I belong\nChaos in my veins it fuels my song\n[Bridge]\nI’m a spark in the night a beacon of fire\nA dreamer with wings climbing higher and higher\nThey can try to cage me but I'm breaking free\nI’m the boy in the mirror the fighter in me\n[Chorus]\nLost and found I’m spinning around\nPicking up pieces from the ground\nHold your breath as the thunder pounds\nI’m the boy who’ll never back down",
"audio_url": "https://cdn1.suno.ai/7a61a147-0715-4cdd-b68e-cfd047e45251.mp3",
"video_url": "",
"created_at": "2025-04-12T10:38:32.131Z",
"model": "chirp-v4",
"state": "succeeded",
"prompt": "boy",
"style": "male vocals, pop",
"duration": 172.4
}
]
}
可以看出,结果内容与上文的是一致的,这也就实现自定义歌曲的生成功能。
异步回调
由于 Suno 生成音乐的时间相对较长,大约需要 1-2 分钟,如果 API 长时间无响应,HTTP 请求会一直保持连接,导致额外的系统资源消耗,所以本 API 也提供了异步回调的支持。
整体流程是:客户端发起请求的时候,额外指定一个 callback_url
字段,客户端发起 API 请求之后,API 会立马返回一个结果,包含一个 task_id
的字段信息,代表当前的任务 ID。当任务完成之后,生成音乐的结果会通过 POST JSON 的形式发送到客户端指定的 callback_url
,其中也包括了 task_id
字段,这样任务结果就可以通过 ID 关联起来了。
下面我们通过示例来了解下具体怎样操作。
首先,Webhook 回调是一个可以接收 HTTP 请求的服务,开发者应该替换为自己搭建的 HTTP 服务器的 URL。此处为了方便演示,使用一个公开的 Webhook 样例网站 https://webhook.site/,打开该网站即可得到一个 Webhook URL,如图所示:
将此 URL 复制下来,就可以作为 Webhook 来使用,此处的样例为 https://webhook.site/03e60575-3d96-4132-b681-b713d78116e2。
接下来,我们可以设置字段 callback_url
为上述 Webhook URL,同时填入 prompt
,如图所示:
点击运行,可以发现会立即得到一个结果,如下:
{
"task_id": "44472ab8-783b-4054-b861-5bf14e462f60"
}
稍等片刻,我们可以在 https://webhook.site/03e60575-3d96-4132-b681-b713d78116e2 上观察到生成歌曲的结果,如图所示:
内容如下:
{
"success": true,
"task_id": "44472ab8-783b-4054-b861-5bf14e462f60",
"data": [
{
"id": "da4324e5-84b2-484b-b0e9-dd261381c594",
"title": "Winter Whispers",
"image_url": "https://cdn1.suno.ai/image_da4324e5-84b2-484b-b0e9-dd261381c594.png",
"lyric": "[Verse]\nSnow falling gently from the sky\nChildren giggling as they pass by\nFire crackling\nCozy and warm\nChristmas spirit begins to swarm\n[Verse 2]\nTwinkling lights\nA sight to behold\nStockings hung\nWaiting to be filled with gold\nGifts wrapped with love\nPiled high\nExcitement in the air\nYou can't deny\n[Chorus]\nWinter whispers in the wind\nJoy and love it brings\nLet's celebrate this season\nWith the ones we're missing",
"audio_url": "https://cdn1.suno.ai/da4324e5-84b2-484b-b0e9-dd261381c594.mp3",
"video_url": "https://cdn1.suno.ai/da4324e5-84b2-484b-b0e9-dd261381c594.mp4",
"created_at": "2024-05-11T07:33:05.430Z",
"model": "chirp-v3",
"prompt": "A song for Christmas",
"style": "pop"
},
{
"id": "b878a87b-a0db-4046-8ccd-ecd2fb3d4372",
"title": "Winter Whispers",
"image_url": "https://cdn1.suno.ai/image_b878a87b-a0db-4046-8ccd-ecd2fb3d4372.png",
"lyric": "[Verse]\nSnow falling gently from the sky\nChildren giggling as they pass by\nFire crackling\nCozy and warm\nChristmas spirit begins to swarm\n[Verse 2]\nTwinkling lights\nA sight to behold\nStockings hung\nWaiting to be filled with gold\nGifts wrapped with love\nPiled high\nExcitement in the air\nYou can't deny\n[Chorus]\nWinter whispers in the wind\nJoy and love it brings\nLet's celebrate this season\nWith the ones we're missing",
"audio_url": "https://cdn1.suno.ai/b878a87b-a0db-4046-8ccd-ecd2fb3d4372.mp3",
"video_url": "https://cdn1.suno.ai/b878a87b-a0db-4046-8ccd-ecd2fb3d4372.mp4",
"created_at": "2024-05-11T07:33:05.430Z",
"model": "chirp-v3",
"prompt": "A song for Christmas",
"style": "pop"
}
]
}
可以看到结果中有一个 task_id
字段,其他的字段都和上文类似,通过该字段即可实现任务的关联。