A Guide to Multimodal Token Calculation (Image, Video, and Audio Tokens) in Gemini 2.5 Pro/Flash

A Guide to Multimodal Token Calculation (Image, Video, and Audio Tokens) in Gemini 2.5 Pro/Flash
Photo by Towfiqu barbhuiya / Unsplash

Hello!

When you use Gemini 2.5 Pro and Gemini 2.5 Flash, accurately tracking token counts is critical for cost calculation and context window management. In this article, we take a detailed look at how tokens are calculated for multimodal content: images, video, and audio.

Basic Concept: What Is a Token?

In the Gemini 2.5 series, one token corresponds to roughly 4 characters, and 100 tokens correspond to roughly 60-80 English words. All input and output is processed in units of tokens, and billing is also based on token counts.

Gemini 2.5 Series Models and Pricing

Available models

  • Gemini 2.5 Pro: flagship model with advanced reasoning capabilities
  • Gemini 2.5 Flash: fast, cost-efficient model
  • Gemini 2.5 Flash Image: dedicated image generation model

Context window

Both models offer a large context window of 1,000,000 tokens.

Pricing (preview stage)

Model Input price Output price
Gemini 2.5 Pro $4 per 1M tokens $20 per 1M tokens
Gemini 2.5 Flash $0.30 per 1M tokens $2.50 per 1M tokens
Gemini 2.5 Flash Image - 1,290 tokens per image (about $0.039)

Token Calculation for Images

Dynamic tiling system

The Gemini 2.5 series uses a dynamic tiling system that adapts to the image size.

Small images (384 pixels or less)

  • Images whose dimensions are both 384 pixels or less:a fixed 258 tokens

Larger images (over 384 pixels)

  • Divided into tiles of 768×768 pixels
  • Each tile: 258 tokens
  • Total tokens = number of tiles × 258

Implementation example

from google import genai

client = genai.Client()
prompt = "Please describe this image"

# Upload the image file
image_file = client.files.upload(file="sample_image.jpg")

# Count the tokens
token_count = client.models.count_tokens(
    model="gemini-2.5-flash",
    contents=[prompt, image_file]
)
print(f"Total tokens: {token_count}")
# Example: for a small image -> total_tokens: 263 (5 for text + 258 for the image)

How the number of tiles is calculated

def calculate_image_tokens(width, height):
    if width <= 384 and height <= 384:
        return 258
    else:
        tiles_width = (width + 767) // 768
        tiles_height = (height + 767) // 768
        return tiles_width * tiles_height * 258

Key points

  • Images uploaded via the File API and images provided as inline data consume the same number of tokens
  • Token counts vary with image resolution, so checking in advance is important

Token Calculation for Video

Fixed-rate method

Video is tokenized at a fixed, time-based rate.

Rate: 263 tokens per second

Calculation example

import time
from google import genai

client = genai.Client()
prompt = "Please summarize the content of this video"

# Upload the video file
video_file = client.files.upload(file="sample_video.mp4")

# Wait for video processing to complete
while video_file.state.name != "ACTIVE":
    print("Processing video...")
    time.sleep(5)
    video_file = client.files.get(name=video_file.name)

# Count the tokens
token_count = client.models.count_tokens(
    model="gemini-2.5-flash",
    contents=[prompt, video_file]
)
print(f"Total tokens: {token_count}")

Video length vs. token count

Video length Tokens
1 second 263
10 seconds 2,630
1 minute 15,780
5 minutes 78,900

Token Calculation for Audio

Fixed-rate method

Audio is also tokenized at a fixed, time-based rate.

Rate: 32 tokens per second

Audio length vs. token count

Audio length Tokens
1 second 32
10 seconds 320
1 minute 1,920
5 minutes 9,600

Practical Example: Using Usage Metadata

generate_content, once called, lets you retrieve detailed token information from usage_metadata.

response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents=[prompt, media_file]
)

