api resource_error ai_generated true

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

413 Request Entity Too Large: Request size exceeds the maximum allowed limit for the API Gateway.

ID: api/api-gateway-request-too-large

其他格式: JSON · Markdown 中文 · English
85%修复率
89%置信度
1证据数
2023-11-08首次发现

版本兼容性

版本状态引入弃用备注
AWS API Gateway REST API active
NGINX 1.24 active
Azure API Management active

根因分析

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

English

HTTP request body or headers exceed the size limit configured on the API gateway (e.g., AWS API Gateway 10MB, NGINX 1MB).

generic

官方文档

https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 85% 失败

    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.

  2. 70% 失败

    Adding compression headers (e.g., gzip) but sending uncompressed large payload still triggers the limit because the gateway checks raw size before decompression.