Skip to content

413 Payload Too Large

Description

The 413 Payload Too Large status code indicates that the server is refusing to process a request because the request payload is larger than the server is willing or able to process. The server may close the connection to prevent the client from continuing the request.

This status code is commonly used when: - A client attempts to upload a file that exceeds the server's size limits - A client sends a request body that exceeds the maximum allowed size - A client attempts to POST form data that is too large - A server needs to protect itself from denial of service attacks involving large payloads

The 413 Payload Too Large status helps servers maintain stability and performance by rejecting requests that would consume excessive resources.

Syntax

The server responds with a 413 Payload Too Large status:

HTTP/1.1 413 Payload Too Large
Content-Type: application/json
Retry-After: [optional, seconds to wait before retrying]
Content-Length: [length in bytes]

{
  "error": "Payload Too Large",
  "message": "The request payload exceeds the server's size limit"
}

Examples

File Upload Example

A client attempts to upload a file that exceeds the server's size limit:

Client Request:

POST /upload HTTP/1.1
Host: files.example.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Length: 26214400

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="large-video.mp4"
Content-Type: video/mp4

[25MB of binary data...]
------WebKitFormBoundary7MA4YWxkTrZu0gW--

Server Response:

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

{
  "error": "Payload Too Large",
  "message": "The uploaded file exceeds the maximum allowed size of 10MB",
  "max_size": 10485760,
  "your_size": 26214400
}

API Request Example

A client sends a JSON payload that is too large:

Client Request:

POST /api/data HTTP/1.1
Host: api.example.com
Content-Type: application/json
Content-Length: 15728640

{
  "data": [
    /* Very large JSON array with thousands of entries */
  ]
}

Server Response:

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

{
  "error": "Payload Too Large",
  "message": "The request payload exceeds the maximum allowed size of 5MB",
  "max_size": 5242880,
  "your_size": 15728640,
  "suggestion": "Consider using pagination or breaking your request into smaller chunks"
}

Form Submission Example

A client submits a form with data that exceeds the server's limits:

Client Request:

POST /contact HTTP/1.1
Host: example.org
Content-Type: application/x-www-form-urlencoded
Content-Length: 1048576

name=John+Doe&email=john.doe%40example.com&message=[Very long message text...]

Server Response:

HTTP/1.1 413 Payload Too Large
Content-Type: text/html
Content-Length: 345

<!DOCTYPE html>
<html>
<head>
  <title>Payload Too Large</title>
</head>
<body>
  <h1>413 Payload Too Large</h1>
  <p>Your form submission exceeds our size limit of 100KB.</p>
  <p>Please reduce the length of your message and try again.</p>
  <p><a href="/contact">Return to contact form</a></p>
</body>
</html>

Summary

The 413 Payload Too Large status code is an important mechanism for servers to protect themselves from excessive resource consumption and potential denial of service situations. By clearly communicating size limits to clients, it helps developers understand and comply with server constraints. This status code is particularly relevant for file upload functionality, API endpoints that accept large data sets, and form submissions where user input might be extensive. Servers may include additional information such as the maximum allowed size and suggestions for how to modify the request to comply with size limitations.