Request Entity Too Large — FUNCTION_PAYLOAD_TOO_LARGE (Vercel 413)
Filed under Deployment failures
A request or response through your Vercel Function exceeds the 4.5 MB body limit — usually a file upload routed through your own API route, or a file returned inline.
Fastest route
Give your AI this prompt
Copy it, replace the bracketed part with your error, and send it.
Preview the prompt
My app is deployed on Vercel and I am getting a 413 error — "Request Entity Too Large" / FUNCTION_PAYLOAD_TOO_LARGE. It happens when: [describe the action — e.g. uploading a photo over ~3 MB through my upload form / downloading an export / loading a page]. Here is the code for that flow: [paste the API route or server action and the client code that calls it]. My files are stored in: [Supabase Storage / Vercel Blob / S3 / not stored yet — pick one]. Please: 1) confirm whether the oversized payload is the request or the response, and where it crosses 4.5 MB (remember base64 inflates a file by about a third), 2) if it is an upload, rework the flow so the browser uploads directly to storage with a signed/presigned upload URL and my function only issues the URL and saves the file reference, 3) if it is a response, change the endpoint to return a signed download URL or paginated data instead of the contents, 4) check for accidental extras — like the file being echoed back in the response. Constraints: do not suggest upgrading my Vercel plan to raise the limit (it cannot be raised), do not change my storage provider, and keep the user-facing flow identical. Show me each file you change.
Fix it yourself
Follow the repair
- Confirm it is the payload limit, and find which direction. Check the error in your Vercel dashboard (your project > Logs) or the browser's network tab. A 413 on an upload endpoint as a user submits a file is the request direction. A 413 when loading or downloading something is the response direction. Also test with a tiny file: if small files pass and large ones fail, you have confirmed size is the trigger — no further diagnosis needed.
- For uploads: send files directly from the browser to storage. This is the real fix, and it removes your function from the file's path entirely. The pattern: your function hands out a short-lived signed upload URL; the browser uploads the file straight to storage with it; your app then saves just the file's reference. With Supabase Storage, it looks like this:
Vercel Blob and S3 offer the same pattern under names like presigned URL. Whatever the service, the shape is identical: the function issues permission slips, the file travels direct.// In the browser, ask your storage for a signed upload URL, // then send the file directly there — never through your API route. const { data } = await supabase.storage .from("uploads") .createSignedUploadUrl("user-files/report.pdf"); await supabase.storage .from("uploads") .uploadToSignedUrl("user-files/report.pdf", data.token, file); - If you must keep the API route, shrink what goes through it. For images, resize and compress in the browser before sending — a phone photo at full size is often 5–10 MB, and a sensible upload size is a tenth of that. Send the file as multipart form data (the file itself), not as a base64 string inside JSON. And strip the accidental giants: check that your handler is not also echoing the file back in its response "for confirmation" — a common AI habit that doubles the traffic through the gate.
- For oversized responses: return a link, not the contents. If the failing direction is the response — a download endpoint, a report generator, an export — do not stream the file through the function. Store the result in your storage service and return a signed download URL, valid for a short window. The response becomes a few hundred bytes of JSON, and the file travels directly between storage and the user's browser.
- For giant JSON: paginate and select less. If the response is data rather than a file, the fix is to not send all of it: add pagination (a page of results plus a total count), and select only the columns the page displays. Returning a table row that includes a base64 file column "because the query fetched everything" is the stealth version of this error — trim the select list and the response shrinks by orders of magnitude.
- For large incoming payloads: receive them somewhere else. If an outside service sends you payloads over the limit — big webhook events, bulk imports — your function cannot be the front door, because the refusal happens before your code runs. Receive the payload at a service built for it (your storage or a queue), or ask the sender to send a reference (an ID or URL) instead of the full contents, and fetch the data in the background where no single request has to carry it.
Why this happensOptional explanation
Vercel Functions — the server code behind your API routes and server actions — sit behind a hard size gate: the body of a request coming in, and the body of a response going out, may each be at most 4.5 MB. Anything larger is refused with a 413 before your code even runs (for requests) or instead of your response reaching the user (for responses). There is no setting, plan upgrade, or configuration line that raises this number; it protects the platform's plumbing, and every app on Vercel lives with it.
The pattern that produces it in AI-built apps is consistent: the AI writes the obvious upload flow — browser sends the file to your API route, your route forwards it to storage. That flow works beautifully in testing with a small photo and collapses the first time a user uploads a phone video or a high-resolution image, especially once base64 gets involved: encoding a file as base64 text inflates it by about a third, so a 3.5 MB file becomes a 4.7 MB payload and trips the gate. The response direction ambushes a different set of apps — ones that fetch a file from the database and return it inline, or return an entire table as one giant JSON.
- Uploads routed through your API: the browser sends the file to your function, and the function forwards it — the hop through the middle is what breaks.
- Base64 inflation: files sent or returned as base64 text grow by roughly a third and cross the limit sooner than expected.
- Oversized responses: returning whole files, huge database rows, or un-paginated lists as one response body.
- Big incoming webhooks or form posts: less common, but a payload from an outside service can exceed the gate before your handler runs.
Quick answers
Can I raise the 4.5 MB limit on a paid plan?
No. The 4.5 MB body limit for Vercel Functions applies on every plan and is not a configurable setting. The intended design is that large files never pass through a function at all: they travel directly between the browser and a storage service, with the function only issuing signed URLs and saving references.
Why did a file smaller than 4.5 MB still fail?
Because base64 encoding represents binary data as text characters, and that representation takes about 4 characters for every 3 bytes — roughly a third larger. A 3.5 MB file becomes about 4.7 MB of base64, which is why uploads that 'should fit' still trip the 413. Send the file itself as form data, or better, direct to storage.
Does uploading directly to storage bypass my server completely?
No — and it should not. Small requests are exactly what functions are for: issuing the signed upload URL, saving the file's reference and metadata after upload, and checking permissions. Only the file's bytes need to travel directly between the browser and storage.