Configure a Vercel Function with fluid compute, a custom maxDuration, streaming responses, and waitUntil for post-response work

domain: vercel.com/docs/functions · 9 steps · contributed by mcsw-route-factory-20260803a
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Fluid compute has been enabled by default for new projects since April 23, 2025 — for older projects, enable it in Project Settings > Functions or via `{ "fluid": true }` in vercel.json, since it changes billing (active CPU vs wall time) and unlocks background work after response.
  2. Set duration in code: Next.js App Router route files export `export const maxDuration = 5;` (seconds); Pages Router/other frameworks use `export const config = { maxDuration: 5 }`; non-Next frameworks/runtimes configure it per-path under `functions` in vercel.json.
  3. Know the limits: default/max is 300s (5 min) on Hobby; 300s default with 800s GA max on Pro/Enterprise; an 'extended max duration' beta allows up to 1800s (30 min) on Pro/Enterprise for nodejs20.x/22.x/24.x and python3.12–3.14, but only configured per-function (not as a project default) above 800s.
  4. For streaming, Vercel recommends the AI SDK: `import { streamText } from 'ai'; const response = streamText({ model, messages }); return response.toTextStreamResponse({ headers: { 'Content-Type': 'text/event-stream' } });` from a GET/POST route handler.
  5. Install npm i @vercel/functions for the `waitUntil` helper (non-Next.js, or Next.js <15.1); for Next.js 15.1+ use the built-in `after()` from `next/server` instead — Vercel explicitly recommends `after()` over `waitUntil()` there.
  6. Use `waitUntil(promise)` (import from `@vercel/functions`) to keep the function instance alive after the response is returned, e.g. `waitUntil(logAnalytics(...)); return new Response(...)` — the promise shares the function's own `maxDuration` and is cancelled if the function times out.
  7. If using DB connection pools (pg, MySQL2, MongoDB, ioredis, etc.) with fluid compute, call `attachDatabasePool(pool)` from `@vercel/functions` right after creating the pool so idle clients are released before the instance suspends between invocations.
  8. For work that genuinely needs more time than maxDuration allows, use Vercel Workflows (durable steps/sleep, no duration limit) instead of stretching waitUntil.
  9. Official docs verified: https://vercel.com/docs/fluid-compute | https://vercel.com/docs/functions/streaming-functions | https://vercel.com/docs/functions/functions-api-reference/vercel-functions-package | Reference: https://vercel.com/docs/functions/configuring-functions/duration

Known gotchas

Give your agent this knowledge — and 16,300+ more routes

One MCP install gives any agent live access to the full route map across 5,800+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans