suno-api icon indicating copy to clipboard operation
suno-api copied to clipboard

[FIX] Vercel Deploy

Open artokun opened this issue 11 months ago β€’ 42 comments

This PR fixes the Vercel deploy by using the internal playwright packaged used in Vercel VMs

Added new packages:

  • playwright-core
  • @sparticuz/chromium

Removed:

  • conflicting npm lock-file

Edited:

  • Dev vs Vercel deploy environments
  • User agent in prod

https://github.com/user-attachments/assets/37902dd3-21fc-4b5b-9b7c-efa212200212

artokun avatar Jan 30 '25 21:01 artokun

@artokun is attempting to deploy a commit to the Linkly AI LLC's projects Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Jan 30 '25 21:01 vercel[bot]

Closes https://github.com/gcui-art/suno-api/issues/226

artokun avatar Jan 30 '25 21:01 artokun

When trying out the fix on Vercel with an actual API call that is launching the browser, I get the following error:

Error generating custom audio: Error: The input directory "/var/task/.next/server/bin" does not exist.
    at Chromium.executablePath (/var/task/.next/server/chunks/279.js:87115:19)
    at SunoApi.launchBrowser (/var/task/.next/server/chunks/57.js:299:114)
    at SunoApi.getCaptcha (/var/task/.next/server/chunks/57.js:338:36)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SunoApi.generateSongs (/var/task/.next/server/chunks/57.js:543:20)
    at async SunoApi.custom_generate (/var/task/.next/server/chunks/57.js:514:24)
    at async POST (/var/task/.next/server/app/api/custom_generate/route.js:314:31)
    at async /var/task/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:42484
    at async eI.execute (/var/task/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:32486)
    at async eI.handle (/var/task/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:43737)

jonico avatar Jan 30 '25 22:01 jonico

Ah ok, let me take that for a spin then. might be a quick fix actually

artokun avatar Jan 31 '25 00:01 artokun

@jonico So I didn't have any issues myself on a live vercel deployment. Give this a try? (i'll keep the link live for 1 day, please don't abuse it ((too much πŸ˜‰ ))

curl --location 'suno-api-sigma-smoky.vercel.app/api/generate' \
--header 'Content-Type: application/json' \
--data '{
  "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,
  "model": "chirp-v4",
  "wait_audio": false
}'

Screenshot 2025-01-30 at 5 06 25β€―PM

artokun avatar Jan 31 '25 01:01 artokun

@jonico @blueeon what's the endpoint you guys were having trouble with? I can fix for that specific route if it's failing. I tested a handful of routes without issues. Also share what non-default ENVs you're using that are generic (non private key obvs)

artokun avatar Jan 31 '25 01:01 artokun

Are you sure that with the playwright-core package no 'fake app' songs are being generated? I had to switch to rebrowser-patches to fix this.

gohoski avatar Jan 31 '25 04:01 gohoski

@artokun just tested with your Vercel instance and got the same error:

image

jonico avatar Jan 31 '25 10:01 jonico

Hi, same for me. Both /custom_generate and /generate endpoints are also throwing the error:

{ "error": "Error: The input directory "/var/task/.next/server/bin" does not exist." }

I have tried both BROWSER_HEADLESS=true and BROWSER_HEADLESS=false. The rest non sensitive env vars:

BROWSER_LOCALE=en BROWSER_GHOST_CURSOR=false BROWSER=chromium

maindconsultingservices avatar Jan 31 '25 11:01 maindconsultingservices

Can you verify your build and env settings in Vercel? This is very bizzare, it's like it's not building or it using cached artifacts

Screenshot 2025-01-31 at 8 09 53β€―AM Screenshot 2025-01-31 at 8 10 13β€―AM

artokun avatar Jan 31 '25 16:01 artokun

I see custom_generate is indeed throwing an issue, investigating

artokun avatar Jan 31 '25 16:01 artokun

All default, I have changed nothing there:

image

maindconsultingservices avatar Jan 31 '25 17:01 maindconsultingservices

I have tested 4 endpoints:

  • get_limit & generate_lyrics OK
  • custom_generate & generate KO: { "error": "Error: The input directory "/var/task/.next/server/bin" does not exist." }

maindconsultingservices avatar Jan 31 '25 17:01 maindconsultingservices

Took a hot minute but I got it working with vercel, @gohoski you were right, it was making the fake app, but now it's making real songs with the package you introduced originally.

Screenshot 2025-01-31 at 2 43 35β€―PM

Generated Audio File https://audiopipe.suno.ai/?item_id=6fb10694-1ff4-4a1e-9b55-21c8da95c696

artokun avatar Jan 31 '25 22:01 artokun

Thanks for the fixes. I'm not getting that error anymore, but a vercel timeout. I had to change maxDuration to 60 in both src/app/api/custom_generate/route.ts and src/app/api/generate/route.ts because otherwise vercel throws an error (hobby/free tier maximum max time for serverless functions is 60 secs, https://vercel.com/docs/functions/runtimes#max-duration). I guess 60 secs is not enough at all, even if "wait_audio": false. I don't know if there could be a workaround by leveraging vercel's edge functions for generate and custom_generate, which are the most time consuming I think:

"Functions using the Edge runtime do not have a maximum duration. They must begin sending a response within 25 seconds and can continue streaming a response beyond that time."

maindconsultingservices avatar Feb 01 '25 08:02 maindconsultingservices

@artokun πŸ‘ Looks good, but please fix the npm package files to install rebrowser. Also, for a local deploy, it seems that we will install two browsersβ€”first the @Sparticuz/chromium, then the original Playwright one. Is there any way to fix this and make it so @Sparticuz/chromium would be installed only for Vercel? Maybe we can use the @Sparticuz/chromium-min package.

