Next.js Discord

Discord Forum

task timed out

Unanswered
Californian posted this in #help-forum
Open in Discord
CalifornianOP
I'm running into this error on one of my api routes. what would be the easiest and most efficient fix for this?

9 Replies

@Californian I'm running into this error on one of my api routes. what would be the easiest and most efficient fix for this?
Dwarf Crocodile
You should probably not make a syncronous api route run for 10 seconds. It is horrible for user experience.

If you're deploying through vercel then through the pro plan you can extend the timeout to 5 minutes but unfortunately on the free plan 10 seconds is max.
CalifornianOP
ah i see
is there any free way to do it
would running it on the edge fix it?
Dwarf Crocodile
No the only free way is probably optimizing your code. What are you doing that is taking 10+ seconds?
Dwarf Crocodile
Yeah that will be hard because if you want to run everything on Vercel then the LLM request will be limited to 10 seconds. If there is no way to speed up the call to the LLM then i see no other way using the free Vercel plan. If the request must take above 10 seconds then I have no other answer except buying Pro or hosting a simple api on google cloud or aws using the free tier there that isn't under these restrictions.
if the request to the LLM can be streamed you can send the initial response within 10 seconds and vercel will allow the function to run for a longer time
see: https://vercel.com/docs/recipes/streaming-from-llm
CalifornianOP
oh yea i can easily stream it