✨ feat: add extend api
- Added extend API - Added documentation for extend API
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { NextResponse, NextRequest } from "next/server";
|
||||
import { sunoApi } from "@/lib/SunoApi";
|
||||
import { corsHeaders } from "@/lib/utils";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
if (req.method === 'POST') {
|
||||
try {
|
||||
const body = await req.json();
|
||||
const { audio_id, prompt, continue_at, tags, title } = body;
|
||||
console.log(body)
|
||||
|
||||
if (!audio_id) {
|
||||
return new NextResponse(JSON.stringify({ error: 'Audio ID is required' }), {
|
||||
status: 400,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...corsHeaders
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const audioInfo = await (await sunoApi)
|
||||
.extendAudio(audio_id, prompt, continue_at, tags, title);
|
||||
|
||||
return new NextResponse(JSON.stringify(audioInfo), {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...corsHeaders
|
||||
}
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('Error extend audio:', 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',
|
||||
...corsHeaders
|
||||
}
|
||||
});
|
||||
}
|
||||
return new NextResponse(JSON.stringify({ error: 'Internal server error: ' + JSON.stringify(error.response.data.detail) }), {
|
||||
status: 500,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...corsHeaders
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return new NextResponse('Method Not Allowed', {
|
||||
headers: {
|
||||
Allow: 'POST',
|
||||
...corsHeaders
|
||||
},
|
||||
status: 405
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function OPTIONS(request: Request) {
|
||||
return new Response(null, {
|
||||
status: 200,
|
||||
headers: corsHeaders
|
||||
});
|
||||
}
|
||||
@@ -28,6 +28,7 @@ export default function Docs() {
|
||||
- \`/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
|
||||
- \`/api/extend_audio\`: Extend audio length
|
||||
\`\`\`
|
||||
|
||||
Feel free to explore the detailed API parameters and conduct tests on this page.
|
||||
|
||||
@@ -179,6 +179,50 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/extend_audio": {
|
||||
"post": {
|
||||
"summary": "Extend audio length.",
|
||||
"description": "Extend audio length.",
|
||||
"tags": ["default"],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"required": ["audio_id"],
|
||||
"properties": {
|
||||
"audio_id": {
|
||||
"type": "string",
|
||||
"description": "The ID of the audio clip to extend.",
|
||||
"example": "e76498dc-6ab4-4a10-a19f-8a095790e28d"
|
||||
},
|
||||
"prompt": {
|
||||
"type": "string",
|
||||
"description": "Detailed prompt, including information such as music lyrics.",
|
||||
"example": ""
|
||||
},
|
||||
"continue_at": {
|
||||
"type": "string",
|
||||
"description": "Extend a new clip from a song at mm:ss(e.g. 00:30). Default extends from the end of the song.",
|
||||
"example": "109.96"
|
||||
},
|
||||
"title": {
|
||||
"type": "string",
|
||||
"description": "Music title",
|
||||
"example": ""
|
||||
},
|
||||
"tags": {
|
||||
"type": "string",
|
||||
"description": "Music genre",
|
||||
"example": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/generate_lyrics": {
|
||||
"post": {
|
||||
"summary": "Generate lyrics based on Prompt.",
|
||||
|
||||
@@ -105,6 +105,7 @@ Suno API currently mainly implements the following APIs:
|
||||
- \`/api/get\`: Get music list
|
||||
- \`/api/get?ids=\`: Get music Info by id, separate multiple id with ",".
|
||||
- \`/api/get_limit\`: Get quota Info
|
||||
- \`/api/extend_audio\`: Extend audio length
|
||||
\`\`\`
|
||||
|
||||
For more detailed documentation, please check out the demo site:
|
||||
|
||||
Reference in New Issue
Block a user