Module 18.1 closes the vendor triangle: OpenAI, Anthropic, and now Gemini (Google). You already left Vol. 17’s Automatic1111 / ComfyUI studios for hosted clients. Gemini is the multimodal-native option—text, images, audio, video, and PDF parts in one contents payload—plus Google Cloud / Vertex paths for enterprises.
This page is the last SDK. Module 18.2 starts immediately after: what an API even is, then FastAPI so your app does not import three vendor SDKs in the browser.
Learning Objectives
By the end of this lesson, students should be able to:
- Authenticate Google’s Gen AI SDK (
google-genai) via API key or Vertex ADC. - Call
generate_contentwith string or multi-partcontents. - Read text, usage metadata, and safety / finish signals from the response.
- Contrast Gemini’s multimodal parts with OpenAI messages and Anthropic blocks.
- Sketch grounding / Google Search tools vs Vol. 15 function calling.
- Hand off all three SDKs to a single backend API in Module 18.2.
Gemini is Google’s multimodal model family. The Gemini SDK here means the official Google Gen AI client (from google import genai / google-genai), which talks to the Gemini Developer API or Vertex AI. You send a model ID plus contents (text and/or inline/file parts). It is not Imagen’s still-image catalog alone (Imagen is a sibling product), and it is not a local Comfy graph.
Three SDKs, One Shipping Job
| SDK | Auth (typical) | Core call | Signature strength |
|---|---|---|---|
| OpenAI | OPENAI_API_KEY | chat.completions / Responses | Ecosystem + Azure-compat |
| Anthropic | ANTHROPIC_API_KEY | messages.create | Long context, Messages blocks |
| Gemini | GEMINI_API_KEY or Vertex ADC | models.generate_content | Native multimodal + Google cloud |
google-genai Sketch
Package names shifted historically (google-generativeai vs google-genai). Teach the current official client; re-read docs before a spike. Model IDs are SKUs.
Multimodal vs Vol. 16 / 17
Gemini parts
- Understand image/PDF/audio in-context
- Great for “what is in this still?”
- Hosted; ToS + safety filters
Vol. 16 / 17 stills
- Imagen / DALL·E generate
- SD/FLUX + ControlNet self-host
- A1111/Comfy remain studios
Module 18.2
- One
POST /v1/chat - Provider switch in config
- Auth, stream, meter, deploy
Reach for Gemini when
- You need cheap/fast multimodal understanding
- You already live on GCP / Vertex
- Grounding with Google Search is a product requirement
Still abstract it
- Do not leak
google.genaitypes to the SPA - Safety ratings ≠ your authz policy
- Vertex vs AI Studio is a deploy choice, not a new architecture
Related Lectures
| Lecture | Why |
|---|---|
| OpenAI / Anthropic | Sibling SDKs; same adapter job |
| Vision / Imagen | Understand vs generate images |
| Tool calling | Gemini function / grounding tools |
| API | Next module—your HTTP contract |
“Gemini is just Google’s ChatGPT.” Product UIs differ; the SDK contract is contents + parts, and Vertex vs AI Studio changes auth. Second: feeding a PNG to Gemini is understanding, not running Stable Diffusion. Third: google.generativeai notebook snippets from 2024 may not match google-genai today—read current docs. Fourth: finishing Module 18.1 is not shipping; without your own API, every frontend still holds a vendor key.
Knowledge Check
- Short Answer: Name the current official Python import path used in this lecture. Answer: google.genai (package google-genai), via genai.Client.
- True/False: Gemini
contentscan include image bytes plus text. Answer: True. - Multiple Choice: Vertex ADC is primarily: (a) cloud credentials, not a browser cookie, (b) a DDIM sampler, (c) a Redis eviction policy. Answer: (a).
- Short Answer: Why is Gemini the last lecture in Module 18.1? Answer: Completes the three-vendor SDK set before Module 18.2 backends.
- True/False: Calling Gemini vision replaces Automatic1111 for txt2img. Answer: False—vision understands; generation is Imagen/SD/FLUX/etc.
- Multiple Choice: Next page after this lecture: (a) API (18.2), (b) CUDA, (c) t-SNE. Answer: (a).
- Short Answer: Where should
GEMINI_API_KEYlive? Answer: Server env / secret store—not the SPA. - True/False: You should expose google.genai response objects directly to mobile clients. Answer: False—normalize to your API DTO.
- Multiple Choice: Gemini’s closest OpenAI analogue for chat is: (a) generate_content, (b) k-means, (c) PNG Info. Answer: (a).
- Short Answer: Name one thing Module 18.2 adds that SDKs alone do not. Answer: Any of: your HTTP API, FastAPI, auth, Docker, queues, streaming gateway, monitoring.
Key Takeaways
- Gemini SDK:
google-genai+generate_content+ multimodal parts. - AI Studio key vs Vertex ADC is auth/deploy, not a new model family.
- Understand (Gemini) ≠ generate (Imagen / SD / FLUX / A1111).
- Module 18.1 done: three vendors. Abstract them.
- Next module: API.
Lab: Same question to OpenAI, Anthropic, and Gemini. Then send a still (from A1111 or phone) only to Gemini vision. Design a one-page interface: ChatRequest {provider, messages, attachments[]}.
Whiteboard: Arrow all three SDKs into “your API.” Cross out keys in the browser. That box is Module 18.2.
Recap: Gemini completes Module 18.1. Ship through your own HTTP API next: API (Application Programming Interface).