When developing text-only LLM applications, estimating API costs is simple: 1,000 words is roughly 1,333 tokens.
When building multimodal applications—processing uploaded receipt photos, medical DICOM scans, WhatsApp audio voice notes, or MP4 security camera recordings—calculating API expenses becomes significantly more complex:
- How many tokens does a 4K 12-megapixel smartphone photo consume?
- How is a 5-minute customer support call recording metered?
- How do Google Gemini, OpenAI GPT-4o, and Anthropic Claude differ in billing video streams?
Without understanding the underlying tokenization mechanics, an application that seems inexpensive during testing can generate catastrophic cloud bills when users upload high-resolution media.
This guide provides the exact mathematical formulas used by OpenAI, Google Gemini, and Anthropic to calculate multimodal tokens, complete with a production Python pricing calculator.
1. Image Token Calculation Formulas
Raw Image Upload (e.g. 2400 x 3600 px)
│
▼
┌─────────────────────────────────┴─────────────────────────────────┐
│ │
▼ ▼
┌───────────────────────────────────────────┐ ┌───────────────────────────────────────────┐
│ OpenAI GPT-4o (Dynamic Patch Grid) │ │ Google Gemini 2.5 (Fixed Grid Patch) │
│ 1. Downscale to fit inside 2048x2048 │ │ Standard image normalized to single patch │
│ 2. Scale shortest side to 768px │ │ Flat Rate: 258 tokens per image │
│ 3. Cut into 512x512 tiles: │ │ │
│ Tokens = (Tiles * 170) + 85 │ │ At $0.075/M tokens: │
│ (4 tiles = 765 tokens -> $0.0019) │ │ Cost = $0.000019 (51,000 images per $1) │
└───────────────────────────────────────────┘ └───────────────────────────────────────────┘
Google Gemini (Fixed Patching)
Google utilizes a highly efficient unified patch tokenizer. Standard images are normalized to a flat rate:
- Flat Rate: 258 tokens per image.
- At Gemini 2.5 Flash input pricing ($0.075 / 1M tokens):
You can analyze over 51,000 full-resolution images for a single dollar.
OpenAI GPT-4o (Dynamic 512×512 Tiling)
OpenAI meters images using a two-step bounding calculation:
- If image exceeds 2048×2048, downscale to fit within 2048×2048.
- Scale the shortest side to exactly 768px.
- Compute how many 512×512 tiles are required to cover the image.
- Low-Res Mode: Fixed at 85 tokens ($0.00021 on GPT-4o).
- Standard 1080×1920 Smartphone Photo:
- Rescaled to 768×1365.
- Requires 2 horizontal tiles $\times$ 3 vertical tiles = 6 tiles.
- Tokens: $(6 \times 170) + 85 = \mathbf{1,105\text{ tokens}}$ (~$0.00276 per photo).
Anthropic Claude 3.5 Sonnet
Anthropic meters images based on total pixel surface area:
\[\text{Tokens} = \frac{\text{Width} \times \text{Height}}{750}\]- Capped at approximately 1,600 tokens maximum per image.
- At Claude 3.5 Sonnet pricing ($3.00 / 1M tokens), a standard full-resolution photo costs $\approx \mathbf{$0.0048}$ (roughly 250x more expensive than Gemini 2.5 Flash).
2. Audio Token Calculation: The 32 Tokens/Sec Constant
When foundation models process raw audio (e.g. WAV, MP3, AAC), the audio waveform is downsampled to 16kHz mono PCM and transformed into discrete spectral embeddings:
┌────────────────────────────────────────────────────────────────────────┐
│ AUDIO TOKEN CONVERSION FORMULA │
├────────────────────────────────────────────────────────────────────────┤
│ Audio Sampling Rate: 16 kHz Mono PCM │
│ Token Conversion Rate: ~32 tokens per second of speech │
│ 1 Minute Voice Recording: 60 sec × 32 tokens = 1,920 tokens │
│ 1 Hour Continuous Audio: 3,600 sec × 32 tokens = 115,200 tokens │
└────────────────────────────────────────────────────────────────────────┘
Financial Impact of Native Audio vs. Whisper Pre-Transcription:
- Option A: Traditional Pipeline: Transcribe via OpenAI Whisper API ($0.006 per minute) $\rightarrow$ feed text to GPT-4o.
- 1 Hour of Audio: $0.360 (Whisper) + $0.02 (Text) = $0.380.
- Option B: Native Gemini 2.5 Flash Audio:
- 1 Hour of Audio: 115,200 tokens @ $0.075 / 1M tokens = $0.0086 (less than 1 cent!).
- Native multimodal ingestion is 44x cheaper than legacy speech-to-text pipelines.
3. Video Processing Math: Temporal Downsampling
When passing an MP4 or WebM video into Gemini or GPT-4o, the model does not ingest 60 frames per second. Video is temporally downsampled to 1 frame per second (1 fps) by default:
\[\text{Total Video Tokens} = (\text{Duration in Seconds} \times \text{Tokens per Frame}) + (\text{Duration in Seconds} \times \text{Audio Tokens per Sec})\]For a standard 60-second social video clip processed on Gemini 2.5 Flash:
- Visual Frames: $60 \text{ seconds} \times 1 \text{ fps} \times 258 \text{ tokens/frame} = \mathbf{15,480\text{ tokens}}$.
- Audio Track: $60 \text{ seconds} \times 32 \text{ tokens/sec} = \mathbf{1,920\text{ tokens}}$.
- Total Ingestion Payload: $15,480 + 1,920 = \mathbf{17,400\text{ tokens}}$.
- Total Cost: $\frac{17,400}{1,000,000} \times $0.075 = \mathbf{$0.0013}$ (about one-tenth of a cent per video).
4. Production Python Multimodal Token Calculator
Below is a standalone utility class that accurately computes token counts and projected dollar costs across media types:
import math
from typing import Dict
class MultimodalTokenCalculator:
@staticmethod
def calculate_image_tokens(width: int, height: int, provider: str = "gemini") -> int:
if provider.lower() == "gemini":
return 258 # Flat patch rate
elif provider.lower() == "openai":
# Scale to 2048 max bounding box
if width > 2048 or height > 2048:
scale = 2048 / max(width, height)
width, height = int(width * scale), int(height * scale)
# Scale shortest side to 768px
scale = 768 / min(width, height)
width, height = int(width * scale), int(height * scale)
# Count 512x512 tiles
tiles_x = math.ceil(width / 512)
tiles_y = math.ceil(height / 512)
return (tiles_x * tiles_y * 170) + 85
elif provider.lower() == "anthropic":
return min(1600, int((width * height) / 750))
raise ValueError(f"Unknown provider: {provider}")
@staticmethod
def calculate_audio_tokens(duration_seconds: float) -> int:
"""Estimates audio tokens based on 32 tokens/second constant."""
return int(duration_seconds * 32)
@staticmethod
def calculate_video_tokens(duration_seconds: float, fps: float = 1.0, provider: str = "gemini") -> int:
"""Calculates combined frame image tokens and audio tokens."""
num_frames = int(duration_seconds * fps)
frame_tokens = num_frames * (258 if provider == "gemini" else 765)
audio_tokens = int(duration_seconds * 32)
return frame_tokens + audio_tokens
@classmethod
def estimate_job_cost(cls, num_images: int, audio_minutes: float, video_minutes: float) -> Dict[str, float]:
"""Calculates total dollar costs across Gemini 2.5 Flash vs GPT-4o."""
# 1. Total tokens
gemini_img_tokens = num_images * 258
openai_img_tokens = num_images * 765
audio_tokens = cls.calculate_audio_tokens(audio_minutes * 60)
gemini_video_tokens = cls.calculate_video_tokens(video_minutes * 60, provider="gemini")
openai_video_tokens = cls.calculate_video_tokens(video_minutes * 60, provider="openai")
gemini_total = gemini_img_tokens + audio_tokens + gemini_video_tokens
openai_total = openai_img_tokens + audio_tokens + openai_video_tokens
# Pricing per million tokens: Gemini Flash = $0.075, GPT-4o = $2.50
return {
"gemini_2_5_flash_usd": (gemini_total / 1_000_000) * 0.075,
"openai_gpt4o_usd": (openai_total / 1_000_000) * 2.50
}
if __name__ == "__main__":
costs = MultimodalTokenCalculator.estimate_job_cost(
num_images=500,
audio_minutes=120,
video_minutes=30
)
print("Projected Job Cost for 500 Images + 2h Audio + 30m Video:")
print(f"- Google Gemini 2.5 Flash: ${costs['gemini_2_5_flash_usd']:.4f}")
print(f"- OpenAI GPT-4o: ${costs['openai_gpt4o_usd']:.4f}")
5. Architectural FinOps Rules for Multimodal Pipelines
- Downscale Before Upload: Pre-scale images to 1500px on the longest dimension before sending to APIs. Uploading uncompressed 48-megapixel camera RAW files wastes network bandwidth without improving extraction accuracy.
- Cap Video Extraction to 0.5 FPS for Static Content: When analyzing presentations, lectures, or screen recordings, downsample from 1.0 fps to 0.5 fps (1 frame every 2 seconds). This cuts video token consumption by 50% with zero loss in comprehension.
- Use Gemini 2.5 Flash for High-Volume Media: At $0.075 per 1M input tokens and flat 258-token image patching, Gemini is 30x to 50x cheaper for visual and audio workloads than competing frontier models.
Download the 2026 AI API Cost Optimization Spreadsheet
A complete, ready-to-use template to model, calculate, and project your API bills for Gemini, OpenAI, Grok, and Claude.