arXiv:2607.21672cs.SEcs.AI2026-07

对比代码转图片后各平台计费差异,发现图像输入实际节省有限。

Pixels for Programs? A Cross-Provider Case Study of Input-Token Accounting for Source Code as Text and Images

  • 测试五种语言、九种代码长度,比较文本与图像输入的token计费
  • 图像输入平均节省24% token,但谷歌Gemini在短代码时反而更贵
  • 研究揭示大模型接口计费逻辑不透明,适合关注成本优化的开发者

长段代码消耗大量文本token,促使将代码渲染为图像以供视觉-语言模型使用。现有研究关注模型在图像化代码后的任务表现,而本文聚焦系统层面:商业API如何计费。我们对Anthropic、OpenAI和Google Vertex AI的15个模型别名进行了可复现的测量,涵盖五种编程语言、20至2000行共九种代码长度。结果显示,这些别名大致归为五个不同的计费模式,非独立模型。在675组完整文本/图像对中,图像相对于文本的token比率分别为0.135、0.194、0.242,对应计费减少86.5%、80.6%、75.8%。但实际临界点不同:Anthropic和OpenAI的图像始终计费更低,而Gemini在20行时计费高出6.95倍,仅在200行以上才低于文本。另发现Gemini在页面边界存在非单调计费现象。本研究仅测量黑盒请求计费,未涉及语义保真度、任务准确率、延迟、费用或编码代理效率。我们公开脚本、固定版本语料、原始日志、验证工具与确定性分析流程,支持复现与扩展。

原文摘要 · Abstract (English)

Long source-code contexts consume many text tokens, motivating the proposal to render code as images for vision-language models. Recent work asks whether models can still solve code tasks after this transformation. We examine a different systems question: how commercial APIs count the resulting requests. We present a reproducible measurement case study of provider-reported input tokens for raw source text and a compact rendered-image representation. The benchmark pairs requests across five programming languages, nine source lengths from 20 to 2,000 lines, and 15 available model aliases exposed by Anthropic, OpenAI, and Google Vertex AI. These aliases collapse to approximately five distinct accounting signatures and are not independent model replications. Across 675 complete text/image pairs, aggregate image-to-text ratios are 0.135, 0.194, and 0.242, corresponding to reported input-token reductions of 86.5\%, 80.6\%, and 75.8\%, respectively. These totals conceal materially different break-even behavior: Anthropic and OpenAI images receive lower counts at every tested size, while Gemini images require 6.95 times as many tokens at 20 lines and cross below text only at 200 lines in the aggregate. A targeted audit also reproduces non-monotonic Gemini image accounting across a page boundary. This study measures black-box request accounting for one compact rendering pipeline. It does not measure semantic fidelity, task accuracy, latency, monetary cost, or coding-agent efficiency. We release the scripts, revision-pinned corpus specification, raw usage records, validators, and deterministic analysis needed to reproduce and extend the study.

代码生成模型计费API审计

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。