Published on

Increasing Next.js Function Execution Timeout in Vercel

Authors

When you're working on the Next.js project, chances are you might choose to use Vercel for hosting it.

And your API will be executed as a serverless function on their infrastructure.

But it comes with some limitations in terms of timeout. Let's see what those are and how to increase their function

By default, all the functions will have a maximum of 10 seconds execution timeout.

Depending on the plan that you're on, you can increase the limit for paid plans.

Let's see how to do it:

Approach 1 - Configuring it in function (for Next.js like framework)

In Next.js (version 13.5+), it's super simple.

Just export the maximum timeout in your function itself.

export const maxDuration = 300; // 300 seconds (5min)

Approach 2 - Configuring it in vercel.json

You can also configure it using vercel.json as well

Like this:

{
  "functions": {
    "api/your-file-path.js": {
      "maxDuration": 30 // 30s
    },
    "api/example/*.js": {
      "maxDuration": 15 // 5s
    }
  }
}

Note: The order in which you declare the path is important. Wildcard routes should be at the end.

Reference

Happy increasing limits!