ai newsDi., 1. Dez.

Gemini: Was kostet eine PDF-Seite oder ein Bild wirklich an Tokens

Die oft zitierte Faustregel, eine PDF-Seite koste 258 Tokens, wurde mit count_tokens an vier Gemini-Modellen praktisch geprueft. Dazu wurden Test-PDFs und PNGs generiert und vermessen.

dev.toSonntag 15:29 · 29.11.DE3 Min. Lesezeit
Bild: dev.to

Posted on Nov 29 • Originally published at aiandsoftwarehub.com

Almost every blog post about Gemini API pricing repeats the same rule of thumb: "a PDF page costs 258 tokens."

I wanted to verify that before budgeting a document pipeline, so on 10 November 2026 I generated test PDFs and PNGs and called client.models.count_tokens() across four Gemini models ( gemini-3.5-flash-lite, gemini-3-flash-preview, gemini-3.6-flash, and gemini-3.8-flash ).

Every single model returned the exact same surprise: 560 tokens per PDF page (even completely blank pages) and ~1,090 tokens per image (whether 300×300 or 3000×2000 pixels). Budgeting with "258" would have undercounted PDF input tokens by 2.17x.

Using the official google-genai Python SDK, I sent each file alongside the 5-token prompt "Describe this file." and subtracted 5 to isolate the file's token cost:

import base64 import pathlib from google import genai client = genai. Client ( ) MODEL = "gemini-3.6-flash" # swap for any model your key lists def count_file_tokens ( path: str, mime_type: str ) -> int: data = pathlib. Path ( path ). read_bytes ( ) resp = client. models. count_tokens ( model = MODEL, contents = [ { "role": "user", "parts": [ { "text": "Describe this file." }, { "inline_data": { "mime_type": mime_type, "data": base64. b64encode ( data ). decode ( ), } }, ], } ], ) return resp. total_tokens print ( "text1.pdf:", count_file_tokens ( "text1.pdf", "application/pdf" ) ) print ( "text10.pdf:", count_file_tokens ( "text10.pdf", "application/pdf" ) ) print ( "blank10.pdf:", count_file_tokens ( "blank10.pdf", "application/pdf" ) ) Enter fullscreen mode Exit fullscreen mode Test 1: PDFs — 560 Tokens Per Page, Blank or Full I generated three A4 PDFs with reportlab:

All four models ( gemini-3.5-flash-lite, gemini-3-flash-preview, gemini-3.6-flash, gemini-3.8-flash ) returned identical numbers:

The blank PDF result is the most telling: the API charged strictly per page, regardless of whether a page held 40 lines of text or literally nothing. (Note: these were standard selectable-text PDFs; scanned pages or huge embedded images were not tested and should be measured separately.)

Next, I generated seven PNGs with Pillow chosen to sit right below and above common tiling thresholds (384 px, 768 px, 1536 px):

There was no step change at 384 px, 385 px, or 768 px. A 3000 × 2000 image (6,000,000 pixels — 66x larger than 300 × 300 ) cost 9 tokens less. Under default Gemini Developer API settings, images behaved as a flat ~1,090-token charge.

Small per-unit errors multiply fast at batch scale:

Once you have real count_tokens numbers for your sample files, you can plug the token totals into this LLM Cost Calculator (or check text prompt overhead with the Token Counter ).

The SDK exposes a media_resolution setting to trade image detail for fewer tokens. When I tried passing it via generationConfig inside count_tokens, the Gemini Developer API rejected the call:

generationConfig parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode. Enter fullscreen mode Exit fullscreen mode That means on the Developer API, you cannot preview media_resolution savings with count_tokens — you have to send a real generate_content call and read response.usage_metadata.prompt_token_count.

Synthetic reportlab PDFs and Pillow PNGs, default settings, one SDK version, four models on one day (10 November 2026). I did not test scanned PDFs, JPEG/WebP photos, the Files API upload route, video, or audio. Google can change tokenization rules without notice, so treat the script above as a tool to run on your own files.

Full write-up and FAQ: aiandsoftwarehub.com.

What are you seeing on your own PDFs with Gemini? Are you stripping blank pages before sending PDFs, or converting pages to lower-res images via media_resolution?

Originaltitel: How Many Tokens Does a Gemini PDF Page or Image Really Cost? (Measured With count_tokens)Quelle: dev.to (dev.to). Original öffnen