Skip to content
 

Configuring Maximum Duration for Vercel Functions

The maximum duration configuration determines the longest time that a function can run. You can configure the maximum duration for Vercel Functions.

Changing the maximum duration gives an invocation more time before Vercel terminates it. With fluid compute, Vercel can reuse function instances and process multiple invocations in the same instance with optimized concurrency. Provisioned memory is billed for running instances, not as a separate memory allocation for every request. Active CPU billing applies while your code is executing, and pauses while your function is waiting on I/O. To learn more, see how pricing works.

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:

  1. Allow sufficient time for your function to complete its normal operations, including any necessary waiting periods (for example, streamed responses).
  2. Set a reasonable limit to prevent abnormally long executions.

The method of configuring the maximum duration depends on your framework and runtime:

Configure the duration in your function definition. For example, Next.js pages router and Node.js /api routes use an exported config object, while the Next.js app router uses a named maxDuration export.

app/api/my-function/route.ts
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:

vercel.json
{
  "$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.

For Python framework apps (FastAPI, Flask, or Django), the whole app builds into a single Vercel Function from its resolved entrypoint. Key the functions entry on that entrypoint file (for example app/main.py or myproject/wsgi.py):

vercel.json
{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "functions": {
    "app/main.py": {
      "maxDuration": 60
    }
  }
}

The order in which you specify file patterns is important. For more information, see Glob pattern.

Pro and Enterprise teams can set individual Vercel Functions using supported Node.js and Python runtime versions to run for up to 30 minutes.

During the beta, durations above 800 seconds must be configured for each function in code or in vercel.json. Project-level defaults above 800 seconds are not supported yet.

Extended max duration is supported for the following runtimes during the beta:

  • nodejs20.x
  • nodejs22.x
  • nodejs24.x
  • python3.12
  • python3.13
  • python3.14

Secure Compute and Static IPs do not support durations above 800 seconds during the beta.

For long-running request handlers that keep a client connection open over HTTP/2, Vercel sends connection-level HTTP/2 PING frames while the response is idle. HTTP/1.1 does not have an equivalent protocol frame, so HTTP/1.1 clients and intermediate network layers may still close idle connections. For those cases, stream progress or heartbeat data while work is running.

For Next.js App Router functions using a supported Node.js runtime, set maxDuration in the route file:

app/api/long-task/route.ts
export const maxDuration = 1800; // This function can run for a maximum of 30 minutes
 
export async function POST(request: Request) {
  return Response.json({ ok: true });
}

For supported Node.js and Python functions outside Next.js App Router, set maxDuration for a specific function path in vercel.json:

vercel.json
{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "functions": {
    "api/long-task.py": {
      "maxDuration": 1800
    }
  }
}

For Python framework apps, key the entry on the resolved entrypoint file (for example app/main.py) instead of an /api route.

While Vercel specifies defaults for the maximum duration of a function, you can also override it in the following ways:

  1. From your dashboard, select your project and open Settings in the sidebar.
  2. From the left side, open Functions in the sidebar and scroll to the Function Max Duration section.
  3. Update the Default Max Duration field value and select Save.

The dashboard sets the project default. During the extended max duration beta, use per-function configuration for durations above 800 seconds.

vercel.json
{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "functions": {
    "app/api/**/*": {
      "maxDuration": 5
    }
  }
}
pages/api/handler.js
{
  "functions": {
    "pages/api/**/*": {
      "maxDuration": 5
    }
  }
}
vercel.json
{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "functions": {
    "app/routes/**/*": {
      "maxDuration": 5 // All functions can run for a maximum of 5 seconds
    }
  }
}
vercel.json
{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "functions": {
    "path/to/dir/**/*": {
      "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):

DefaultMaximumExtended maximum
Hobby300s (5 minutes)300s (5 minutes)-
Pro300s (5 minutes)800s1800s (30 minutes)
Beta
Enterprise300s (5 minutes)800s1800s (30 minutes)
Beta

The 800 second maximum is generally available for Pro and Enterprise teams. For beta requirements and examples, see extended max duration.

For workloads that require unlimited execution time, use Vercel Workflows, which allow your code to pause, resume, and maintain state for minutes to months without duration limits.

Last updated July 1, 2026

Was this helpful?

supported.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.