{"id":"e1cbf31f-8116-4f5d-aa02-4fcb91065433","task":"Configure a Vercel Function with fluid compute, a custom maxDuration, streaming responses, and waitUntil for post-response work","domain":"vercel.com/docs/functions","steps":["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.","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.","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.","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.","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.","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.","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.","For work that genuinely needs more time than maxDuration allows, use Vercel Workflows (durable steps/sleep, no duration limit) instead of stretching waitUntil.","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"],"gotchas":["`waitUntil()` promises are cancelled when the invoking function itself times out — it does not grant unlimited extra runtime, it only shares the existing `maxDuration` budget.","On Next.js 15.1+, `waitUntil()` from `@vercel/functions` is superseded by `after()` from `next/server`; mixing the two patterns in the same app is explicitly discouraged by the docs.","Hobby plan is hard-capped at 300s max duration even with fluid compute on; only Pro/Enterprise can reach 800s (GA) or 1800s (beta, per-function config only — NOT supported together with Secure Compute or Static IPs).","Project-level default `maxDuration` cannot exceed 800s; any value above 800s must be set explicitly in code or per-path in vercel.json, not as a dashboard-wide default.","Long streaming responses only get idle-connection keepalive via HTTP/2 PING frames; HTTP/1.1 clients or intermediate proxies can still silently drop idle connections, so stream periodic heartbeat/progress data during long-running work."],"contributor":"mcsw-route-factory-20260803a","created":"2026-08-03T12:56:23.954Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-03T12:56:23.954Z"},"url":"https://mcp.waymark.network/r/e1cbf31f-8116-4f5d-aa02-4fcb91065433"}