How Many Tokens Does a Gemini PDF Page or Image Really Cost? (Measured With count_tokens)
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 a
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.
TL;DR
- PDFs: 1 page of text = 560 tokens. 10 pages of text = 5,600 tokens. 10 completely blank pages = 5,600 tokens.
- Images (PNG): 300×300 up to 1536×1536 = 1,094 tokens each. 3000×2000 = 1,085 tokens (100x more pixels, 9 tokens less).
- Why you must measure: Never hard-code blog numbers —
count_tokenstakes one API call per sample file and tells you the real number for your exact model.
The Measurement Script
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"))
Test 1: PDFs — 560 Tokens Per Page, Blank or Full
I generated three A4 PDFs with reportlab:
-
text1.pdf: 1 page with 40 lines of random words -
text10.pdf: 10 pages of the same dense text -
blank10.pdf: 10 completely empty pages
All four models (gemini-3.5-flash-lite, gemini-3-flash-preview, gemini-3.6-flash, gemini-3.8-flash) returned identical numbers:
| File | Total tokens (incl. 5-token prompt) | File-only tokens | Per page |
|---|---|---|---|
text1.pdf (1 page of text) |
565 | 560 | 560 |
text10.pdf (10 pages of text) |
5,605 | 5,600 | 560 |
blank10.pdf (10 empty pages) |
5,605 | 5,600 | 560 |
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.)
Test 2: Images — Flat ~1,090 Tokens Across 100x Pixel Growth
Next, I generated seven PNGs with Pillow chosen to sit right below and above common tiling thresholds (384 px, 768 px, 1536 px):
Image dimensions (image/png) |
Total tokens (incl. 5-token prompt) | Image-only tokens |
|---|---|---|
| 300 × 300 | 1,094 | 1,089 |
| 384 × 384 | 1,094 | 1,089 |
| 385 × 385 | 1,094 | 1,089 |
| 768 × 768 | 1,094 | 1,089 |
| 1536 × 1536 | 1,094 | 1,089 |
| 1536 × 768 | 1,086 | 1,081 |
| 3000 × 2000 | 1,085 | 1,080 |
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.
What That Error Does to a Real Budget
Small per-unit errors multiply fast at batch scale:
| Batch workload | At "258 / unit" myth | At measured cost | Multiplier |
|---|---|---|---|
| 200 PDFs × 12 pages (2,400 pages) | 619,200 tokens | 1,344,000 tokens | 2.17x |
| 1,000 PNG images | 258,000 tokens | ~1,090,000 tokens | 4.22x |
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).
One API Gotcha: media_resolution in count_tokens
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.
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.
4-Step Pre-Budgeting Habit
- Run
count_tokenson 3–4 representative real files (short, long, and worst-case scanned/image-heavy). - Subtract the token count of your text-only prompt.
- Compare two same-page-count files with different text density to confirm whether your model charges flat per page.
- Re-run the check whenever you upgrade or switch model IDs.
Limits of This Run
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?
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.