feat: Add new API

- Add a new API generate_lyrics.
- Update the documentation.
- Modify the API version.
This commit is contained in:
blueeon
2024-03-31 16:44:07 +08:00
parent 721bfecb77
commit b3be1185a9
8 changed files with 224 additions and 93 deletions
+42
View File
@@ -0,0 +1,42 @@
import { NextResponse, NextRequest } from "next/server";
import { sunoApi } from "@/lib/SunoApi";
export const dynamic = "force-dynamic";
export async function POST(req: NextRequest) {
if (req.method === 'POST') {
try {
const body = await req.json();
const { prompt } = body;
if (!prompt) {
return new NextResponse(JSON.stringify({ error: 'Prompt is required' }), {
status: 400,
headers: { 'Content-Type': 'application/json' }
});
}
const lyrics = await (await sunoApi).generateLyrics(prompt);
return new NextResponse(JSON.stringify(lyrics), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
} catch (error: any) {
console.error('Error generating lyrics:', JSON.stringify(error.response.data));
if (error.response.status === 402) {
return new NextResponse(JSON.stringify({ error: error.response.data.detail }), {
status: 402,
headers: { 'Content-Type': 'application/json' }
});
}
return new NextResponse(JSON.stringify({ error: 'Internal server error: ' + JSON.stringify(error.response.data.detail) }), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
}
} else {
return new NextResponse('Method Not Allowed', {
headers: { Allow: 'POST' },
status: 405
});
}
}
+5 -2
View File
@@ -21,10 +21,13 @@ Suno API currently mainly implements the following APIs:
\`\`\`bash
- \`/api/generate\`: Generate music
- \`/api/custom_generate\`: Generate music (Custom Mode, support setting lyrics,
music style, title, etc.)
- \`/api/get\`: Get music Info
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
\`\`\`
Feel free to explore the detailed API parameters and conduct tests on this page.
> Please note:
+54 -4
View File
@@ -3,7 +3,7 @@
"info": {
"title": "suno-api",
"description": "Use API to call the music generation service of Suno.ai and easily integrate it into agents like GPTs.",
"version": "1.0.0"
"version": "1.1.0"
},
"tags": [
{
@@ -137,6 +137,56 @@
}
}
},
"/api/generate_lyrics": {
"post": {
"summary": "Generate lyrics based on Prompt.",
"description": "Generate lyrics based on Prompt.",
"tags": ["default"],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"required": ["prompt"],
"properties": {
"prompt": {
"type": "string",
"description": "Prompt",
"example": "A soothing lullaby"
}
}
}
}
}
},
"responses": {
"200": {
"description": "success",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "Lyrics"
},
"title": {
"type": "string",
"description": "music title"
},
"status": {
"type": "string",
"description": "Status"
}
}
}
}
}
}
}
}
},
"/api/get": {
"get": {
"summary": "Get audio information",
@@ -146,8 +196,8 @@
{
"in": "query",
"name": "ids",
"description": "Audio IDs, separated by commas.",
"required": true,
"description": "Audio IDs, separated by commas. Leave blank to return a list of all music.",
"required": false,
"schema": {
"type": "string"
}
@@ -297,7 +347,7 @@
}
},
"title": "audio_info",
"description": "audio info"
"description": "Audio Info"
}
}
}
+20 -17
View File
@@ -7,23 +7,24 @@ export default function Home() {
const markdown = `
---
## Introduction
## 👋 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.
👉 We update quickly, please Star us on Github: [github.com/gcui-art/suno-api](https://github.com/gcui-art/suno-api)
We update quickly, please star us on Github: [github.com/gcui-art/suno-api](https://github.com/gcui-art/suno-api)
## Features
## 🌟 Features
- Perfectly implements the creation API from \`app.suno.ai\`
- Automatically keep the account active.
- 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
## 🚀 Getting Started
### 1. Obtain the cookie of your app.suno.ai account
@@ -60,9 +61,9 @@ npm install
- If youre running this locally, be sure to add the following to your \`.env\` file:
\`\`\`bash
SUNO_COOKIE=<your-cookie>
\`\`\`
\`\`\`bash
SUNO_COOKIE=<your-cookie>
\`\`\`
### 4. Run suno-api
@@ -74,14 +75,14 @@ SUNO_COOKIE=<your-cookie>
- 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
}
\`\`\`
\`\`\`json
{
"credits_left": 50,
"period": "day",
"monthly_limit": 50,
"monthly_usage": 50
}
\`\`\`
it means the program is running normally.
@@ -89,7 +90,7 @@ it means the program is running normally.
You can check out the detailed API documentation at [suno.gcui.art/docs](https://suno.gcui.art/docs).
## API Reference
## 📚 API Reference
Suno API currently mainly implements the following APIs:
@@ -97,7 +98,9 @@ Suno API currently mainly implements the following APIs:
- \`/api/generate\`: Generate music
- \`/api/custom_generate\`: Generate music (Custom Mode, support setting lyrics,
music style, title, etc.)
- \`/api/get\`: Get music Info
- \`/api/generate_lyrics\`: Generate lyrics based on prompt
- \`/api/get\`: Get music list
- \`/api/get?ids=\`: Get music Info by id, separate multiple id with ",".
- \`/api/get_limit\`: Get quota Info
\`\`\`