Rendering code as images slashes AI tokens 86% for Anthropic and OpenAI
New study reveals Gemini charges 7x more tokens for code images than text at 20 lines.
A recent arXiv paper (2607.21672) by Ronak Bhalgami investigates a practical systems question: how do major AI providers count input tokens when source code is submitted as rendered images instead of raw text? The study benchmarks requests across five programming languages, nine source lengths from 20 to 2,000 lines, and 15 model aliases from Anthropic, OpenAI, and Google Vertex AI. The results reveal stark differences in accounting behavior: Anthropic and OpenAI consistently report fewer tokens for image-based code inputs, achieving aggregate reductions of 86.5% and 80.6% respectively. In contrast, Google's Gemini models charge 6.95 times more tokens for a 20-line code image compared to its text version, only crossing below text-based token counts at around 200 lines. The study also uncovered non-monotonic token accounting in Gemini across page boundaries.
These findings have significant implications for developers using AI for code analysis or generation, especially when dealing with large codebases. The paper does not evaluate task accuracy, latency, or cost, but focuses purely on token accounting. The author provides all reproduction scripts, corpus specifications, and raw data, enabling others to verify and extend the results. This work highlights the need for transparency in API pricing and could influence how developers optimize their prompts when working with different model providers.
- Across 675 text/image pairs, Anthropic and OpenAI showed 86.5% and 80.6% token reductions for image-based code.
- Google Gemini charged 6.95x more tokens for a 20-line code image than its text version, breaking even only at 200 lines.
- Study covered 5 programming languages, 9 source sizes, and 15 model aliases from three major providers.
Why It Matters
Reveals hidden cost differences in AI token accounting, enabling smarter prompt optimization for code-heavy workflows.