← All errors · VercelServerless & Edge Function errors
FUNCTION_PAYLOAD_TOO_LARGE (413): Vercel request body too large on image uploads
What you see
An upload works locally but fails on Vercel with HTTP 413 once the file (often a phone photo, or several images in one form) gets big. Vercel names the error FUNCTION_PAYLOAD_TOO_LARGE, "Payload Too Large", error code 413. If the response is the part that is too big, it can show up as 500 - FUNCTION RESPONSE PAYLOAD TOO LARGE instead.
What it means
By default, Vercel Functions accept request bodies up to 4.5 MB. As of November 20, 2026, request bodies up to 20 MiB are available in public beta if you opt in. When a function receives more than the applicable limit, Vercel returns 413 FUNCTION_PAYLOAD_TOO_LARGE before your code can handle it, so raising a limit in your own code does not help. The response body limit is still 4.5 MB, except for streamed responses. The most common reason for the 413 is uploading files through an API route. Vercel's advice is still to treat functions as a light API layer, not a media server: send the file straight from the browser to storage, and let your function only hand out permission to upload. If the body itself needs to be larger (up to 20 MiB), you can opt in as described below.
Likely causes
- The browser posts the file (FormData or base64 JSON) to your own API route, route handler or server function, so the whole file passes through a Vercel Function.
- Several images are sent in one request, so the total goes over the applicable limit (4.5 MB by default) even though each file is small.
- Files are base64-encoded into JSON, which makes the body larger than the original file.
- Local dev has no such limit, so it only breaks after deploying to Vercel.
- The function returns too much data (the response body limit is still 4.5 MB, except for streamed responses), for example a large file or a huge JSON list.
- You opted into the 20 MiB request-body limit but the function or Routing Middleware is still on the Edge runtime, which stays at 4.5 MB and returns 413 on oversize bodies.
How to fix it
Confirm it is the size limit. Send one file over 4.5 MB (the default request-body limit) and one small file to the same route and compare the status codes. Use your own route and form field name:
head -c 6000000 /dev/urandom > big.bin head -c 1000000 /dev/urandom > small.bin curl -s -o /dev/null -w '%{http_code}\n' -F "file=@big.bin" https://your-app.vercel.app/api/upload curl -s -o /dev/null -w '%{http_code}\n' -F "file=@small.bin" https://your-app.vercel.app/api/uploadIf the body is over 4.5 MB but under 20 MiB, you can opt into Vercel's larger request-body limit, in public beta since November 20, 2026. It applies to the Node.js, Python, and Bun runtimes. Set VERCEL_SUPPORT_LARGE_REQUEST_BODY=1 for the environments you want (the opt-in applies to the whole project in each selected environment, so you can test it on Preview first), then redeploy. Add it with the CLI or in the project dashboard under Settings > Environment Variables:
vercel env add VERCEL_SUPPORT_LARGE_REQUEST_BODY # when prompted, enter: 1 # then pick the environment (Preview, Production, or both) # redeploy afterwards for the change to take effectThe docs also require fluid compute, and they require the project's function memory to be set to Performance (4 GB). Vercel says that Performance setting is available on Pro and Enterprise plans. The same limits docs list Hobby function memory as 2 GB default and maximum, and the memory configuration docs say Hobby users cannot change that size and always use 2 GB (1 vCPU). Set memory in the dashboard under Settings > Functions > Function CPU; Vercel says you cannot set it in vercel.json. After you opt in, Routing Middleware still runs and still sees request headers and metadata, but it no longer receives the request body (Vercel does this so the body is not sent twice). Functions and Routing Middleware on the Edge runtime stay at the 4.5 MB cap and return 413 on oversize bodies; to use the larger limit, switch them to the Node.js runtime with runtime: 'nodejs', or to proxy.ts in Next.js. When handling a larger body, Vercel says to start reading it promptly and avoid holding it in memory. This opt-in does not raise the response body limit, which stays 4.5 MB except for streamed responses. For files larger than 20 MiB, or if you cannot meet the opt-in requirements, use the direct-to-storage approaches below.
Fix it with Vercel Blob client uploads: the file goes from the browser straight to Vercel Blob, secured by a token your server issues. Browser side:
'use client' import { upload } from '@vercel/blob/client' async function onFile(file) { const blob = await upload(file.name, file, { access: 'private', // or 'public' handleUploadUrl: '/api/upload', }) return blob.url }Server route that issues the token. Check that the user is signed in inside onBeforeGenerateToken, or anyone can upload to your store. handleUpload needs the BLOB_READ_WRITE_TOKEN env var, and onUploadCompleted cannot reach localhost, so test that part on a deployment or through a tunnel such as ngrok:
// app/api/upload/route.js import { handleUpload } from '@vercel/blob/client' import { NextResponse } from 'next/server' export async function POST(request) { const body = await request.json() try { const json = await handleUpload({ body, request, onBeforeGenerateToken: async (pathname) => { // const session = await auth(); if (!session) throw new Error('Not authenticated') return { allowedContentTypes: ['image/jpeg', 'image/png', 'image/webp'], addRandomSuffix: true, } }, onUploadCompleted: async ({ blob }) => { // save blob.url to your database }, }) return NextResponse.json(json) } catch (error) { return NextResponse.json({ error: error.message }, { status: 400 }) } }Using Supabase Storage instead: create a signed upload URL on the server (it is valid for 2 hours), send the path and token to the browser, and upload the file directly with uploadToSignedUrl:
// server (route handler, after checking the user) const { data, error } = await supabase.storage .from('avatars') .createSignedUploadUrl(`${userId}/photo.jpg`) // return data.path and data.token to the browser // browser const { error } = await supabase.storage .from('avatars') .uploadToSignedUrl(path, token, file, { contentType: file.type })Using Amazon S3 (or another S3-compatible store): generate a presigned PUT URL on the server and have the browser PUT the file to it. Send the same Content-Type you signed, or S3 returns SignatureDoesNotMatch:
// server import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3' import { getSignedUrl } from '@aws-sdk/s3-request-presigner' const s3 = new S3Client({ region: process.env.AWS_REGION }) const url = await getSignedUrl( s3, new PutObjectCommand({ Bucket: process.env.S3_BUCKET, Key: key, ContentType: contentType }), { expiresIn: 600 } ) // browser await fetch(url, { method: 'PUT', headers: { 'Content-Type': file.type }, body: file })If the files are only photos and you must keep the upload going through your function, shrink them in the browser first. This only helps when the result ends up under the limit that applies to your function (4.5 MB by default, or 20 MiB if you opted in), so direct-to-storage is the safer fix for anything users pick from their camera roll:
async function shrink(file, maxSide = 2000, quality = 0.8) { const img = await createImageBitmap(file) const scale = Math.min(1, maxSide / Math.max(img.width, img.height)) const canvas = document.createElement('canvas') canvas.width = Math.round(img.width * scale) canvas.height = Math.round(img.height * scale) canvas.getContext('2d').drawImage(img, 0, 0, canvas.width, canvas.height) return new Promise((resolve) => canvas.toBlob(resolve, 'image/jpeg', quality)) }Other options from Vercel's docs: send several files as separate requests instead of one big form, and for data that is too large in the response, return less per request or stream the response.
Test it: deploy, upload a file over 4.5 MB, and watch DevTools > Network. If you opted into the 20 MiB limit and the file still goes through your function, the request should succeed up to 20 MiB (and still return 413 above that, or on Edge). If you used direct-to-storage, the file itself should now go to the storage host (Vercel Blob, your-project.supabase.co or your S3 bucket), and the only request to your own /api route should be the small token or URL request, with no 413.
Still stuck after trying this? Get it fixed for $49, or you don't pay.
Prevent this next time
- Add timeouts to outbound requests and return clear error responses instead of crashing.
- Set up uptime checks and log alerts on critical endpoints so you hear about failures before users do.
Guide: catch outages before your users do.
Tools that help:
- Better Stack: Uptime, cron/heartbeat monitoring and log alerts.
Some links on this page are affiliate links: if you sign up or buy through them, FixStack may earn a commission at no extra cost to you. Learn more.
FAQ
What does "FUNCTION_PAYLOAD_TOO_LARGE (413): Vercel request body too large on image uploads" mean?
By default, Vercel Functions accept request bodies up to 4.5 MB. As of November 20, 2026, request bodies up to 20 MiB are available in public beta if you opt in. When a function receives more than the applicable limit, Vercel returns 413 FUNCTION_PAYLOAD_TOO_LARGE before your code can handle it, so raising a limit in your own code does not help. The response body limit is still 4.5 MB, except for streamed responses. The most common reason for the 413 is uploading files through an API route. Vercel's advice is still to treat functions as a light API layer, not a media server: send the file straight from the browser to storage, and let your function only hand out permission to upload. If the body itself needs to be larger (up to 20 MiB), you can opt in as described below.
What usually causes it?
The browser posts the file (FormData or base64 JSON) to your own API route, route handler or server function, so the whole file passes through a Vercel Function. Several images are sent in one request, so the total goes over the applicable limit (4.5 MB by default) even though each file is small. Files are base64-encoded into JSON, which makes the body larger than the original file. Local dev has no such limit, so it only breaks after deploying to Vercel. The function returns too much data (the response body limit is still 4.5 MB, except for streamed responses), for example a large file or a huge JSON list. You opted into the 20 MiB request-body limit but the function or Routing Middleware is still on the Edge runtime, which stays at 4.5 MB and returns 413 on oversize bodies.
How do I fix it?
1. Confirm it is the size limit. Send one file over 4.5 MB (the default request-body limit) and one small file to the same route and compare the status codes. Use your own route and form field name: 2. If the body is over 4.5 MB but under 20 MiB, you can opt into Vercel's larger request-body limit, in public beta since November 20, 2026. It applies to the Node.js, Python, and Bun runtimes. Set VERCEL_SUPPORT_LARGE_REQUEST_BODY=1 for the environments you want (the opt-in applies to the whole project in each selected environment, so you can test it on Preview first), then redeploy. Add it with the CLI or in the project dashboard under Settings > Environment Variables: 3. The docs also require fluid compute, and they require the project's function memory to be set to Performance (4 GB). Vercel says that Performance setting is available on Pro and Enterprise plans. The same limits docs list Hobby function memory as 2 GB default and maximum, and the memory configuration docs say Hobby users cannot change that size and always use 2 GB (1 vCPU). Set memory in the dashboard under Settings > Functions > Function CPU; Vercel says you cannot set it in vercel.json. After you opt in, Routing Middleware still runs and still sees request headers and metadata, but it no longer receives the request body (Vercel does this so the body is not sent twice). Functions and Routing Middleware on the Edge runtime stay at the 4.5 MB cap and return 413 on oversize bodies; to use the larger limit, switch them to the Node.js runtime with runtime: 'nodejs', or to proxy.ts in Next.js. When handling a larger body, Vercel says to start reading it promptly and avoid holding it in memory. This opt-in does not raise the response body limit, which stays 4.5 MB except for streamed responses. For files larger than 20 MiB, or if you cannot meet the opt-in requirements, use the direct-to-storage approaches below. 4. Fix it with Vercel Blob client uploads: the file goes from the browser straight to Vercel Blob, secured by a token your server issues. Browser side: 5. Server route that issues the token. Check that the user is signed in inside onBeforeGenerateToken, or anyone can upload to your store. handleUpload needs the BLOB_READ_WRITE_TOKEN env var, and onUploadCompleted cannot reach localhost, so test that part on a deployment or through a tunnel such as ngrok: 6. Using Supabase Storage instead: create a signed upload URL on the server (it is valid for 2 hours), send the path and token to the browser, and upload the file directly with uploadToSignedUrl: 7. Using Amazon S3 (or another S3-compatible store): generate a presigned PUT URL on the server and have the browser PUT the file to it. Send the same Content-Type you signed, or S3 returns SignatureDoesNotMatch: 8. If the files are only photos and you must keep the upload going through your function, shrink them in the browser first. This only helps when the result ends up under the limit that applies to your function (4.5 MB by default, or 20 MiB if you opted in), so direct-to-storage is the safer fix for anything users pick from their camera roll: 9. Other options from Vercel's docs: send several files as separate requests instead of one big form, and for data that is too large in the response, return less per request or stream the response. 10. Test it: deploy, upload a file over 4.5 MB, and watch DevTools > Network. If you opted into the 20 MiB limit and the file still goes through your function, the request should succeed up to 20 MiB (and still return 413 above that, or on Edge). If you used direct-to-storage, the file itself should now go to the storage host (Vercel Blob, your-project.supabase.co or your S3 bucket), and the only request to your own /api route should be the small token or URL request, with no 413.
Last checked against official docs on . Sources: Vercel changelog: Vercel Functions now support request bodies up to 20MiB (Nov 20, 2026), Vercel docs: Vercel Functions limits (request body size), Vercel docs: Configuring memory and CPU for Vercel Functions, Vercel docs: FUNCTION_PAYLOAD_TOO_LARGE, Vercel KB: How do I bypass the 4.5MB body size limit of Vercel Functions, Vercel docs: Client uploads with Vercel Blob, Supabase docs: createSignedUploadUrl, Supabase docs: uploadToSignedUrl, AWS docs: Uploading objects with presigned URLs.
Related errors
More Vercel errors and fixes →
Tools that help
- Railway: Deploy backends and databases; new users get $20 credit.
Some links on this page are affiliate links: if you sign up or buy through them, FixStack may earn a commission at no extra cost to you. Learn more.
Get new fixes weekly
No spam. Unsubscribe anytime. Privacy