Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Vercel Deploy #227

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

[FIX] Vercel Deploy #227

wants to merge 19 commits into from

Conversation

artokun
Copy link

@artokun artokun commented Jan 30, 2025

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
Screen.Recording.2025-01-30.at.1.43.06.PM.mov

Copy link

vercel bot commented Jan 30, 2025

@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.

@artokun
Copy link
Author

artokun commented Jan 30, 2025

Closes #226

@jonico
Copy link
Contributor

jonico commented Jan 30, 2025

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)

@artokun
Copy link
Author

artokun commented Jan 31, 2025

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

@artokun
Copy link
Author

artokun commented Jan 31, 2025

@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
Copy link
Author

artokun commented Jan 31, 2025

@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)

@gohoski
Copy link
Contributor

gohoski commented Jan 31, 2025

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.

@jonico
Copy link
Contributor

jonico commented Jan 31, 2025

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

image

@maindconsultingservices

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

@artokun
Copy link
Author

artokun commented Jan 31, 2025

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
Copy link
Author

artokun commented Jan 31, 2025

I see custom_generate is indeed throwing an issue, investigating

@maindconsultingservices

All default, I have changed nothing there:

image

@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."
    }

@artokun
Copy link
Author

artokun commented Jan 31, 2025

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

@maindconsultingservices
Copy link

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."

@gohoski
Copy link
Contributor

gohoski commented Feb 1, 2025

@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.

@artokun
Copy link
Author

artokun commented Feb 1, 2025

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
Copy link
Author

artokun commented Feb 1, 2025

@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
Copy link
Author

artokun commented Feb 5, 2025

Is there any more feedback to get this PR in?

@gohoski
Copy link
Contributor

gohoski commented Feb 6, 2025

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

@artokun
Copy link
Author

artokun commented Feb 7, 2025

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

@gohoski
Copy link
Contributor

gohoski commented Feb 7, 2025

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
Copy link
Contributor

gohoski commented Feb 8, 2025

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

@jonico
Copy link
Contributor

jonico commented Feb 8, 2025

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.

@artokun
Copy link
Author

artokun commented Feb 9, 2025

I'll revert to npm

@artokun
Copy link
Author

artokun commented Feb 12, 2025

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

@codingneverending
Copy link

codingneverending commented Feb 15, 2025

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

@kalepail
Copy link

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============================================================"
}

@artokun
Copy link
Author

artokun commented Feb 17, 2025

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
Copy link
Author

artokun commented Feb 17, 2025

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

@kalepail
Copy link

kalepail commented Feb 17, 2025

I am on a pro account and have set those params. Again this is an error coming from SunoApi.ts before it ever gets to the captcha. It's error'ing on this line:

await page.waitForResponse('**/api/project/**\\?**', { timeout: 60000 }); // wait for song list API call

Looking at my Vercel logs I see:

{"level":30,"time":1739813899351,"pid":3,"hostname":"169.254.84.187","msg":"Waiting for Suno interface to load"}

Hangs there for 60 seconds and then times out

@kalepail
Copy link

Seems like the Suno interface just gets stuck loading indefinitely

@kalepail
Copy link

2ASJ-sWsq
Based off this screenshot it doesn't look like anything is loading in the background at least in the case of the Cloudflare captcha so that await will never pass. (got this screenshot by just dumb waiting 10 seconds then capturing a screenshot)

@kalepail
Copy link

Unless I'm mistaken there are two issues here:

a) the service assumes the captcha is not already showing and tries to trigger it (but if it is already showing the data it's waiting on never arrives thus the 60 second hang)
b) and/or the captcha is assumed to never be a Cloudflare turnstile captcha and awaits on an image based captcha which it may not be (which causes the waitForRequests method to hang)

@gohoski
Copy link
Contributor

gohoski commented Feb 23, 2025

The Cloudflare Turnstile CAPTCHA is very new for me. I almost never haven't seen it both on my main PC and my server. AFAIK, it is being shown only on IPs that are marked as a 'hosting'/VPN or such.

The only way to solve this CAPTCHA is to develop a library that smoothly controls the mouse without any evaluations on the page, as they are being detected as seen in ghost-cursor-playwright. If we would rapidly click on the button with page.click, Turnstile would detect this and not solve the CAPTCHA.

You can use the Browser Automation Studio's algorithm located in the source code of their old version. I will probably develop it on the next week, as I'm afraid that I will get it also.

@kalepail
Copy link

It's actually really easy to solve with 2captcha. You just grab the sitekey and pass it to the hcaptcha endpoint. The token you get back works for the generation endpoint. The problem I'm having now is every single request pops up a captcha and when generating 100% of my gens have the "this is a fake app" lyrics.

(I built my own version of this service for Cloudflare Workers fwiw)

@kalepail
Copy link

Seems if we got the headers a cookies right we could get the service thinking we were a mobile session and avoid captchas altogether or at least avoid detection off lack of mouse movement. (No mice on mobile)

@gohoski
Copy link
Contributor

gohoski commented Feb 28, 2025

@kalepail This is why I went with the image coordinates endpoint instead. The hCaptcha endpoint does not support the 'hidden' hCaptcha variant, as said by the 2Captcha Support team.

I might look into emulating a mobile device instead, HOWEVER, it is actually very hard to emulate a mobile device and not get detected. There always will be leaks such as navigator properties, and even then mobile devices still get a CAPTCHA—hell, even the mobile app, which I 'reverse engineered' (kinda) via HTTP Toolkit, has the hCaptcha. It doesn't have Cloudflare Turnstile though, so that's why I went with that route when the hCaptcha is not needed.

To solve the Cloudflare CAPTCHA, it seems that I need to move to Kaliiiiiiiiii-Vinyzu/patchright-nodejs and develop a good enough library to automatically control the mouse as a human. However, if you are on a Windows machine that has already used Suno before, you'll probably not get it right now.

@gohoski
Copy link
Contributor

gohoski commented Mar 1, 2025

If you get a Cloudflare challenge page (suno.com needs to review the security of your connection before proceeding), add __client_uat=1737406840; __client_uat_U9tcbTPE=1737406840; to the end of your cookies

@gohoski
Copy link
Contributor

gohoski commented Mar 1, 2025

After a lot of digging, I have decided that it is going to be too unsuccessful and unmaintainable to try to solve the Cloudflare Turnstile CAPTCHA itself. If you happen to have this CAPTCHA, your best bet is to use proxies, try to use Suno itself on the machine for a few tries, change the user-agent, etc. However, I will be making a PR to support proxies for this matter.

Maybe it is possible to solve the Cloudflare CAPTCHA using 2Captcha's corresponding endpoint, but I'm not sure. I will give it a shot though.

@mzimmer52
Copy link

If you get a Cloudflare challenge page (suno.com needs to review the security of your connection before proceeding), add __client_uat=1737406840; __client_uat_U9tcbTPE=1737406840; to the end of your cookies

This works, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants