Skip to content

fix(api): cap request body size and bound dev text fields - #567

Merged
remsky merged 3 commits into
remsky:masterfrom
davidcoulson:fix/request-size-limits
Oct 30, 2026
Merged

remsky merged 3 commits into
remsky:masterfrom
davidcoulson:fix/request-size-limits

Conversation

@davidcoulson

Copy link
Copy Markdown
Contributor

MAX_INPUT_LENGTH is checked after the body is read and parsed, so a
client could send any amount of JSON before it was refused, and the
/dev/tune multipart upload is spooled before its 10 MB check runs (even
with the tuner disabled). /dev/phonemize, /dev/generate_from_phonemes
and /dev/ssml did not use the InputText limit at all.

Add MAX_REQUEST_BODY_MB (default 32, room for the largest valid speech
request in escaped JSON and a tune upload). A small ASGI middleware
413s on a larger Content-Length, and counts chunked bodies as they
arrive; FastAPI reports a failed body read as its own 400, so the
middleware swaps that response for the 413. The three dev text fields
now use InputText.

Testing

  • pytest: new tests, each confirmed to fail without the fix; full suite passes.
  • On the 3070, a 40 MB body to /v1/audio/speech returns 413; normal requests are unaffected.
  • These were run on an RTX 3070 (Unraid, nvidia runtime) using an image built from docker/gpu/Dockerfile.optimized with this and six sibling PRs merged.

One of seven PRs from the same review. Each is based on master on its own; where they overlap (CHANGELOG [Unreleased], and kokoro_v1.py across the OOM, voice-mix and event-loop PRs), the conflicts are mechanical.

MAX_INPUT_LENGTH is checked after the body is read and parsed, so a
client could send any amount of JSON before it was refused, and the
/dev/tune multipart upload is spooled before its 10 MB check runs (even
with the tuner disabled). /dev/phonemize, /dev/generate_from_phonemes
and /dev/ssml did not use the InputText limit at all.

Add MAX_REQUEST_BODY_MB (default 32, room for the largest valid speech
request in escaped JSON and a tune upload). A small ASGI middleware
413s on a larger Content-Length, and counts chunked bodies as they
arrive; FastAPI reports a failed body read as its own 400, so the
middleware swaps that response for the 413. The three dev text fields
now use InputText.
Comment thread api/src/core/config.py Resolved
@remsky
remsky merged commit d536675 into remsky:master Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants