# RuntimeError: Request body exceeded maximum size (1000000 bytes)

- **ID:** `python/fastapi-request-body-too-large`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The incoming request body is larger than the maximum allowed size set by the application.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **Increase the maximum request body size** (90% success)
   ```
   from starlette.middleware.base import BaseHTTPMiddleware
class LimitUploadSize(BaseHTTPMiddleware):
    async def dispatch(self, request, call_next):
        if request.headers.get('content-length'):
            if int(request.headers['content-length']) > 10 * 1024 * 1024:
                raise HTTPException(status_code=413, detail="Request too large")
        return await call_next(request)
app.add_middleware(LimitUploadSize)
   ```
2. **Use streaming to handle large bodies** (80% success)
   ```
   async def upload():
    async for chunk in request.stream():
        process_chunk(chunk)
   ```

## Dead Ends

- **Truncating the request body on the client side** — May lose data; not a server-side fix. (60% fail)
- **Ignoring the error and retrying** — Same error will occur until limit is increased or body is reduced. (95% fail)
