Lesson 16 Google Gemini
Theme:
Lesson 16 · Slide 1

Google Gemini

Google’s Gemini models offer unique capabilities including a 1M-token context window, native multimodal processing of images, video, audio, and documents, and tight integration with the Google ecosystem.

Learning Objectives

Lesson 16 · Slide 2

Gemini Model Family

Google offers three tiers of Gemini models, each balancing capability against speed and cost.

ModelInput (per MTok)Output (per MTok)ContextBest For
Gemini 2.5 Pro$1.25–$10$10–$301MComplex reasoning
Gemini 2.5 Flash$0.15–$0.60$0.60–$3.501MFast, cost-effective
Gemini 2.0 FlashFree tier availableFree tier available1MPrototyping

Key differentiator: Gemini 2.5 Flash offers a generous free tier (up to 500 RPD at no cost), making it excellent for prototyping and learning before committing to paid usage.

Lesson 16 · Slide 3

1M Token Context Window

Gemini’s 1M-token context window (roughly 700K words) opens use cases that were previously impossible with shorter context models.

Cost Consideration

Filling a 1M-token context costs $1.25–$10 per request depending on the model. For repeated queries over the same document, consider chunking + RAG as an alternative. Context length is a capability, not a mandate.

Lesson 16 · Slide 4

Multimodal: Image, Video, Audio, Documents

Gemini processes multiple input modalities natively, not through separate models.

import google.generativeai as genai

model = genai.GenerativeModel("gemini-2.5-flash")

# Analyse an image
response = model.generate_content([
    "Describe what you see in this image.",
    genai.upload_file("photo.jpg"),
])
print(response.text)
Note: Video and audio analysis are capabilities unique to Gemini among the major API providers. Claude and GPT-4o support images but have limited or no video/audio input support.
Lesson 16 · Slide 5

Google AI Studio vs Vertex AI

Google offers two platforms to access Gemini, each designed for different use cases.

Google AI Studio

  • Free tier available
  • Simple API key authentication
  • Best for prototyping and learning
  • google-generativeai SDK
  • Limited to Gemini models

Vertex AI

  • Enterprise GCP integration
  • IAM / service account auth
  • Best for production workloads
  • google-cloud-aiplatform SDK
  • Access to Claude, Llama, Mistral too

For this course, we use Google AI Studio with the google-generativeai SDK. The API surface is nearly identical; the main difference is authentication and enterprise features.

Lesson 16 · Slide 6

API Setup & SDK

Getting started with the google-generativeai SDK requires minimal setup.

pip install google-generativeai
import google.generativeai as genai
from dotenv import load_dotenv
import os

load_dotenv()
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))

model = genai.GenerativeModel("gemini-2.5-flash")
response = model.generate_content("Explain quantum entanglement simply.")
print(response.text)
print(f"Tokens: {response.usage_metadata.prompt_token_count} in, "
      f"{response.usage_metadata.candidates_token_count} out")

Key difference from OpenAI/Anthropic: Gemini uses a GenerativeModel object rather than passing the model name to each call. You create the model once and call generate_content() on it. Chat sessions use model.start_chat().

Lesson 16 · Slide 7

Demo: Analyse a Document with Gemini

Live demonstration: use Gemini’s long context to analyse a complete document.

Demo Steps

  1. Configure the Gemini SDK with API key
  2. Load a long document (~50K tokens)
  3. Send the full document as context with analysis questions
  4. Demonstrate multi-turn conversation about the document
  5. Show token usage metadata
  6. Compare the same task with Claude (200K context) and note differences
Notes: Emphasise that long context is not free — show the cost of a 50K-token input request and compare with a RAG approach that might use only 2K tokens of retrieved context.
Lesson 16 · Slide 8

Lab & Homework

Lab Exercises

  1. First Call — set up Gemini API, make a call with gemini-2.5-flash
  2. Long Context — analyse a long text (~50K tokens)
  3. Multimodal — describe an image using Gemini

Homework Tasks

  1. Gemini 1M context for codebase analysis
  2. PDF analyser with native doc understanding
  3. Compare Gemini Flash vs Claude Haiku on 20 tasks
1 / ?