C.W.K.
Stream
Lesson 01 of 04 · published

Image, Video & Audio

~14 min · multimodal, vision, video, audio, file-api

Level 0Spark
0 XP0/35 lessons0/10 achievements
0/140 XP to next level140 XP to go0% complete

One model, three modalities

Gemini 2.5 Flash and Pro accept text, images, video, and audio in the same conversation. You don't switch models or endpoints — you just include the right Part type in your contents.

Two ways to attach media

  • Inline bytes — base64-encode the file, send it in the request. Best for small files (≤ 20MB total request size).
  • File API — upload first via client.files.upload, then reference the resulting file URI. Required for anything large; required for video.

Files uploaded via the File API live for 48 hours. Plenty of time to make the actual generation call.

Token costs are fixed-per-shape, not character-based

  • Images: ≤ 384px = 258 tokens. Larger = 258 per 768×768 tile.
  • Video: ~300 tokens/second. Max 1 hour. YouTube URLs supported directly.
  • Audio: 32 tokens/second. Max 9.5 hours.

Supported formats

  • Image: PNG, JPEG, WEBP, HEIC.
  • Video: MP4, MOV, AVI, FLV, MPG, WMV, 3GPP, WEBM.
  • Audio: WAV, MP3, AIFF, AAC, OGG, FLAC.

Code

Image — inline bytes·python
from google import genai
from google.genai import types
from pathlib import Path

client = genai.Client()
img_bytes = Path('photo.jpg').read_bytes()

response = client.models.generate_content(
    model='gemini-2.5-flash',
    contents=[
        types.Part.from_bytes(data=img_bytes, mime_type='image/jpeg'),
        'Caption this image in one sentence.',
    ],
)
print(response.text)
Image — File API (preferred for large files)·python
uploaded = client.files.upload(file='photo.jpg')

response = client.models.generate_content(
    model='gemini-2.5-flash',
    contents=[uploaded, 'Describe in 3 sentences.'],
)
print(response.text)

# When done
client.files.delete(name=uploaded.name)
Video — wait for processing·python
import time

uploaded = client.files.upload(
    file='lecture.mp4',
    config=types.UploadFileConfig(display_name='Lecture'),
)

# Big videos go through PROCESSING — poll until ACTIVE
while uploaded.state.name == 'PROCESSING':
    time.sleep(2.5)
    uploaded = client.files.get(name=uploaded.name)

response = client.models.generate_content(
    model='gemini-2.5-flash',
    contents=[uploaded, 'Summarize the key points.'],
)
Audio — transcription·python
uploaded = client.files.upload(file='podcast.mp3')

response = client.models.generate_content(
    model='gemini-2.5-flash',
    contents=[
        'Transcribe this audio. Use proper punctuation and paragraph breaks.',
        uploaded,
    ],
)
print(response.text)

External links

Exercise

Pick three small files from your machine — one image, one short video (≤ 30 sec), one audio clip. Build a single Python script that uploads each via the File API, sends it to Flash with an appropriate prompt (caption / describe / transcribe), prints the response, and deletes the file. Catch + report any PROCESSING delays.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.