{"record":{"id":"143274f01b56a03b","repo":"vercel/next.js","slug":"body-exceeded-limit-limit","errorCode":null,"errorMessage":"Body exceeded ${limit} limit","messagePattern":"Body exceeded (.+?) limit","errorType":"http","errorClass":"ApiError","httpStatus":413,"severity":"error","filePath":"packages/next/src/server/api-utils/node/parse-body.ts","lineNumber":50,"sourceCode":"): Promise<any> {\n  let contentType\n  try {\n    contentType = parse(req.headers['content-type'] || 'text/plain')\n  } catch {\n    contentType = parse('text/plain')\n  }\n  const { type, parameters } = contentType\n  const encoding = parameters.charset || 'utf-8'\n\n  let buffer\n\n  try {\n    const getRawBody =\n      require('next/dist/compiled/raw-body') as typeof import('next/dist/compiled/raw-body')\n    buffer = await getRawBody(req, { encoding, limit })\n  } catch (e) {\n    if (isError(e) && e.type === 'entity.too.large') {\n      throw new ApiError(413, `Body exceeded ${limit} limit`)\n    } else {\n      throw new ApiError(400, 'Invalid body')\n    }\n  }\n\n  const body = buffer.toString()\n\n  if (type === 'application/json' || type === 'application/ld+json') {\n    return parseJson(body)\n  } else if (type === 'application/x-www-form-urlencoded') {\n    const qs = require('querystring') as typeof import('querystring')\n    return qs.decode(body)\n  } else {\n    return body\n  }\n}\n","sourceCodeStart":32,"sourceCodeEnd":67,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/api-utils/node/parse-body.ts#L32-L67","documentation":"Thrown as an ApiError(413) by parseBody() when the raw request body exceeds the configured size limit (default '1mb', or config.api.bodyParser.sizeLimit). The raw-body library raises an 'entity.too.large' error which Next.js converts into a 413 Payload Too Large response.","triggerScenarios":"A request body larger than the limit reaches an API route with bodyParser enabled. The limit defaults to '1mb' but can be raised via `export const config = { api: { bodyParser: { sizeLimit: '5mb' } } }`.","commonSituations":"File uploads through a JSON API route; large payloads (base64 images, big arrays) hitting the 1MB default; clients sending unexpectedly large documents.","solutions":["Increase the limit if legitimate: `export const config = { api: { bodyParser: { sizeLimit: '10mb' } } }`.","For file uploads, disable bodyParser and stream the request: `export const config = { api: { bodyParser: false } }` and use a multipart parser.","Reduce payload size on the client (compress, paginate, or upload files to object storage and send a reference)."],"exampleFix":"// before (pages/api/upload.ts) - default 1mb limit\nexport default function handler(req, res) { /* ... */ }\n// after - raise limit or disable parser\nexport const config = { api: { bodyParser: { sizeLimit: '10mb' } } }\n// or for streaming uploads:\n// export const config = { api: { bodyParser: false } }","handlingStrategy":"validation","validationCode":"import { statSync } from 'fs'\n// On the client, check payload size before sending\nfunction assertBodyUnderLimit(body: string, limitBytes: number) {\n  if (Buffer.byteLength(body) > limitBytes) throw new Error(`Body exceeds ${limitBytes} byte limit`)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Raise config.api.bodyParser.sizeLimit if larger payloads are legitimate.","Disable bodyParser and stream uploads for files.","Compress or paginate large payloads on the client.","Store large blobs in object storage and send a reference."],"tags":["api-routes","body-parsing","limits","client-error"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}