Add `FileSystem(max_media_bytes=)` to set the largest image, PDF or video `read_file` returns as the file itself
Part of #14691 (the FileSystem(max_media_bytes=) item of its first step).
Why we make these changes. read_file returns an image, PDF or video as the file itself only up to a fixed 5 MB, the strictest per-image limit among mainstream providers. That keeps the next model request from failing on Anthropic-sized limits, but it also stops a model that takes larger files (a minute of video for Gemini, a long PDF) from ever seeing them. This makes the limit a setting, with the same default.
New public surface.
FileSystem.max_media_bytes: int = 5_000_000(keyword-only), validated as a positive integer like the other limits.FileSystemToolset(max_media_bytes=5_000_000).
User-visible behavior.
FileSystem(max_media_bytes=50_000_000) # read_file returns videos up to 50 MB as the file itself
A file over the limit is still described (Too large to view: the limit is N bytes.), and the limit applies after any max_image_side downscaling. A file over the 64 MiB read_file reads at most stays described by its size whatever the setting.
Verification. test_max_media_bytes_sets_the_limit (a file at the limit is returned, one byte over is described with the configured limit) and test_invalid_max_media_bytes_rejected in tests/harness/file_system/test_filesystem.py.
What changes for existing users. Nothing: the default stays 5 MB.
Held for review by Aditya, the workspaces owner, who is back on December 15; not for merge before then.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.
š¤ Generated with Claude Code
Summary by cubic
Makes the largest file that read_file returns as the file itself configurable instead of a fixed 5 MB.
- Adds
FileSystem(max_media_bytes=)(and the same onFileSystemToolset), keyword-only, defaulting to5_000_000so existing users see no change. - A file over the limit is still described with the configured limit, and the 64 MiB hard read cap still applies.
- The limit is checked after
max_image_sidedownscaling and validated as a positive integer like the other limits.