MCPcopy
hub / github.com/gcui-art/suno-api / POST

Function POST

src/app/api/generate_stems/route.ts:8–98  ·  view source on GitHub ↗
(req: NextRequest)

Source from the content-addressed store, hash-verified

6export const dynamic = "force-dynamic";
7
8export async function POST(req: NextRequest) {
9 if (req.method === 'POST') {
10 try {
11 const body = await req.json();
12 const { audio_id } = body;
13
14 if (!audio_id) {
15 return new NextResponse(JSON.stringify({ error: 'Audio ID is required' }), {
16 status: 400,
17 headers: {
18 'Content-Type': 'application/json',
19 ...corsHeaders
20 }
21 });
22 }
23
24 const audioInfo = await (await sunoApi((await cookies()).toString()))
25 .generateStems(audio_id);
26
27 return new NextResponse(JSON.stringify(audioInfo), {
28 status: 200,
29 headers: {
30 'Content-Type': 'application/json',
31 ...corsHeaders
32 }
33 });
34 } catch (error: any) {
35 console.error('Error generating stems:', error);
36
37 // Handle different types of errors
38 if (error.response) {
39 // Axios error with response
40 console.error('Response error:', JSON.stringify(error.response.data));
41
42 if (error.response.status === 402) {
43 return new NextResponse(JSON.stringify({
44 error: error.response.data?.detail || 'Payment required'
45 }), {
46 status: 402,
47 headers: {
48 'Content-Type': 'application/json',
49 ...corsHeaders
50 }
51 });
52 }
53
54 return new NextResponse(JSON.stringify({
55 error: 'API Error: ' + (error.response.data?.detail || error.response.statusText || 'Unknown error')
56 }), {
57 status: error.response.status || 500,
58 headers: {
59 'Content-Type': 'application/json',
60 ...corsHeaders
61 }
62 });
63 } else if (error.request) {
64 // Axios error without response (network error, timeout, etc.)
65 console.error('Network error:', error.message);

Callers

nothing calls this directly

Calls 2

sunoApiFunction · 0.90
generateStemsMethod · 0.80

Tested by

no test coverage detected