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.
Vercel Functions now have a public beta that increases the request body limit from 4.5MB to 20MiB. It’s opt-in, only works on specific runtimes and memory settings, and it changes how Middleware sees the body. If you just flip an env var and keep Edge Middleware or small-memory functions, you’ll still hit 413 Payload Too Large.
This is how the 20MiB limit actually works, how to enable it, and what to change in existing Next.js APIs so large JSON and file uploads don’t time out or blow up your memory.
1. What exactly changed in Vercel Functions?
From Vercel’s changelog:
"Vercel Functions now accept inbound request bodies up to 20MiB, up from 4.5MB, in Public Beta."
So there are now two limits, depending on whether you opt into the beta and what runtime you use:
- Default (no beta):
- 4.5MB body limit.
- Applies to all Functions and Routing Middleware.
- Larger bodies return
413.
- With the beta enabled:
- Up to 20MiB body size for:
- Node.js Functions
- Python Functions
- Bun Functions
- Routing Middleware (with a caveat on the body, explained later)
- Functions and Routing Middleware on the Edge runtime stay at 4.5MB and still return
413if you go over.
- Up to 20MiB body size for:
The key detail: the larger limit is not automatic. You need an env var, a memory setting, and the right runtime.
If you’re currently seeing 413 on ~5MB uploads, your function or middleware is still on the 4.5MB limit, either because the beta isn’t enabled or because it’s an Edge runtime.
2. How to enable large request bodies (and why the env var “doesn’t work”)
To opt in, Vercel’s changelog says:
"To turn this on, set the
VERCEL_SUPPORT_LARGE_REQUEST_BODY=1environment 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."
So for VERCEL_SUPPORT_LARGE_REQUEST_BODY=1 to actually change behavior, all of these must be true:
- The env var is set on the Vercel project.
- It’s set in the environment you’re testing (
Preview,Production, or both). - The project’s functions use the performance memory setting of 4GB.
- The specific function is on the Node.js, Python or Bun runtime (not Edge).
If you set VERCEL_SUPPORT_LARGE_REQUEST_BODY=1 and still see the 4.5MB limit or 413:
- Check that the function you’re calling is not Edge runtime.
- Check that the function’s memory setting is the 4GB performance tier.
- Make sure you set the env var on the correct environment, then redeploy.
The opt-in is project-wide per environment. You can, for example:
- Turn it on only for
Previewto test large uploads. - Leave
Productionat 4.5MB until you’re ready.
Once it’s on for an environment, it applies to all non-Edge functions that meet the memory requirement.
3. Edge vs Node.js: which functions can use 20MiB?
The beta applies differently across runtimes and middleware:
- Node.js / Python / Bun Functions
- Can accept request bodies up to 20MiB when the beta is enabled and memory is 4GB.
- Routing Middleware
- Runs in the project where the beta is enabled.
- Still processes requests (with an important body change below).
- Edge runtime Functions and Edge Middleware
- Stay on the 4.5MB limit.
- If the body exceeds that, they return
413.
If you currently use Edge runtime handlers or Edge Middleware for file or large JSON uploads, you won’t get the 20MiB limit without moving those paths to Node.js.
Vercel calls this out explicitly:
"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', orproxy.tsin Next.js."
In a Next.js app, that means:
- Don’t mark upload handlers as Edge runtime.
- Use a Node.js runtime for the route.
- Optionally, use
proxy.tsin Next.js (as Vercel suggests) if you’re proxying to a backend.
Example: Next.js route handler on Node.js runtime
Illustration of a route handler configured for Node.js runtime, so it can use the 20MiB limit:
// app/api/upload/route.ts
export const runtime = 'nodejs';
export async function POST(req: Request) {
// Read and handle the body promptly here
const reader = req.body?.getReader();
if (!reader) {
return new Response('No body', { status: 400 });
}
let total = 0;
for (;;) {
const { done, value } = await reader.read();
if (done) break;
total += value.byteLength;
// Process or stream the chunk out instead of buffering everything
}
return new Response(`Received ${total} bytes`, { status: 200 });
}This pattern processes the body as a stream and avoids holding the entire payload in memory, which matters more once you allow up to 20MiB.
4. What changes for Middleware and why your body disappears
Turning on the beta doesn’t only increase the limit. It also changes how Routing Middleware sees the request body.
Vercel’s changelog says:
"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 avoids sending the body twice, to both middleware and the target function, which would raise cost and time to first byte."
Mechanically, that means for a project with the beta enabled:
- Routing Middleware always runs, like before.
- It still sees:
- URL
- Method
- Headers
- Other metadata
- It does not receive the request body at all.
This is enforced at the project level when you opt in. There’s no per-route override. If your Middleware currently does things that depend on reading the body (for example, inspecting JSON contents for auth), that behavior becomes unavailable with the beta.
The upside is clear: the request body is only read once, by the target function, so you don’t pay twice in cost and time to first byte.
The trade-off is also clear: Middleware can no longer make decisions based on body contents. You’ll need to push that logic into the handler or rely on headers, cookies or the URL.
If you’re using Middleware for auth, moving checks into your Next.js API handlers or into your backend is often a better long-term structure anyway.
5. Avoiding timeouts and memory issues with 20MiB bodies
The changelog gives one practical guideline:
"When handling larger request bodies, read the body promptly and avoid holding it in memory to prevent backpressure and memory issues."
There are two mechanisms behind that advice:
- Backpressure
- If your handler doesn’t start reading the body, the client keeps sending while your function sits idle.
- On serverless infrastructure, that can surface as slow responses or failed requests when the underlying system can’t buffer more.
- Memory pressure
- If you
await req.json()orawait req.arrayBuffer()on a 20MiB payload and keep that object around, your function holds all of it in memory. - Do that across concurrent requests and you can easily hit memory constraints, even on the 4GB setting.
- If you
So when you move from 4.5MB to 20MiB, the implementation pattern matters more than before.
Safer patterns for large JSON and file uploads
A few patterns I’d reach for with this beta enabled:
- Stream the body instead of buffering
- Use the request’s
ReadableStreamand process chunks like in the route example above. - For file uploads, stream directly into blob storage, object storage or your database driver instead of building a full in-memory buffer first.
- Use the request’s
- Do minimal work before reading
- Don’t perform expensive network calls or CPU-heavy work before you start consuming the request body.
- Read or start streaming the body promptly so the underlying system can apply backpressure correctly.
- Keep body-size validation cheap
- If you enforce your own limits under 20MiB, check
Content-Lengthearly when present. - Or keep a running counter of bytes read and abort if it exceeds your limit.
- If you enforce your own limits under 20MiB, check
If your app also needs time-bound cleanup of uploaded files, you can combine this with Vercel Blob’s automatic TTL deletion. I wrote about that pattern in more detail in Using Vercel Blob TTL for automatic file deletion.
6. Trying it on a real project
To try the 20MiB beta on a project without breaking production:
Enable the env var on Preview
In your Vercel project settings, set:
VERCEL_SUPPORT_LARGE_REQUEST_BODY=1Redeploy to create a new preview deployment.
Confirm function memory is 4GB
- Set your project’s function memory to the performance setting of 4GB, as required by the changelog.
Make sure the handler is not Edge runtime
- In Next.js route handlers, export
runtime = 'nodejs'. - If you’re using
proxy.tsin Next.js, keep it on Node.js as Vercel suggests.
- In Next.js route handlers, export
Hit the Preview URL with a large request
- Send a request slightly over 4.5MB but under 20MiB and inspect the status code.
- If you still see
413, check the runtime and memory again.
Once you’re happy with behavior in Preview, repeat the same setup for Production.
For observability around these changes, Vercel’s tracing support now extends beyond plain Next.js apps. If you have background workers, instrumenting Vercel Daemons with OpenTelemetry can help you see upload behavior next to the rest of your system.
7. When I wouldn’t enable the 20MiB beta
I wouldn’t turn this on yet in a few cases:
- Your Middleware logic depends on the request body
- The beta explicitly removes the body from Routing Middleware.
- If you can’t move that logic into handlers or services, you’ll be surprised when the body disappears.
- You don’t actually need >4.5MB
- Most typical JSON APIs and small form uploads fit under 4.5MB.
- Staying on the default limit avoids the Middleware body change and keeps memory usage simpler.
- You rely heavily on Edge runtime for uploads
- Edge Functions and Edge Middleware remain capped at 4.5MB and return
413above that. - If your architecture depends on Edge for these paths, you’ll need to re-design around Node.js functions first.
- Edge Functions and Edge Middleware remain capped at 4.5MB and return
For bigger architectural shifts such as moving uploads off Edge, redesigning auth, or tightening limits, you may want someone to walk the trade-offs with you. I do that kind of work regularly as a Next.js developer on Vercel-hosted products.
This beta makes it possible to accept larger request bodies in Vercel Functions without separate file-upload infrastructure, but it comes with clear constraints. The env var alone isn’t enough: you need the 4GB memory setting, a non-Edge runtime and Middleware that doesn’t depend on the body. If you handle bodies as streams and keep Middleware focused on headers and routing, you can adopt the 20MiB limit without running into timeouts or memory surprises.
Sources
- Vercel Functions now support request bodies up to 20MiB - Vercel changelog, 2026-11-20