Hi there, I have a serverless function on the Pro plan that has a default max duration of 15 seconds. I'd like to increase this to 1 minute but neither of the 2 approaches I've tried seem to be working. I tried setting maxDuration as a constant in the api route handler typescript file. I also tried setting it using vercel.json config. Any help is appreciated.
#Serverless functions maxDuration not working in Vercel
1 messages · Page 1 of 1 (latest)
Hi @thorny fable. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Based on the information provided, you've taken the correct steps to increase the maxDuration of your serverless function. However, there might be some issues with how you've implemented these steps. Let's go through them:
- Setting
maxDurationin the API route handler TypeScript file: According to the Next.js documentation (https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config), you can set themaxDurationin your TypeScript file like this:
export const maxDuration = 60
Please ensure that you're using Next.js version 13.4.10 or higher, as this setting requires it.
- Setting
maxDurationusingvercel.jsonconfig: According to the Vercel documentation (https://vercel.com/docs/configuration), you can set themaxDurationin thevercel.jsonfile like this:
{
"functions": {
"api/your-function": {
"maxDuration": 60
}
}
}
Replace "api/your-function" with the path to your serverless function.
If you're still facing issues, it might be due to other factors. For instance, if your function is taking too long to process a request or isn't returning a response, it might time out. Check the Vercel documentation (https://vercel.com/docs/functions/serverless-functions) for more information on Serverless Functions timeouts.
If none of these solutions work, I recommend reaching out to Vercel support for further assistance.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@thorny fable kapa.ai is still learning and improving, please let us know how it did by reacting below