A Guide to Multimodal Token Calculation (Image, Video, and Audio Tokens) in Gemini 2.5 Pro/Flash
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.
