vercel/next.js · error · ApiError

Body exceeded ${limit} limit

Error message

Body exceeded ${limit} limit

What it means

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.

Source

Thrown at packages/next/src/server/api-utils/node/parse-body.ts:50

): Promise<any> {
  let contentType
  try {
    contentType = parse(req.headers['content-type'] || 'text/plain')
  } catch {
    contentType = parse('text/plain')
  }
  const { type, parameters } = contentType
  const encoding = parameters.charset || 'utf-8'

  let buffer

  try {
    const getRawBody =
      require('next/dist/compiled/raw-body') as typeof import('next/dist/compiled/raw-body')
    buffer = await getRawBody(req, { encoding, limit })
  } catch (e) {
    if (isError(e) && e.type === 'entity.too.large') {
      throw new ApiError(413, `Body exceeded ${limit} limit`)
    } else {
      throw new ApiError(400, 'Invalid body')
    }
  }

  const body = buffer.toString()

  if (type === 'application/json' || type === 'application/ld+json') {
    return parseJson(body)
  } else if (type === 'application/x-www-form-urlencoded') {
    const qs = require('querystring') as typeof import('querystring')
    return qs.decode(body)
  } else {
    return body
  }
}

View on GitHub (pinned to 0ae8c72462)

Solutions

  1. Increase the limit if legitimate: `export const config = { api: { bodyParser: { sizeLimit: '10mb' } } }`.
  2. For file uploads, disable bodyParser and stream the request: `export const config = { api: { bodyParser: false } }` and use a multipart parser.
  3. Reduce payload size on the client (compress, paginate, or upload files to object storage and send a reference).

Example fix

// before (pages/api/upload.ts) - default 1mb limit
export default function handler(req, res) { /* ... */ }
// after - raise limit or disable parser
export const config = { api: { bodyParser: { sizeLimit: '10mb' } } }
// or for streaming uploads:
// export const config = { api: { bodyParser: false } }
Defensive patterns

Strategy: validation

Validate before calling

import { statSync } from 'fs'
// On the client, check payload size before sending
function assertBodyUnderLimit(body: string, limitBytes: number) {
  if (Buffer.byteLength(body) > limitBytes) throw new Error(`Body exceeds ${limitBytes} byte limit`)
}

Prevention

When it happens

Trigger: 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' } } }`.

Common situations: File uploads through a JSON API route; large payloads (base64 images, big arrays) hitting the 1MB default; clients sending unexpectedly large documents.

Related errors


AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06). Data as JSON: /api/errors/143274f01b56a03b. Report an issue: GitHub.