Stop Base64 Encoding Large Files in Tool Calls

MarcusW4evr · reddit · 2026-07-19

While implementing a tool call for agents to upload files, the author discovered that converting files to base64 and embedding them in the payload works for small files but fails badly with real-world files. A JPEG of a few to hundreds of KB bloats into tens of thousands of tokens after base64 encoding. Although the upload succeeds, the cost is entirely disproportionate, as this encoded data isn't meant for model reasoning but merely transferring "from A to B."

A more rational approach is having the agent write files to disk or reference existing paths/URLs, letting the server-side tool read the bytes directly instead of routing binary content into the context. Base64 should be reserved exclusively for truly small items like icons or thumbnails.

Original post →

More from coding & agent

coding & agent channel →