Closed nilooy closed 8 months ago
Sorry, I don't see how this could be an AI SDK problem if it works fine without QStash. Perhaps it works locally because they detect you're in dev and handle things differently?
@nilooy did you manage to figure this out? I want to do something similar.
I'm using the AI SDK with OpenAI's Chat Completion to interface with SMS via Twilio, and need to accommodate for longer runs than 25s.
One solution as mentioned in Vercel's docs is streaming (to keep the Edge function alive), however since this is happening server-side to respond to SMS messages, it's sort of a "headless" environment, and I have no where to stream to — and streaming from Edge seems to be the only solution if I want to stay within the Next.js environment.
My thought was to use Upstash's QStash with callbacks and open a stream there, but I haven't tried to implement this yet. Maybe I'm missing something.
@rileybarabash It was such a pain as I was developing as indie dev to find a good solution for this. I am currently using Google cloud function and cloud task to achieve the background task with next.js but it's bit time consuming to setup. There's one paid(also free plan) solution called defer.run that integrates easily with next.js and vercel and it seems to be working pretty well for my colleagues. It has quite a long timeout but if you have too many concurrent task, it may get expensive. You may look at their pricing. I have tried quirrel and qstash both, none works with streaming and technically I understand the limitations. There's also this trending library called trigger.dev which seems nice and their long running jobs are in WIP. So may be not an option for now. Also netlify has long running jobs now but not for free plan also vercel now has timeout settings up to 5 min in pro plan. You have to decide on your budget, time and needs which one to use. I suggest to give defer.run a try.
Thank you for the thorough response! Going to look into defer.run.
I also wasn't aware that Vercel offered longer serverless timeouts on their Pro plan, that may be a decent option as well.
Looks like defer.run is not an option anymore unfortunately.
Defer is reaching the end of its service life on May 1, 2024
I actually got Defer running pretty well, it was easy to set up and manage. Very unfortunate to see them sunset.
The owner suggested migrating to trigger.dev. Join their Discord server, the answers you need should be there.
i am trying to use vercel edge function's streaming with ai sdk for long running job(up to 120s) with https://docs.upstash.com/qstash
it works perfectly locally but when deployed on vercel, it doesn't. it just stream for few milli seconds and stops. (no error) i'm not sure exactly where the issue is. At first glance seems like, the issue is on qstash but then it works locally and not in vercel, so it indicates that the issue might be there.
calling this to run queue:
the queue that run as background job