Suno AI API
使用API调用suno.ai的音乐生成AI,并且可以轻松集成到GPTs等代理中。
👉我们更新很快,欢迎star。
English |简体中文 | русский |演示 |文档 |一键部署到Vercel
🔥 我们的新项目:ReadPo - 10 倍加速您的阅读和写作!
简介
Suno.ai v3 是一个令人惊叹的 AI 音乐服务,虽然官方还没有开放 API,但我们已经迫不及待的想在某些地方集成它的能力。我们发现有些用户也有类似的需求,所以我们将这个项目开源了,希望你们喜欢。
演示
我们部署了一个示例,绑定了一个免费的 suno 账号,所以它每天都有使用限制,但你可以看到它运行起来的样子: suno.gcui.ai
特征
- 完美的实现了app.suno.ai中的大部分API
- 自动保持账号活跃
- 兼容OpenAI的
/v1/chat/completions
API格式 - 支持自定义模式
- 一键到配置 vercel
- 除了标准 API,还配备了 GPTs、coze 等 Agent 平台的 API Schema,所以你可以把它当做一个 LLM 的工具/插件/Action,集成到任何 AI Agent 中。
- 众多的开源协议,您可以轻松的集成和修改。
如何开始使用?
1.获取你的app.suno.ai账号的cookie
- 浏览器访问app.suno.ai
- 打开浏览器的控制台:单击
F12
或者开发者工具
- 选择
网络
标签 - 刷新页面
- 找到包含
client?_clerk_js_version
关键词的请求 - 点击并切换到
Header
标签 - 找到
Cookie
部分,鼠标复制 Cookie 的值
2.克隆并部署本项目
您可以选择自己喜欢的部署方式:
部署到Vercel
本地运行
git clone https://github.com/gcui-art/suno-api.git
cd suno-api
npm install
或者,你也可以使用Docker Compose
docker compose build && docker compose up
3.配置suno-api
- 如果部署到了Vercel,请在Vercel后台,添加环境变量
SUNO_COOKIE
,达到第一步获取的cookie。 - 如果在本地运行,请在 .env 文件中添加:
SUNO_COOKIE=<your-cookie>
4. 运行suno api
- 如果部署到了Vercel:
- 请在Vercel后台,点击
Deploy
,等待配置成功。 - 访问
https://<vercel分配的域名>/api/get_limit
API进行测试
- 请在Vercel后台,点击
- 如果在本地运行:
- 请运行
npm run dev
- 访问
http://localhost:3000/api/get_limit
API进行测试
- 请运行
- 如果返回以下结果:
{
"credits_left": 0,
"period": "string",
"monthly_limit": 0,
"monthly_usage": 0
}
则已经正常运行。
5.使用Suno API
您可以在suno.gcui.ai查看详细的API文档,并在线测试。
API说明
Suno API 目前主要实现了以下API:
- `/api/generate`: 创建音乐
- `/v1/chat/completions`: 创建音乐 - 用OpenAI API 兼容的格式调用 generate API
- `/api/custom_generate`: 创建音乐(自定义模式,支持设置歌词、音乐风格、设置标题等)
- `/api/generate_lyrics`: 根据Prompt创建歌词
- `/api/get`: 根据id获取音乐信息。获取多个请用","分隔,不传ids则返回所有音乐
- `/api/get_limit`: 获取配额信息
- `/api/extend_audio`: 在一首音乐的基础上,扩展音乐长度
- `/api/generate_stems`: 制作主干轨道(单独的音频和音乐轨道
- `/api/get_aligned_lyrics`: 获取歌词中每个单词的时间戳列表
- `/api/clip`: 检索特定音乐的信息
- `/api/concat`: 合并音乐,将扩展后的音乐和原始音乐合并
详细文档请查看演示站点: suno.gcui.ai/docs
API 集成代码示例
Python
import time
import requests
# replace your vercel domain
base_url = 'http://localhost:3000'
def custom_generate_audio(payload):
url = f"{base_url}/api/custom_generate"
response = requests.post(url, json=payload, headers={'Content-Type': 'application/json'})
return response.json()
def extend_audio(payload):
url = f"{base_url}/api/extend_audio"
response = requests.post(url, json=payload, headers={'Content-Type': 'application/json'})
return response.json()
def generate_audio_by_prompt(payload):
url = f"{base_url}/api/generate"
response = requests.post(url, json=payload, headers={'Content-Type': 'application/json'})
return response.json()
def get_audio_information(audio_ids):
url = f"{base_url}/api/get?ids={audio_ids}"
response = requests.get(url)
return response.json()
def get_quota_information():
url = f"{base_url}/api/get_limit"
response = requests.get(url)
return response.json()
if __name__ == '__main__':
data = generate_audio_by_prompt({
"prompt": "A popular heavy metal song about war, sung by a deep-voiced male singer, slowly and melodiously. The lyrics depict the sorrow of people after the war.",
"make_instrumental": False,
"wait_audio": False
})
ids = f"{data[0]['id']},{data[1]['id']}"
print(f"ids: {ids}")
for _ in range(60):
data = get_audio_information(ids)
if data[0]["status"] == 'streaming':
print(f"{data[0]['id']} ==> {data[0]['audio_url']}")
print(f"{data[1]['id']} ==> {data[1]['audio_url']}")
break
# sleep 5s
time.sleep(5)
JS
const axios = require("axios");
// replace your vercel domain
const baseUrl = "http://localhost:3000";
async function customGenerateAudio(payload) {
const url = `${baseUrl}/api/custom_generate`;
const response = await axios.post(url, payload, {
headers: { "Content-Type": "application/json" },
});
return response.data;
}
async function generateAudioByPrompt(payload) {
const url = `${baseUrl}/api/generate`;
const response = await axios.post(url, payload, {
headers: { "Content-Type": "application/json" },
});
return response.data;
}
async function extendAudio(payload) {
const url = `${baseUrl}/api/extend_audio`;
const response = await axios.post(url, payload, {
headers: { "Content-Type": "application/json" },
});
return response.data;
}
async function getAudioInformation(audioIds) {
const url = `${baseUrl}/api/get?ids=${audioIds}`;
const response = await axios.get(url);
return response.data;
}
async function getQuotaInformation() {
const url = `${baseUrl}/api/get_limit`;
const response = await axios.get(url);
return response.data;
}
async function main() {
const data = await generateAudioByPrompt({
prompt:
"A popular heavy metal song about war, sung by a deep-voiced male singer, slowly and melodiously. The lyrics depict the sorrow of people after the war.",
make_instrumental: false,
wait_audio: false,
});
const ids = `${data[0].id},${data[1].id}`;
console.log(`ids: ${ids}`);
for (let i = 0; i < 60; i++) {
const data = await getAudioInformation(ids);
if (data[0].status === "streaming") {
console.log(`${data[0].id} ==> ${data[0].audio_url}`);
console.log(`${data[1].id} ==> ${data[1].audio_url}`);
break;
}
// sleep 5s
await new Promise((resolve) => setTimeout(resolve, 5000));
}
}
main();
集成到常见的自定义代理中
当做一个工具/插件/操作时,你可以把 suno ai 集成到你的 AI Agent 中。
集成到 GPT
[即将推出...]
集成到coze
[即将推出...]
集成到LangChain
[即将推出...]
贡献指南
您有四种方式支持本项目:
- Fork 项目并提交 PR:我们欢迎任何让这个组件和编辑器变得更好的 PR。
- 提交问题:我们欢迎任何合理的建议、错误反馈。
- 转发:在项目的顶部我们放置了赞助按钮,如果这个项目对您有帮助,您可以请我们喝一杯,干杯☕。
- 推荐:向其他人推荐本项目;点击星星;使用本项目后放置外链。
许可证
LGPL-3.0 或更高版本
您有问题/建议/困难/错误吗?
我们使用 Github 的问题来管理这些反馈,你可以提交一个。我们会经常来处理。
相关链接
- 项目仓库:github.com/gcui-art/suno-api
- Suno.ai 官网: suno.ai
- 演示站点:suno.gcui.ai
- Readpo:ReadPo 是人工智能驱动的读写助手。以闪电般的速度收集信息并筛选,创建引人入胜的内容。
声明
suno-api 是一个非官方的开源项目,供初学者学习和研究使用。