The maximum duration configuration determines the longest time that a function can run. This guide will walk you through configuring the maximum duration for your Vercel Functions.
You are charged based on the amount of time your function has run, also known as its duration. It specifically refers to the actual time elapsed during the entire invocation, regardless of whether that time was actively used for processing or spent waiting for a streamed response. To learn more see Managing function duration.
For this reason, Vercel has set a default maximum duration for functions, which can be useful for preventing runaway functions from consuming resources indefinitely.
If a function runs for longer than its set maximum duration, Vercel will terminate it. Therefore, when setting this duration, it's crucial to strike a balance:
The method of configuring the maximum duration depends on your framework and runtime:
For these runtimes / frameworks, you can configure the number of seconds directly in your function:
export const maxDuration = 5; // This function can run for a maximum of 5 seconds
export function GET(request: Request) {
return new Response('Vercel', {
status: 200,
});
}
For these runtimes and frameworks, configure the maxDuration
property of the functions
object in your vercel.json
file:
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"functions": {
"api/test.js": {
"maxDuration": 30 // This function can run for a maximum of 30 seconds
},
"api/*.js": {
"maxDuration": 15 // This function can run for a maximum of 15 seconds
},
"src/api/*.js": {
"maxDuration": 25 // You must prefix functions in the src directory with /src/
}
}
}
If your Next.js project is configured to use src directory, you will need to prefix your function routes with /src/
for them to be detected.
The order in which you specify file patterns is important. For more information, see Glob pattern.
While Vercel specifies defaults for the maximum duration of a function, you can also override it in the following ways:
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"functions": {
"app/api/**/*": {
"maxDuration": 5 // All functions can run for a maximum of 5 seconds
}
}
}
This glob pattern will match everything in the specified path, so you may wish to be more specific by adding a file type, such as app/api/**/*.ts
instead.
Vercel Functions have the following defaults and maximum limits for the duration of a function with fluid compute (enabled by default):
Default Maximum Hobby 300s 300s Pro 300s 800s Enterprise 300s 800sIf you have disabled fluid compute, the following defaults and maximum limits apply:
Default Maximum Hobby 10s 60s Pro 15s 300s Enterprise 15s 900sRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4