Ryan KatayiSenior full-stack engineer
    All sessions

    Engineering notes — ExplainersVercel Functions 20MiB limit: how it actually works

    How the new 20MiB request body limit for Vercel Functions works, how to enable VERCEL_SUPPORT_LARGE_REQUEST_BODY, and how to adapt Next.js APIs safely.

    9 min

    #Vercel#Next.js#Node.js#Infrastructure

    Vercel Functions now have a public beta that raises the inbound request body cap from 4.5MB to 20MiB for some runtimes. It’s opt‑in, tied to a new environment variable and a higher memory setting, and it changes how Routing Middleware sees the body. If you’ve been hitting 413s or the old 4.5MB limit on Next.js APIs and uploads, this is what actually changes and how to adapt your code without blowing up memory or timeouts.

    Vercel announced the change in their post “Vercel Functions now support request bodies up to 20MiB”. Everything here about the platform comes from that post; design advice is my interpretation.

    What changed in the 20MiB request body limit?

    Vercel has raised the maximum inbound request body size for many functions from 4.5MB to 20MiB, in Public Beta.

    From the post:

    "Vercel Functions now accept inbound request bodies up to 20MiB, up from 4.5MB, in Public Beta."

    — Vercel changelog, 2026-11-20

    Mechanically, this means:

    • The new 20MiB limit applies only when you opt in with an environment variable.
    • It affects functions on the Node.js, Python and Bun runtimes, and Routing Middleware.
    • Edge runtime functions and Edge Routing Middleware stay at 4.5MB and keep returning 413 on oversize bodies.
    • To use the larger limit, the project’s functions must use the performance memory setting of 4GB.

    So if you’re seeing 413 Payload Too Large on Vercel Functions or Next.js Route Handlers, the core reasons are:

    • You’re on the default 4.5MB cap (no beta flag, or using Edge runtime), and the client sent more than that.
    • Or you opted into the beta but are still using Edge for that path.

    The rest of this post is about how to switch specific APIs and uploads to a Node-style runtime under this new limit, and what to avoid once you do.

    Which runtimes get 20MiB, and which stay at 4.5MB?

    The beta limit and the old limit now live side by side.

    According to Vercel:

    "It applies to functions on the Node.js, Python, and Bun runtimes, and to Routing Middleware. Functions and Routing Middleware on the Edge runtime keep the 4.5MB cap and return 413 on oversize bodies, so moving them onto the larger limit means switching to the Node.js runtime with runtime: 'nodejs' , or proxy.ts in Next.js."

    — Vercel changelog, 2026-11-20

    So in practice:

    • Node.js / Python / Bun runtimes

      • With the beta flag and 4GB performance memory, inbound request bodies up to 20MiB are allowed.
      • Above that, you still get a 413.
    • Edge runtime (functions and middleware)

      • Hard cap stays at 4.5MB.
      • If the body is larger, Vercel returns 413 before your code runs.
      • There’s no flag in this announcement that changes Edge’s limit.

    If you have a Next.js app that currently runs upload endpoints or JSON APIs on the Edge runtime (for example to reduce latency), raising the body limit means moving those specific handlers to a Node.js runtime and opting into the beta.

    The post mentions using runtime: 'nodejs' or proxy.ts in Next.js for that. The exact shape of proxy.ts is a Next.js detail, but the important part for this change is that those paths run on Node, not Edge.

    How do you enable VERCEL_SUPPORT_LARGE_REQUEST_BODY safely?

    The new limit is opt‑in per project and per environment.

    From the announcement:

    • "To turn this on, set the VERCEL_SUPPORT_LARGE_REQUEST_BODY=1 environment variable."
    • "The opt-in applies to the whole project in the environment where you set it, so you can test the larger limit on preview before enabling it in production."
    • "It requires the project's functions to use the performance memory setting of 4GB."

    That gives you a clear rollout path:

    1. Update the project’s function memory setting to 4GB performance for the environment where you’ll test this.
    2. Set the environment variable in that environment.
    3. Verify specific routes that need larger bodies.
    4. Repeat for production once you’re happy.

    Trying it locally (conceptually) looks like this when you configure your project’s env variables:

    VERCEL_SUPPORT_LARGE_REQUEST_BODY=1

    Vercel’s post doesn’t describe how to set this via UI or CLI, but you’ll put it alongside your other environment variables for the project. Because it’s environment‑scoped, you can enable it on Preview first, then Production.

    Two important consequences to keep in mind:

    • Once you set this flag in an environment, all functions in that environment can receive up to 20MiB (subject to runtime).
    • Edge runtime functions are unaffected. To benefit, handlers must run on Node.js, Python or Bun.

    If you only need larger bodies on one or two endpoints, you still opt in at the project level and then move only those endpoints off Edge.

    Why your middleware will stop seeing the request body

    The beta doesn’t just change limits, it also changes how Routing Middleware sees the body.

    From the post:

    • "When a project opts in, Routing Middleware receives request headers and metadata but no request body, enforced at the project level."
    • "Middleware still runs and still sees every other request header, so body-dependent middleware behavior is the one thing that becomes unavailable."
    • This behavior "avoids sending the body twice, to both middleware and the target function, which would raise cost and time to first byte."

    Before the opt‑in, Middleware could see the body within the 4.5MB limit. After you set VERCEL_SUPPORT_LARGE_REQUEST_BODY=1:

    • Middleware still executes for every request.
    • Middleware still has access to URL, method and all headers.
    • Middleware no longer gets access to the body, at all, in that project environment.

    That has a few practical effects:

    • If you currently inspect bodies in middleware (for example, to look at JSON payload content), that logic will break after you opt in.
    • You must move any body‑dependent decisions out of middleware and into the actual function or route handler.

    If you’re not reading the body in middleware today, you get the new limit without changing middleware code, which is a nice property.

    How to adapt Next.js APIs and uploads to the 20MiB limit

    Vercel’s announcement doesn’t show Next.js‑specific examples, but the mechanics map cleanly.

    If a Next.js route is hitting the old 4.5MB limit with 413 responses and you want it to use the 20MiB cap:

    1. Ensure the project’s functions use the 4GB performance memory setting.
    2. Set VERCEL_SUPPORT_LARGE_REQUEST_BODY=1 in that environment.
    3. Mark that specific route as Node.js runtime, not Edge.

    A simple illustration for a Route Handler that needs larger bodies might look like this:

    // app/api/upload/route.ts (illustration only)
    
    export const runtime = 'nodejs';
    
    export async function POST(request: Request) {
      // Read the request body promptly
      const reader = request.body?.getReader();
      let total = 0;
    
      while (reader) {
        const { done, value } = await reader.read();
        if (done) break;
        total += value.byteLength;
        // In real code, stream `value` to storage or a processor
      }
    
      return new Response(`Received ${total} bytes`, { status: 200 });
    }

    That pattern does two things the announcement recommends:

    • It reads the body promptly so the upstream can continue streaming.
    • It avoids holding the whole body in memory at once.

    The post explicitly warns:

    • "When handling larger request bodies, read the body promptly and avoid holding it in memory to prevent backpressure and memory issues."

    So even though you now have up to 20MiB to work with, you should still treat the body as a stream, especially for file uploads or large JSON dumps.

    If you have mixed needs across routes:

    • Keep latency‑sensitive, small‑payload endpoints on Edge with the 4.5MB limit.
    • Move only the large‑payload endpoints to Node.js or another supported runtime.
    • Use the same project with VERCEL_SUPPORT_LARGE_REQUEST_BODY=1 enabled, knowing middleware no longer sees bodies there.

    For more complex products, this is the point where I’d also look at background processing and clean data flows. If you’re already pushing data into Supabase or Postgres, designing around structured uploads and worker‑style processing pays off over time. I cover some of those patterns in my Next.js security advisories checklist and my write‑up on Vercel Blob TTL for uploads.

    Forms, JSON and multipart uploads under 20MiB

    The 20MiB limit is transport, not format. Vercel doesn’t care whether those bytes are JSON, multipart/form-data or something else, as long as the total size stays under 20MiB for the supported runtimes.

    Design‑wise, here’s how I’d think about common cases:

    • JSON APIs that were near or over 4.5MB

      • Move them to Node.js runtime under the beta if you truly need that much JSON in one request.
      • Read and process the body as it arrives, rather than building one huge object in memory when possible.
    • File uploads from forms

      • Treat files as streams once they hit your handler.
      • Avoid patterns where you read the entire file into a single buffer or string just to pass it along.
    • Multipart form posts

      • Use a parser that can work chunk by chunk instead of one that insists on buffering the whole body up front.
      • Offload long‑running work instead of trying to do everything during the request window.

    These patterns aren’t described in Vercel’s post. They follow from the warning about backpressure and memory problems and from the reality that 20MiB is still a non‑trivial chunk of memory if you copy it multiple times.

    If you’re already pushing uploaded content to a database‑backed workflow like Supabase or Postgres, there’s a nice synergy here. Vercel Functions handle the network edge and initial ingest, and the heavier processing happens in background jobs and database logic.

    When I wouldn’t turn this on yet

    There are clear cases where I’d hold off on VERCEL_SUPPORT_LARGE_REQUEST_BODY or limit where I use it.

    You probably shouldn’t enable it (yet) if:

    • Your Routing Middleware depends on reading the body for auth or routing decisions.
    • You don’t have any endpoints that need more than 4.5MB, and you’re happy with the current behavior.
    • You’re not ready to move specific handlers off the Edge runtime, but those same handlers are the ones hitting the limit.

    Even once you enable it, I’d keep the 20MiB paths narrow:

    • Only the routes that truly need more than 4.5MB run on Node.js, Python or Bun.
    • Everything else stays as‑is, especially if they currently benefit from Edge.

    The announcement also labels this as a Public Beta. That usually means behavior could still change. I’d avoid building anything that absolutely depends on 20MiB bodies being available forever, and I’d keep an eye on Vercel’s documentation for updates.

    Raising the request body limit to 20MiB on Vercel Functions removes a common source of 413 errors for file uploads and large JSON APIs, as long as you move those paths to the supported runtimes and opt in with VERCEL_SUPPORT_LARGE_REQUEST_BODY=1 on 4GB performance memory. The trade‑offs are clear: Edge runtimes stay capped at 4.5MB, Routing Middleware loses access to the body in environments where the flag is set, and you’re responsible for reading larger bodies promptly without buffering them in memory. If you want help threading those constraints through a real Next.js app, I work on this stack every day as a Next.js developer.

    Sources

    Now playingCudioGet in touch