gcui-art / suno-api

Use API to call the music generation AI of suno.ai, and easily integrate it into agents like GPTs.
https://suno.gcui.ai
GNU Lesser General Public License v3.0
1.43k stars 329 forks source link

Internal Server Error deployed to vercel #136

Open yeetmaster69 opened 4 months ago

yeetmaster69 commented 4 months ago

I just deployed to vercel and am trying to call a POST request to /api/generate. Vercel logs say "TypeError: Cannot read properties of undefined (reading 'data')"

To Reproduce Steps to reproduce the behavior:

  1. Go to postman
  2. Use my URL = https://suno-api-six-henna.vercel.app/api/generate
  3. Add params "prompt", "make_instrumental", "wait_audio"
  4. See error

Expected behavior The response should have been successful

Screenshots

Screenshot 2024-07-16 at 5 00 48 PM Screenshot 2024-07-16 at 5 01 13 PM

Made request using POSTMan and tried from my machine as well.

Exoplanetarium commented 4 months ago

I have the same problem. Returns Error data: {"error": "Internal server error: undefined"} (my personal logs) even though the /api/get_limit endpoint works for the vercel server I'm using.

karpoveech commented 4 months ago

@yeetmaster69 @Exoplanetarium The /api/generate request handles "prompt" and other parameters in its body, not in the endpoint. Probably you should try including "prompt", booleans for "make_instrumental" and "wait_audio" in the request body.

Check src/app/api/generate/route.ts

Exoplanetarium commented 4 months ago

This is my steup for /api/generate, which used to work:

const url = "https://suno-api-three-xi.vercel.app/api/generate"; // not real deployment url
const headers = { "Content-Type": "application/json" };
const payload = {
  prompt,
  make_instrumental: instrumental, // instrumental is a prop that is always Boolean
  wait_audio: false,
};

...

const response = await axios.post(url, payload, { headers });

As of about last week, it seems to have stopped working and returned this undefined error. I have tried taking only the _client part of the cookie and redeploying, using a different account cookie, and logging each prop to make sure they are of the correct type.

karpoveech commented 4 months ago

@Exoplanetarium the /api/generate works as expected right now if you properly set the SUNO_COOKIE in the .env file. You may check correctness of SUNO_COOKIE by calling api/get_limit query, and in case it returns 500, you're most likely to have an invalid cookie set in the .env file.

I myself found a way to troubleshoot this by logging in to the proper account on suno.com, then finding and setting the cookie in the .env file so the file looks like this: SUNO_COOKIE=__client=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.ey ...the remaining part of the cookie...

Exoplanetarium commented 4 months ago

@karpoveech I checked the /api/get_limit query and it returned

{
  "credits_left": 50,
  "period": null,
  "monthly_limit": 50,
  "monthly_usage": 0
}

so it should work, but calling /api/generate returns the 500 error: undefined. I'm deploying this api on Vercel, so maybe that causes issues?

Update: I looked into the Vercel logs but all I could get was Error generating custom audio: ""

karpoveech commented 4 months ago

@Exoplanetarium commit here 14e843a should fix the error logging for you. In the current API version it logs Error generating custom audio every time it encounters any error but without any description. Now I extended this log so it contains the error message and returns this error message in the query response as well

Exoplanetarium commented 3 months ago

Thank you for that commit, I've added it to my clone of suno-api. Now it gives me the Error: Failed to get session id, you may need to update the SUNO_COOKIE. However, I'm still not sure how to resolve the error, I've tried many different sections of the cookie including inserting everything after __client but it hasn't worked so far. What part of the cookie works?

karpoveech commented 3 months ago

Make sure you have only one .env file in the repository root. As for the cookie itself, as I've said before, the contents of the .env file should look like this: SUNO_COOKIE=__client=ey.............ey..............tm........... Instead of dots, these should be symbols, my cookie string is more than 500 chars long without __client=.

Note that cookie must not contain the ; symbol which you might've accidentally copied from the browser's dev tools. You can decode the cookie at https://jwt.io and see if it's malformed.

I don't see any other reasons the API isn't working for you

Exoplanetarium commented 3 months ago

Unfortunately, nothing you've suggested has worked. The closest I got was a cookie the api did accept (/api/get_limit returned non-error) but I received a 403 Error when trying to call /api/generate. I literally have no idea why or how this is happening, and I would appreciate other perspectives on my problem from the other devs to help me debug.

h85579049 commented 3 months ago

Same error with me, not working for me.

wocall commented 3 months ago

Same error with me,:( can Get but can't Post。

wocall commented 3 months ago

It is possible that the account has been banned. I couldn't create it successfully on the official website today.

tahercoolguy commented 2 months ago

Yes @wocall you are right account has been banned . I tried three different account all banned . After 7 days .