Skip to content

feat(api): add configurable --max-request-size flag to serve api - #3938

Open
aheritier wants to merge 1 commit into
mainfrom
feat/api-max-request-size
Open

feat(api): add configurable --max-request-size flag to serve api#3938
aheritier wants to merge 1 commit into
mainfrom
feat/api-max-request-size

Conversation

@aheritier

Copy link
Copy Markdown
Collaborator

Fixes #3937.

Adds --max-request-size <bytes> to serve api, mirroring the flag that serve chat already has. The default remains 1 MiB; requests exceeding the limit return HTTP 413.

Changes:

  • pkg/server: new Option/WithMaxRequestBytes functional option (variadic — all ~22 existing NewWithManager/New call sites compile unchanged, keeping the 1 MiB default)
  • cmd/root/api.go: --max-request-size PersistentFlag (int64 bytes, default 1<<20) threaded through server.New
  • pkg/server/server_test.go: table tests for custom cap on POST /api/sessions/:id/messages (under-limit→400, over-limit→413) and zero/negative fallback to 1 MiB
  • docs/features/api-server/index.md: new CLI flags table row documenting default, units, and 413 behaviour

Note: The flag help string includes "(default 1 MiB)" alongside Cobra's auto-appended "(default 1048576)" — this matches the existing pattern in serve chat and is intentionally kept for consistency.

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
aheritier marked this pull request as ready for review August 6, 2026 22:43
@aheritier
aheritier requested a review from a team as a code owner August 6, 2026 22:43
@aheritier aheritier added area/cli CLI commands, flags, output formatting area/core Core agent runtime, session management area/docs Documentation changes kind/feat PR adds a new feature (maps to feat:). Use on PRs only. labels Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli CLI commands, flags, output formatting area/core Core agent runtime, session management area/docs Documentation changes kind/feat PR adds a new feature (maps to feat:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(api): make maximum request body size configurable

1 participant