Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Next.JS API timeout

My API returns me a result after 10 minute later because of some limitations of another API. In localhost, I can wait 10 minutes and receive my data successfully but in Vercel, my API returns me 504 which means timeout error. How can I disable that?

enter image description here

like image 601
questiontoansw Avatar asked Apr 11 '26 06:04

questiontoansw


1 Answers

This is due to serverless functions execution time limits on Vercel. The time limit in the hobby plan is 10 seconds, and 60 (now 15) seconds in the pro plan, so you're definitely hitting the time limit in case of your API on Vercel and whatever changes you make in the code, it will fail on Vercel if it exceeds the limit.

You can either upgrade your plan to Pro if you're on Hobby, this will give you the ability to run serverless functions with time limits up to 5 minutes by exporting a maxDuration variable with time in seconds in your function file, as mentioned by Vercel here

Based on your feedback, we’re improving Serverless Functions as follows: Pro customers can now run longer functions for up to 5 minutes. Pro customers default function timeout will be reduced to 15 seconds on October 1st.

Or if your API takes 10 minutes, you might want to think of other ways for making your API call, like making the API call from a node.js backend instead of serverless, or better, use web sockets or a message broker instead if it takes that much time.

like image 195
MohamedZh Avatar answered Apr 12 '26 20:04

MohamedZh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!