HTTP

Status Code

413 Payload Too Large

The request body is too large for the server to process. Learn about size limits and how to handle large uploads.

4 min read beginner Try in Playground

What is a 413 Error?

TL;DR: Your request body exceeds the server’s size limit. Reduce file size, compress data, or use chunked uploads.

A 413 Payload Too Large status code means your request body is bigger than what the server is willing to accept. Think of it like trying to stuff a large suitcase into an airplane overhead bin—the bin exists and works fine, but your suitcase is simply too big to fit.

The server understands your request perfectly, but the amount of data you’re trying to send exceeds the configured size limits.

When Does This Happen?

You’ll encounter a 413 error in these common situations:

1. Large File Uploads

You upload:   50MB video file
Server limit: 10MB maximum
Result:       413 Payload Too Large

2. Bulk Data Submissions

You send:     1000 user records in one request
Server limit: 100 records maximum
Result:       413 Payload Too Large

3. Large Form Data

You submit:   Form with 5MB of text data
Server limit: 1MB form size
Result:       413 Payload Too Large

4. API Request with Large JSON

You send:     JSON with 50,000 array items
Server limit: 10,000 items maximum
Result:       413 Payload Too Large

5. Image Upload Exceeding Limits

You upload:   Uncompressed 20MB photo
Server limit: 5MB image size
Result:       413 Payload Too Large

Example Response

When your payload is too large, the server responds like this:

HTTP/1.1 413 Payload Too Large
Content-Type: application/json
Retry-After: 3600
Content-Length: 178

{
  "error": "Payload too large",
  "message": "Request body exceeds maximum size limit",
  "max_size": "10MB",
  "received_size": "25MB",
  "suggestion": "Break large uploads into smaller chunks"
}
```text

Key parts of this response:

- **413 Payload Too Large** - The status code and reason
- **Retry-After** - Optional header suggesting when to retry
- **Content-Type** - Format of the error details
- **Body** - Specific size limits and helpful suggestions

## Real-World Examples

**Example 1: File Upload Too Large**

```http
POST /upload HTTP/1.1
Host: fileserver.com
Content-Type: multipart/form-data
Content-Length: 52428800

[Large 50MB file data...]

Response:

HTTP/1.1 413 Payload Too Large
Content-Type: application/json

{
  "error": "File too large",
  "message": "Maximum file size is 10MB",
  "max_size_bytes": 10485760,
  "received_size_bytes": 52428800,
  "alternatives": [
    "Compress the file before uploading",
    "Use chunked upload API at /upload/chunked"
  ]
}
```text

**Example 2: Bulk API Request Too Large**

```http
POST /api/users/bulk HTTP/1.1
Host: api.example.com
Content-Type: application/json

{
  "users": [
    // 5000 user objects...
  ]
}

Response:

HTTP/1.1 413 Payload Too Large
Content-Type: application/json

{
  "error": "Bulk request too large",
  "message": "Maximum 100 users per batch",
  "max_items": 100,
  "received_items": 5000,
  "batch_endpoint": "/api/users/batch",
  "suggestion": "Split into multiple requests of 100 users each"
}
```javascript

## How to Handle 413 Errors

**As a Developer:**

- Check the response for size limits
- Implement chunked uploads for large files
- Break large requests into smaller batches
- Compress data before sending when possible
- Show progress indicators for large uploads

**As a User:**

- Compress files before uploading
- Try uploading smaller files
- Break large operations into smaller parts
- Check if the service offers alternative upload methods

**As a Server Administrator:**

- Set reasonable size limits based on your infrastructure
- Provide clear error messages with actual limits
- Offer chunked upload alternatives
- Monitor and adjust limits based on usage patterns

## 413 vs Other Similar Codes

| Code    | Meaning                | What's Different                              |
| ------- | ---------------------- | --------------------------------------------- |
| **413** | Request body too large | The payload size exceeds server limits        |
| **414** | URI too long           | The URL itself is too long, not the body      |
| **400** | Bad request            | Request format is wrong, not necessarily size |
| **422** | Unprocessable entity   | Request format is correct but data is invalid |
| **507** | Insufficient storage   | Server doesn't have enough disk space         |

## Common Solutions

**❌ Sending everything at once**

```javascript
// This might hit size limits
const response = await fetch('/upload', {
  method: 'POST',
  body: hugeFile // 100MB file
})

✅ Chunked upload approach

// Break into manageable chunks
const chunkSize = 1024 * 1024 // 1MB chunks
const totalChunks = Math.ceil(file.size / chunkSize)

for (let i = 0; i < totalChunks; i++) {
  const start = i * chunkSize
  const end = Math.min(start + chunkSize, file.size)
  const chunk = file.slice(start, end)

  await fetch('/upload/chunk', {
    method: 'POST',
    headers: {
      'Content-Range': `bytes ${start}-${end - 1}/${file.size}`,
      'X-Chunk-Index': i,
      'X-Total-Chunks': totalChunks
    },
    body: chunk
  })
}
```javascript

**❌ Bulk operations without batching**

```javascript
// This might exceed payload limits
await fetch('/api/users', {
  method: 'POST',
  body: JSON.stringify({
    users: allUsers // 10,000 users
  })
})

✅ Batched approach

// Process in smaller batches
const batchSize = 100
for (let i = 0; i < allUsers.length; i += batchSize) {
  const batch = allUsers.slice(i, i + batchSize)

  await fetch('/api/users/batch', {
    method: 'POST',
    body: JSON.stringify({ users: batch })
  })
}
```text

## Server Configuration Examples

**Nginx size limit:**

```nginx
client_max_body_size 10M;

Apache size limit:

LimitRequestBody 10485760
```text

**Express.js size limit:**

```javascript
app.use(express.json({ limit: '10mb' }))
app.use(express.urlencoded({ limit: '10mb', extended: true }))

Try It Yourself

Visit our request builder and test size limits:

  1. Set method to POST
  2. Set path to /upload
  3. Add a very large request body
  4. Watch for the 413 response with size information

Frequently Asked Questions

What does 413 Payload Too Large mean?

A 413 error means the request body exceeds the server limit. This commonly happens when uploading files larger than the server allows or sending too much JSON data.

How do I fix a 413 error?

Reduce the size of your request body, compress files before uploading, split large uploads into chunks, or ask the server administrator to increase the limit.

What is the default upload limit?

Limits vary by server. Nginx defaults to 1MB, Apache to 2GB, and Node.js body-parser to 100KB. Check your server configuration for the exact limit.

Can I increase the upload limit?

Yes, server administrators can increase limits. In Nginx use client_max_body_size, in Apache use LimitRequestBody, in Express use body-parser limit option.

Keep Learning