413
Client Error
413 Payload Too Large: Request Body Exceeds Server Limits
β¦ The Golden Answer: The 413 Payload Too Large status code (formerly "Request Entity Too Large") means the server refuses to process the request because the request body is larger than the server is willing or able to handle. This typically happens when uploading files, large JSON payloads, or submitting forms with excessive data. The fix is either to reduce the payload size (compress, split, or optimize) or to increase the server's payload limits.
Common Causes of 413 Errors
| Cause | Example | How to Fix |
|---|---|---|
| File upload too large | Uploading a 100 MB file when the server limit is 10 MB. | Compress the file, split into chunks, or increase the server limit. |
| Large JSON payload | Sending a 50 MB JSON payload to an API. | Optimize the payload (remove unnecessary fields) or use pagination/streaming. |
| Form submission with many fields | Submitting a form with hundreds of fields or large text areas. | Reduce the number of fields or use a more efficient data format. |
| CDN or proxy limits | Cloudflare has a 100 MB upload limit (Enterprise plans can increase). | Check your CDN/proxy limits and adjust your plan or use direct uploads. |
| Web server configuration | Nginx client_max_body_size set too low. | Increase the limit in your web server configuration. |
Example: 413 Response
When a client sends a request that exceeds the server's limit:
POST /upload HTTP/1.1
Host: example.com
Content-Type: multipart/form-data
Content-Length: 104857600
[100 MB of data...]
HTTP/1.1 413 Payload Too Large
Content-Type: text/html
Content-Length: 123
<html>
<body>
<h1>413 Payload Too Large</h1>
<p>The request entity is too large. Maximum allowed size is 10 MB.</p>
</body>
</html>
How to Increase Server Limits
| Server | Configuration Directive | Example |
|---|---|---|
| Nginx | client_max_body_size | client_max_body_size 50M; |
| Apache | LimitRequestBody | LimitRequestBody 52428800 (50 MB in bytes) |
| PHP (php.ini) | upload_max_filesize and post_max_size | upload_max_filesize = 50Mpost_max_size = 50M |
| Cloudflare | Plan limits | Free/Pro: 100 MB; Business: 200 MB; Enterprise: custom. |
| Node.js (Express) | limit option in body-parser | app.use(express.json({ limit: '50mb' })); |
Alternative Approaches
- Chunked uploads β split large files into smaller chunks and upload sequentially.
- Clientβside compression β compress data before sending (e.g., using gzip compression).
- Direct upload to cloud storage β generate a signed URL and upload directly to S3 or similar, bypassing your server.
- Streaming β use streaming uploads to handle large files without loading them entirely into memory.
When to Use 413 vs. 400
- 413 Payload Too Large β the payload size exceeds a configured limit. The server can handle the request, but the payload is too big.
- 400 Bad Request β the payload is malformed or invalid, regardless of size.
Frequently Asked Questions
Is 413 a client error or a server error?
It's a client error (4xx) because the client sent a payload that exceeds the server's configured limits. However, the fix may involve server-side configuration changes.
What is the maximum payload size for most servers?
It varies. Nginx and Apache default to 1 MB or 8 MB. Cloudflare has a 100 MB limit on Free/Pro plans. PHP defaults to 2 MB for uploads. Always check your specific server configuration.
Can I send a Retry-After header with 413?
Yes, you can include a Retry-After header to suggest when the client can try again (e.g., after increasing the limit or reducing the payload).