feat(api): add configurable --max-request-size flag to serve api - #3938
Open
aheritier wants to merge 1 commit into
Open
feat(api): add configurable --max-request-size flag to serve api#3938aheritier wants to merge 1 commit into
aheritier wants to merge 1 commit into
Conversation
Mirrors the --max-request-size flag that serve chat already has. - Add Option/WithMaxRequestBytes to pkg/server via functional-options (variadic, so all existing NewWithManager/New call sites compile untouched and keep the 1 MiB default). - Register --max-request-size PersistentFlag on the serve api command (int64 bytes, default 1<<20) and thread the value through server.New. - BodyLimit middleware is global on the echo instance, so the cap applies consistently to every /api route including POST /api/sessions/:id/messages. - Oversized requests return HTTP 413 (Request Entity Too Large). - Tests: existing default-cap test kept; new table tests for custom cap on the messages route, plus zero/negative fallback to 1 MiB. - Docs: add --max-request-size row to the api-server CLI Flags table. Closes #3937
aheritier
marked this pull request as ready for review
August 6, 2026 22:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3937.
Adds
--max-request-size <bytes>toserve api, mirroring the flag thatserve chatalready has. The default remains 1 MiB; requests exceeding the limit return HTTP 413.Changes:
pkg/server: newOption/WithMaxRequestBytesfunctional option (variadic — all ~22 existingNewWithManager/Newcall sites compile unchanged, keeping the 1 MiB default)cmd/root/api.go:--max-request-sizePersistentFlag (int64 bytes, default1<<20) threaded throughserver.Newpkg/server/server_test.go: table tests for custom cap onPOST /api/sessions/:id/messages(under-limit→400, over-limit→413) and zero/negative fallback to 1 MiBdocs/features/api-server/index.md: new CLI flags table row documenting default, units, and 413 behaviourNote: The flag help string includes "(default 1 MiB)" alongside Cobra's auto-appended "(default 1048576)" — this matches the existing pattern in
serve chatand is intentionally kept for consistency.