# Retrieve detailed token information
metadata = response.usage_metadata
print(f"Input tokens: {metadata.prompt_token_count}")
print(f"Output tokens: {metadata.candidates_token_count}")
print(f"Total tokens: {metadata.total_token_count}")

# Retrieve cached tokens (if available)
if hasattr(metadata, 'cached_content_token_count'):
    print(f"Cached tokens: {metadata.cached_content_token_count}")

# Retrieve thinking tokens (only when using a thinking model)
if hasattr(metadata, 'thoughts_token_count'):
    print(f"Thinking tokens: {metadata.thoughts_token_count}")

Best Practices for Cost Optimization

1. Check token counts in advance

# Check the token count before calling generate_content
estimated_tokens = client.models.count_tokens(
    model="gemini-2.5-flash",
    contents=contents
)
if estimated_tokens > threshold:
    # Adjust the content or show a warning
    pass

2. Optimize images

  • Avoid unnecessarily large images (they increase the number of tiles)
  • Images of 384 pixels or less cost a fixed 258 tokens, so use small thumbnails when they are sufficient

3. Manage video and audio length

  • Video: extract and use only the parts you need
  • Audio: more efficient than video (32 tokens vs. 263 tokens for the same one second)

4. Context caching

In the Gemini 2.5 series, you can reduce token usage by taking advantage of context caching. Cached tokens are billed at half the normal rate.

5. Choose the right model

  • Complex tasks: Gemini 2.5 Pro
  • When you need fast processing: Gemini 2.5 Flash
  • When cost matters most: Gemini 2.5 Flash (about 1/7 of Pro's input cost)

Summary

Multimodal token calculation in Gemini 2.5 Pro/Flash follows these rules.

  • Images: 258 tokens for images up to 384px; otherwise number of tiles × 258 tokens
  • Video: 263 tokens per second
  • Audio: 32 tokens per second
  • Context window: 1 million tokens for both models

Understanding these calculation methods lets you predict API usage costs and manage the context window efficiently. Especially when developing large-scale multimodal applications, checking token counts in advance and optimizing your content are essential.

References

For more details, please refer to the official Gemini API documentation.

- Image token consumption in the OpenAI GPT series

OpenAI API: How Vision-Enabled LLMs Calculate Image Tokens (2025 Edition)
Hello! OpenAI's vision-enabled models (that is, LLMs that also accept image input) use two different methods for converting images into tokens. The latest GPT-5 and GPT-4.1 families introduce a patch-based method that differs from the traditional tile method. This change greatly improves the efficiency of image processing and enables finer control. The difference between the two methods: OpenAI currently operates two calculation methods in parallel, patch-based and tile-based. The patch-based method is used by new-generation models such as GPT-4.1-mini, GPT-4.1-nano, GPT-5-mini, GPT-5-nano, and o4-mini. It divides an image into very small 32×32-pixel patches. Compared with the traditional 512×512-pixel tiles, that is about 1/256 the size, enabling more precise image understanding. Meanwhile, flagship models such as GPT-4o, GPT-4.1, GPT-5, o1, and o3 continue to use the tile-based method, which

- Image token consumption in the Anthropic Claude series

Claude 4.5 API: A Guide to Calculating and Optimizing Image Input Tokens
Hello! In this article, we take a detailed look at how image token counts are calculated when using Claude 4.5 Sonnet/Haiku and Claude 4.1 Opus via the API. How image tokens are calculated: Images sent to the Claude 4.5 API are counted as tokens just like text, forming the basis of billing. If an image is within the API's size limits and does not need resizing, you can estimate its token count with a simple formula. Basic formula: tokens = (width px × height px) ÷ 750. Using this formula, you can predict costs before uploading and optimize images as needed. For example, a 1000×1000-pixel image consumes about 1,334 tokens, and under Claude 4.5 pricing you can calculate the per-image cost in advance. A 1092×1092-pixel (1.19-megapixel) image comes to about 1,590 tokens, which you can also use as a baseline for estimating batch-processing costs. Image size limits and optimization: The Claude 4.5 API has several important

Read more