# 413 请求实体过大：请求大小超过API网关允许的最大限制。

- **ID:** `api/api-gateway-request-too-large`
- **领域:** api
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

HTTP请求体或头部超过API网关配置的大小限制（如AWS API Gateway 10MB，NGINX 1MB）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| AWS API Gateway REST API | active | — | — |
| NGINX 1.24 | active | — | — |
| Azure API Management | active | — | — |

## 解决方案

1. ```
   Increase the maximum request size on the gateway. For NGINX: add 'client_max_body_size 20M;' in the http or server block. For AWS API Gateway, increase the payload limit to 10MB (maximum) or use binary media types.
   ```
2. ```
   Split large payloads into chunks using multipart upload or paginated API calls. Example: POST /upload with 'Content-Range: bytes 0-1048575/5242880' header.
   ```
3. ```
   Use a direct upload to cloud storage (e.g., S3 presigned URL) and pass only the reference (URL) in the API request.
   ```

## 无效尝试

- **** — Increasing client-side timeout without reducing payload size does not resolve the 413 error, as the gateway rejects the request before it reaches the backend. (85% 失败率)
- **** — Adding compression headers (e.g., gzip) but sending uncompressed large payload still triggers the limit because the gateway checks raw size before decompression. (70% 失败率)
