GEMINI LABJP
NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20
Articles/API / SDK
API / SDK/2026-04-13Advanced

Gemini API Multimodal Input Optimization — Production Techniques to Cut Token Costs for Images, PDFs, Video, and Audio

Cut your Gemini API multimodal token costs by up to 70% in production. Practical optimization techniques for images, PDFs, video, and audio with working Python code examples.

gemini-api277multimodal44cost-optimization30tokens3production140image-processingvideo-analysisaudio-processing

Premium Article

The Hidden Cost That Tripled My API Bill Overnight

When you start building multimodal applications with the Gemini API, you encounter a scale of token consumption that text-only work never prepared you for. I learned this the hard way — the month after deploying an image analysis prototype to production, my API bill came in at three times the estimate.

The root cause was straightforward: I was sending full-resolution images, processing PDFs page by page without filtering, and feeding entire videos into the API. The Gemini API's multimodal capabilities are powerful, but without understanding how each modality maps to tokens, costs spiral out of control fast.

This guide walks through concrete techniques to reduce multimodal token costs by 50–70% in production, broken down by modality. Every code example is tested and ready to drop into a Python project.

How Gemini API Tokenizes Each Modality — The Mechanics You Need to Know

Before optimizing anything, you need to understand exactly how each input type converts to tokens. Blindly compressing files without this knowledge leads to wasted effort — or worse, degraded output quality with no cost savings.

Image Tokenization Rules

The Gemini API divides images into fixed-size tiles and processes each tile as a set number of tokens. As of April 2026:

  • Standard resolution (768×768 or smaller): approximately 258 tokens (reduced from 1,290 in the April 2026 update)
  • High resolution (larger than 768×768): scales with tile count. A 4096×4096 image consumes roughly 2,580 tokens
  • Gemini 2.5 Flash Image: input token count already reduced to 258

The implication is clear: sending images at unnecessarily high resolution burns tokens without meaningfully improving recognition accuracy for most use cases.

PDF Tokenization Rules

PDFs are internally converted to page-level images, and each page follows the same tokenization rules as standalone images.

  • Each page consumes roughly 258–1,000 tokens depending on visual complexity
  • A 100-page PDF sent in full can consume 25,800–100,000 tokens
  • Even text-heavy PDFs are processed as images, so pre-extracting text doesn't reduce tokens if you still send the PDF

Video Tokenization Rules

Video is sampled at 1 frame per second, with each frame tokenized as an image.

  • Approximately 258 tokens per second at standard resolution
  • A 10-minute video = 600 frames ≈ 154,800 tokens
  • If the audio track is included, add roughly 32 tokens per second

Audio Tokenization Rules

Audio uses its own encoding pipeline.

  • Approximately 32 tokens per second
  • 1 hour of audio ≈ 115,200 tokens
  • Format differences (MP3, WAV, FLAC) don't affect token count — the API normalizes internally
import google.genai as genai
 
client = genai.Client(api_key="YOUR_API_KEY")
 
def count_tokens_for_input(file_path: str, mime_type: str) -> int:
    """Pre-measure token consumption for any multimodal input."""
    uploaded = client.files.upload(
        file=file_path,
        config={"mime_type": mime_type}
    )
    
    response = client.models.count_tokens(
        model="gemini-2.5-flash",
        contents=[uploaded]
    )
    
    print(f"File: {file_path}")
    print(f"Tokens: {response.total_tokens:,}")
    print(f"Estimated cost: ${response.total_tokens * 0.00000015:.4f}")
    # Gemini 2.5 Flash input cost: $0.15/1M tokens
    
    return response.total_tokens
 
# Usage
count_tokens_for_input("report.pdf", "application/pdf")
count_tokens_for_input("screenshot.png", "image/png")
count_tokens_for_input("meeting.mp3", "audio/mp3")

Measuring your current token consumption is always step one. You can't optimize what you haven't measured.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
If multimodal input costs are ballooning beyond your budget, you'll get concrete, modality-specific strategies to bring them under control
You'll walk away with copy-paste Python preprocessing pipelines for images, PDFs, video, and audio that slot into your existing codebase
You'll learn architecture patterns backed by real-world benchmarks that cut monthly API bills by 50–70%
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

API / SDK2026-06-14
Controlling Image Tokens with the Gemini API media_resolution Setting — Tuning Batch Image Classification by Measurement
media_resolution, introduced in the Gemini 3 line, switches how many tokens an image input consumes across three levels. Through real batch-classification measurements, this guide shows how to balance cost and accuracy by assigning the right tier per task.
API / SDK2026-07-02
Routing Between Local Gemma 4 and the Gemini API Cut My Bill from ¥32,000 to ¥9,000 — A Production Hybrid Router Design
How I cut a ¥32,000/month Gemini API bill to the ¥9,000 range with hybrid inference: routing design, a full Python router, production pitfalls, and how Gemma 4 arriving on the Gemini API in July 2026 changes the decision.
API / SDK2026-06-28
Mixing Text and Images in One File Search Skewed My Results Toward Images — Rebalancing by Modality After Retrieval
When you put text and images in a single File Search store with gemini-embedding-2, results can quietly skew toward one modality. Here is how to measure that skew and even it out after retrieval, using per-modality normalization and quota-based merging — with working code.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →