maxDuration (route segment config)

Sets the maximum execution time (seconds) for a server function.

Since Next 13.5 (App Router) Spec ↗

Syntax

export const maxDuration = 60

Returns

number — Allowed execution seconds before timeout.

Examples

// Allow a long-running report endpoint up to 60s
export const maxDuration = 60

export async function GET() {
  const report = await buildHeavyReport()
  return Response.json(report)
}
// Page with a slow data dependency
export const maxDuration = 30

export default async function Page() {
  const data = await slowAggregate()
  return <Dashboard data={data} />
}

Notes

Caps how long the server function may run before the platform kills it. The allowed maximum depends on the deployment platform/plan (e.g. Vercel function limits). Applies to the Node.js runtime; the Edge runtime uses streaming/CPU limits instead. Exported from `page.js`/`route.js`/`layout.js`.

See also