Here's a mistake that doesn't look like one. You build a support bot that reads incoming emails and drafts replies. The emails are HTML, so you send the HTML. Most of them have the company logo in the signature, embedded right in the markup. Nothing breaks, the drafts are fine, and the input bill is about a hundred times what you estimated.

The logo is the problem. When a file travels inside text, it's usually written as base64, and the model has to read every character of it.

A few words first

A token is a chunk of text the model reads; APIs bill per million of them. A tokenizer is the program that cuts text into tokens; I used tiktoken with o200k_base, the one OpenAI's current models use. Input tokens are everything you send in the request. Base64 is a way to write any file, an image, a PDF, a zip, using only 64 safe characters (letters, digits, + and /), so it can sit inside text formats. A data URI is a link that contains the file itself, like src="data:image/png;base64,iVBORw0KGgo..." in an HTML <img> tag. A list price is the vendor's official price per million tokens, before any discount.

The measurement

I took four PNG files of different sizes, base64-encoded them, and counted the tokens. I added 100 KB of random bytes as a control, and English prose from Python's own docstrings for comparison.

What File size Tokens Tokens per KB
Social preview image (PNG) 133.4 KB 122,584 919
512-pixel icon (PNG) 13.1 KB 12,096 924
Browser screenshot (PNG) 271.3 KB 248,134 914
Random bytes 100.0 KB 93,147 931
English prose, for comparison 20.4 KB 4,955 243

All four images land between 914 and 931 tokens per kilobyte of the original file, which is the same rate as random noise. That makes sense: PNG and JPEG are already compressed, so their bytes look random, and base64 of random bytes gives the tokenizer nothing to merge. It averages 1.48 characters per token. English prose averages 4.22.

Two things stack up here. Base64 makes the file a third longer, because it writes every 3 bytes as 4 characters. Then the tokenizer, which was trained on human text, cuts that string into tiny pieces. The result is roughly 0.9 tokens per byte, so you can estimate any file in your head: kilobytes × 920. The older cl100k_base tokenizer is a few percent worse still.

What it costs

The 133 KB preview image is 122,584 tokens. At gpt-5.6's list price of $2 per million input tokens (from the catalog snapshot of the LLM gateway I work on), that's $0.25 per request. On claude-haiku-5.5 at $0.10 per million it's 1.2 cents. Small numbers, until they repeat.

Back to the support bot. Say an email's actual text is 400 tokens, the signature logo is a modest 40 KB, and you process 1,000 emails a day. The logo adds about 37,300 tokens, so each request is 94 times bigger than the text you meant to send. On gpt-5.6-mini at $0.20 per million, the month goes from $2.40 to $225.95. On gpt-5.6 it goes from $24 to $2,259.53. You're paying for the model to read a picture it can't see, because as text it's just a long string of letters.

Size also turns into a reliability problem. At 920 tokens per kilobyte, anything over about 430 KB doesn't fit in a 400K-token context window, and anything over about 1 MB doesn't fit in a 1M one. A normal phone photo of 2 MB comes out at roughly 1.9 million tokens, so the request fails with a context-length error, and it fails only for the users who attach big files. That bug is hard to reproduce.

Where base64 sneaks in

Data URIs in HTML emails and scraped pages. JSON API responses with an avatar or attachment field, passed whole into a prompt or returned whole from a tool call. Log lines that dump request bodies. Jupyter notebooks, whose .ipynb files store every plot as base64.

The fix is to remove the blobs before the text reaches the model and leave a short note in their place:

import re BLOB = re.compile(r"data:[\w/+.-]+;base64,[A-Za-z0-9+/=]+|[A-Za-z0-9+/=]{200,}") def strip_blobs(text): return BLOB.sub(lambda m: f"[binary data, {len(m.group())} chars removed]", text) html = '<p>Thanks!</p><img src="data:image/png;base64,' + "iVBORw0KGgo" * 3000 + '">' print(len(html), "->", len(strip_blobs(html)), "chars") 

The first alternative catches data URIs. The second catches any long unbroken run of base64 characters, which is what attachments in JSON usually look like. Run it on everything you didn't write yourself: emails, scraped pages, tool results. If the model really needs to see the image, send it as an image part of the request, which vendors bill by the picture's pixel dimensions rather than by its byte size.

What this doesn't solve

The regex is a blunt tool. A 200-character run of letters and digits isn't always base64: long hashes, API tokens, minified code, or a DNA sequence will be cut too. Tune the threshold for your data and log what you remove at least at first.

Sometimes the base64 is the point. If you're asking the model to decode a string or debug an encoding issue, stripping it defeats the purpose. In that case send a short sample, not the whole file.

Image parts aren't free either. A picture sent the proper way still costs tokens: a high-resolution photo can cost anywhere from about a thousand to over ten thousand, depending on the vendor. That's a much smaller bill than the base64 version, but it isn't zero.

Finally, my numbers come from one tokenizer. Claude and Gemini use their own, so the exact rate will differ. But base64 is close to random text for any tokenizer trained on human language, so expect it to be expensive everywhere. Check the rate on your provider by sending one file and reading the token count in the response.