@maindconsultingservices To fix this, maybe we can develop a task system or a webhook as described in #228.

gohoski avatar Feb 01 '25 10:02 gohoski

Alright. I was able to:

  • Get it working with Docker + Local without worrying about any external packages when not in a vercel environment
  • Get it working inside a Vercel Deployment environment

I was NOT able to:

  • Not include the precompiled sparticuz package as a direct dependency, while it does add an extra 20mb to the package, I can't seem to load it conditionally and have it still work, it has to do with how it collects the path after installation most likely.

Let me know if there is anything else you'd like to see, otherwise I think I reached my wits end on how to get this to work accross all environments

artokun avatar Feb 01 '25 19:02 artokun

@artokun πŸ‘ Looks good, but please fix the npm package files to install rebrowser. Also, for a local deploy, it seems that we will install two browsersβ€”first the @Sparticuz/chromium, then the original Playwright one. Is there any way to fix this and make it so @Sparticuz/chromium would be installed only for Vercel? Maybe we can use the @Sparticuz/chromium-min package.

@maindconsultingservices To fix this, maybe we can develop a task system or a webhook as described in #228.

Maybe we can land this PR then move to a streamable format using vercel's RSC streamable pattern

artokun avatar Feb 01 '25 20:02 artokun

Is there any more feedback to get this PR in?

artokun avatar Feb 05 '25 02:02 artokun

Seems to be good, but why did we suddenly move from npm to pnpm?

gohoski avatar Feb 06 '25 16:02 gohoski

Seems to be good, but why did we suddenly move from npm to pnpm?

There was a package.lock and a pnpm-lock in the repo, you can't have both so I deleted the npm one assuming the only reason the pnpm one was there was because it was desired. I can switch to the other no problem. Let me know if this is the case

artokun avatar Feb 07 '25 15:02 artokun

pnpm hasn't been used here for like 8 months, so I doubt that blueeon has plans on moving to pnpm. I didn't know that you can't have both though, thanks for letting me know.

Right now I don't see any definite advantages of pnpm over other package managers. Right now npm serves everything we need, if we will have problems with it, then it will be reasonable to move. And we can actually just not move and run yarn/pnpm install.

gohoski avatar Feb 07 '25 18:02 gohoski

What is being used on Vercel though? pnpm or npm?

gohoski avatar Feb 08 '25 11:02 gohoski

What is being used on Vercel though? pnpm or npm?

At least when the pnpm update lock file is not up to date, Vercel complains about it not being up to date. I would recommend to test it out on vercel, it can be setup within minutes for free.

jonico avatar Feb 08 '25 15:02 jonico

I'll revert to npm

artokun avatar Feb 09 '25 18:02 artokun

Reverted back to NPM, deployed no issues on my end @gohoski

artokun avatar Feb 12 '25 17:02 artokun

Reverted back to NPM, deployed no issues on my end @gohoski

Hi, I got this error message on build logs: image

And this error on /api/custom_generate { "error": "Error: pOST: Executable doesn't exist at /home/sbx_user1051/.cache/ms-playwright/chromium_headless_shell-1148/chrome-linux/headless_shell\n╔═════════════════════════════════════════════════════════════════════════╗\nβ•‘ Looks like Playwright Test or Playwright was just installed or updated. β•‘\nβ•‘ Please run the following command to download new browsers: β•‘\nβ•‘ β•‘\nβ•‘ npx playwright install β•‘\nβ•‘ β•‘\nβ•‘ <3 Playwright Team β•‘\nβ•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•" }

And this is my build setting: image

codingneverending avatar Feb 15 '25 16:02 codingneverending

I'm now on this crazy train too and happy to help debug and test. I've got my own fork of this stood up with this PR. Everything seems to be going well on the Playwright side so far but I'm hitting a timeout on the Suno front.

{
    "error": "TimeoutError: pOST: Timeout 60000ms exceeded while waiting for event \"response\"\n=========================== logs ===========================\nwaiting for response \"**/api/project/**\\?**\"\n============================================================"
}

kalepail avatar Feb 17 '25 04:02 kalepail

Reverted back to NPM, deployed no issues on my end @gohoski

Hi, I got this error message on build logs:

And this error on /api/custom_generate { "error": "Error: pOST: Executable doesn't exist at /home/sbx_user1051/.cache/ms-playwright/chromium_headless_shell-1148/chrome-linux/headless_shell\n╔═════════════════════════════════════════════════════════════════════════╗\nβ•‘ Looks like Playwright Test or Playwright was just installed or updated. β•‘\nβ•‘ Please run the following command to download new browsers: β•‘\nβ•‘ β•‘\nβ•‘ npx playwright install β•‘\nβ•‘ β•‘\nβ•‘ <3 Playwright Team β•‘\nβ•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•" }

And this is my build setting: image

Don't set anything in vercel, let it handle it on its own

Screenshot 2025-02-17 at 8 16 51β€―AM

artokun avatar Feb 17 '25 16:02 artokun

I'm now on this crazy train too and happy to help debug and test. I've got my own fork of this stood up with this PR. Everything seems to be going well on the Playwright side so far but I'm hitting a timeout on the Suno front.

{
    "error": "TimeoutError: pOST: Timeout 60000ms exceeded while waiting for event \"response\"\n=========================== logs ===========================\nwaiting for response \"**/api/project/**\\?**\"\n============================================================"
}
  1. Captcha won't get solved under 60s, usually for me it takes anywhere between 90s - 240s
  2. To get 300s timeout you need to be on a PRO Vercel account

See README section: https://github.com/gcui-art/suno-api/pull/227/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R132-R147

artokun avatar Feb 17 '25 16:02 artokun