Skip to content

raise the Anthropic request body limit to 64 MiB - #152

Merged
raine merged 2 commits into
raine:mainfrom
rikbrown:rik/body-limit
Sep 14, 2026
Merged

raine merged 2 commits into
raine:mainfrom
rikbrown:rik/body-limit

Conversation

@rikbrown

Copy link
Copy Markdown
Contributor

Problem

MAX_OPENAI_REQUEST_BYTES is 16 MiB. An image-heavy Claude Code session (~490k tokens of screenshots) pushes the request body past that, and because Claude Code re-sends the full history on every turn, the gate then rejects every subsequent request on that session — the session is unrecoverable without dropping the transcript.

Fix

Raise the limit to 64 MiB, matching the Codex image edit cap already used in providers::codex::images, so the two paths agree on how large an image-bearing request may be.

MAX_PROVIDER_STREAM_BYTES (32 MiB) and MAX_SSE_EVENT_BYTES (2 MiB) are untouched — those bound responses, which this does not change.

Verification

Tests in tests/server.rs cover the boundary directly:

  • a body at the limit clears the gate
  • a body over the limit still returns the length error
  • a body over the old 16 MiB limit now clears the gate

cargo clippy --all-targets -- -D warnings clean, cargo fmt --check clean, full suite green.

🤖 Generated with Claude Code

An image-heavy Claude Code session (490k tokens of screenshots) exceeded the
16 MiB gate, which rejected every subsequent request on that session. 64 MiB
matches the Codex image edit cap in `providers::codex::images`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 6aef599)
@RichAyotte

Copy link
Copy Markdown
Contributor

Raising MAX_OPENAI_REQUEST_BYTES also raises /v1/chat/completions and /v1/responses, which still read that constant.

messages_body_over_limit_returns_length_error still expects 400 with length limit exceeded. Anthropic's Messages and Token Counting APIs document 413 request_too_large for overflow (https://platform.claude.com/docs/en/api/errors#request-size-limits).

Claude Code sessions with image-heavy histories can exceed the previous 16 MiB
request limit. Give Anthropic Messages and Token Counting their own 64 MiB
limit while preserving the existing OpenAI-compatible endpoint limit.

Return the documented 413 request_too_large response when an Anthropic request
exceeds the limit, and cover both Anthropic endpoints at the boundary.
@raine
raine merged commit ba8cd70 into raine:main Sep 14, 2026
@raine

raine commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Thanks for this! The larger limit fixes the image-heavy session case nicely. I split the Anthropic limit from the OpenAI-compatible endpoints and corrected oversized Anthropic requests to return 413 request_too_large. Merged.

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.

3 participants