<div align="center">
<h1 align="center"">
Suno AI API
</h1>
<p>Use API to call the music generation AI of Suno.ai and easily integrate it into agents like GPTs.</p>
<p>ð We update quickly, please star.</p>
</div>
<p align="center">
<a target="_blank" href="./README.md">English</a>
| <a target="_blank" href="./README_CN.md">ç®ä½ä¸æ</a>
| <a target="_blank" href="https://suno.gcui.art">Demo</a>
| <a target="_blank" href="https://suno.gcui.art/docs">Docs</a>
| <a target="_blank" href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fgcui-art%2Fsuno-api&env=SUNO_COOKIE&project-name=suno-api&repository-name=suno-api">Deploy with Vercel</a>
</p>
<p align="center">
<a href="https://www.producthunt.com/products/gcui-art-suno-api-open-source-sunoai-api/reviews?utm_source=badge-product_review&utm_medium=badge&utm_souce=badge-gcui-art-suno-api-open-source-sunoai-api" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/product_review.svg?product_id=577408&theme=light" alt="gcui-art/suno-api:Open-source SunoAI API - Use API to call the music generation AI of suno.ai. | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
</p>
![suno-api banner](https://github.com/gcui-art/suno-api/blob/main/public/suno-banner.png)
## Introduction
Suno.ai v3 is an amazing AI music service. Although the official API is not yet available, we couldn't wait to integrate its capabilities somewhere.
We discovered that some users have similar needs, so we decided to open-source this project, hoping you'll like it.
## Demo
We have deployed an example bound to a free Suno account, so it has daily usage limits, but you can see how it runs:
[suno.gcui.art](https://suno.gcui.art)
## Features
- Perfectly implements the creation API from app.suno.ai
- Automatically keep the account active.
- Compatible with the format of OpenAIâs `/v1/chat/completions` API.
- Supports Custom Mode
- One-click deployment to Vercel
- In addition to the standard API, it also adapts to the API Schema of Agent platforms like GPTs and Coze, so you can use it as a tool/plugin/Action for LLMs and integrate it into any AI Agent.
- Permissive open-source license, allowing you to freely integrate and modify.
## Getting Started
### 1. Obtain the cookie of your app.suno.ai account
1. Head over to [app.suno.ai](https://app.suno.ai) using your browser.
2. Open up the browser console: hit `F12` or access the `Developer Tools`.
3. Navigate to the `Network tab`.
4. Give the page a quick refresh.
5. Identify the request that includes the keyword `client?_clerk_js_version`.
6. Click on it and switch over to the `Header` tab.
7. Locate the `Cookie` section, hover your mouse over it, and copy the value of the Cookie.
![get cookie](https://github.com/gcui-art/suno-api/blob/main/public/get-cookie-demo.gif)
### 2. Clone and deploy this project
You can choose your preferred deployment method:
#### Deploy to Vercel
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fgcui-art%2Fsuno-api&env=SUNO_COOKIE&project-name=suno-api&repository-name=suno-api)
#### Run locally
```bash
git clone https://github.com/gcui-art/suno-api.git
cd suno-api
npm install
```
Alternatively, you can use [Docker Compose](https://docs.docker.com/compose/)
```bash
docker compose build && docker compose up
```
### 3. Configure suno-api
- If deployed to Vercel, please add an environment variable `SUNO_COOKIE` in the Vercel dashboard, with the value of the cookie obtained in the first step.
- If youâre running this locally, be sure to add the following to your `.env` file:
```bash
SUNO_COOKIE=<your-cookie>
```
### 4. Run suno api
- If youâve deployed to Vercel:
- Please click on Deploy in the Vercel dashboard and wait for the deployment to be successful.
- Visit the `https://<vercel-assigned-domain>/api/get_limit` API for testing.
- If running locally:
- Run `npm run dev`.
- Visit the `http://localhost:3000/api/get_limit` API for testing.
- If the following result is returned:
```json
{
"credits_left": 50,
"period": "day",
"monthly_limit": 50,
"monthly_usage": 50
}
```
it means the program is running normally.
### 5. Use Suno API
You can check out the detailed API documentation at :
[suno.gcui.art/docs](https://suno.gcui.art/docs)
## API Reference
Suno API currently mainly implements the following APIs:
```bash
- `/api/generate`: Generate music
- `/v1/chat/completions`: Generate music - Call the generate API in a format that works with OpenAIâs API.
- `/api/custom_generate`: Generate music (Custom Mode, support setting lyrics, music style, title, etc.)
- `/api/generate_lyrics`: Generate lyrics based on prompt
- `/api/get`: Get music information based on the id. Use â,â to separate multiple ids.
If no IDs are provided, all music will be returned.
- `/api/get_limit`: Get quota Info
```
For more detailed documentation, please check out the demo site:
[suno.gcui.art/docs](https://suno.gcui.art/docs)
## API Integration Code Example
### Python
```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 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
```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 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]
没有合适的资源?快使用搜索试试~ 我知道了~
Suno AI API学习参考
共48个文件
ts:9个
tsx:8个
json:6个
需积分: 5 0 下载量 145 浏览量
2024-04-21
12:12:24
上传
评论
收藏 49.18MB ZIP 举报
温馨提示
Suno AI API学习参考
资源推荐
资源详情
资源评论
收起资源包目录
suno-api-main1.zip (48个子文件)
suno-api-main
README_CN.md 9KB
.github
ISSUE_TEMPLATE
feature_request.md 595B
bug_report.md 665B
新功能.md 666B
.env.example 32B
src
lib
SunoApi.ts 12KB
utils.ts 845B
app
v1
chat
completions
route.ts 2KB
api
generate_lyrics
route.ts 2KB
generate
route.ts 2KB
get_limit
route.ts 1KB
custom_generate
route.ts 2KB
get
route.ts 1KB
docs
page.tsx 2KB
swagger-suno-api.json 14KB
components
Header.tsx 2KB
Footer.tsx 807B
Section.tsx 405B
Logo.tsx 524B
Swagger.tsx 316B
favicon.ico 15KB
layout.tsx 915B
page.tsx 5KB
globals.css 442B
LICENSE 7KB
docker-compose.yml 122B
package.json 1KB
public
vercel.svg 629B
github-logo.webp 7KB
get-cookie-demo.mp4 6.45MB
suno-banner.png 80KB
next.svg 1KB
get-cookie-demo.gif 42.51MB
github-mark.png 6KB
swagger-suno-api.json 7KB
next.config.mjs 92B
tailwind.config.ts 553B
Dockerfile 310B
package-lock.json 335KB
pnpm-lock.yaml 240KB
.eslintrc.json 40B
.gitignore 403B
tsconfig.json 578B
.dockerignore 453B
README.md 9KB
FUNDING.yml 870B
icon.png 4KB
postcss.config.js 83B
共 48 条
- 1
资源评论
Kwan的解忧杂货铺
- 粉丝: 2w+
- 资源: 3699
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功