Anthropic 413: measure request bytes and preserve file isolation

Match Claude byte limits to the endpoint, measure real JSON serialization, and avoid treating file or batch allowances as model context capacity.

By benchr Editorial Team · · · Changelog

Provider documentation read . Documentation review; no provider execution is established by this date.

Anthropic's HTTP 413 request_too_large concerns the byte size accepted by the endpoint. A request can fit a model's token window and still be too large on the wire. Measure the serialized body and inspect encoded attachments before changing the model.

Match the limit to the endpoint

Request-size limits in the direct Claude API error reference, read October 15, 2026
EndpointPublished maximum
Messages32 MB
Token Counting32 MB
Message Batches256 MB
Files500 MB

These are endpoint byte ceilings. Model token, document, and media restrictions still apply. A batch container's allowance does not enlarge an individual model request, and an accepted upload does not establish that every model or endpoint can process the file.

Anthropic says the direct API's edge returns an oversized-request rejection before the request reaches the API servers. Do not assume that every edge rejection will be parsed identically by every proxy or SDK; retain status, content type, and request identifiers when available.

Measure the bytes you will actually send

A string's character count is not its UTF-8 byte count, and the size of an original image is not the size of base64 embedded in JSON. Whitespace, escaping, metadata, history, and repeated media also contribute. Compressing or counting one component does not measure the entire serialized request.

This Python helper returns the exact bytes for its own compact JSON serialization and their length. It is locally tested with Unicode, escaped strings, and invalid nonfinite numbers. An SDK can serialize differently; use its actual request body if you need an exact transport measurement. The documentation's MB labels are retained above without inventing an undocumented byte-conversion boundary.

"""Measure this serialization, not an SDK's potentially different encoding."""
import json


def serialized_json_body(payload):
    body = json.dumps(payload, ensure_ascii=False, allow_nan=False,
                      separators=(",", ":")).encode("utf-8")
    return body, len(body)

Reduce repetition before moving the asset

Inspect duplicate attachments, full transcripts retained at every turn, and tool results that the next request does not need. If the chosen model and endpoint support file references, a Files upload can avoid repeatedly embedding the asset. Confirm the supported media type, processing state, reference lifetime, and model-specific limits in the Files documentation first.

The Files guide also identifies the workspace as the access boundary. File references are not automatically isolated by end user, conversation, or session. Keep the user-to-file mapping on the server and do not accept an untrusted file ID as authorization to read it. Reducing request size must not weaken tenant isolation.

Splitting a document changes how evidence is available to the model. Keep source locations and combine results explicitly rather than presenting independent chunk summaries as a whole-document reading. For asynchronous independent work, use a supported batch workflow; it is not an automatic reroute for an oversized single request.

When the body fits but context does not

Measure tokens separately. Large plain text can fit the endpoint's byte allowance while exceeding the model's input or combined context budget. The context reference distinguishes those limits, and the context diagnostic guide explains the admission arithmetic while labeling its OpenAI-specific controls.

No file upload, token-count request, or provider inference was executed for this guide. The local helper validates serialization arithmetic only. Keep a regression case for the request builder, including Unicode and media metadata, and repeat the byte measurement after middleware has assembled the final payload.

Changelog

  • 2026-10-15 — Reconstructed endpoint byte-limit and file-reference guidance; removed an undefined reroute example and an undocumented MB conversion. Added a locally tested exact-serialization helper and workspace-isolation caveat.
  • — Published. Byte caps per endpoint, the Cloudflare boundary, and the response shape verified against Anthropic's API error docs.

Sources and documentation review

Documentation review dates are recorded per source. No provider inference or independent benchmark replication was performed for this revision.

  1. Claude API byte limits — read
  2. Claude Files API and workspace isolation — read