Gemini by Example

Gemini is Google's most capable AI model for generating text, code, images, and more. Please visit the official documentation to learn more.

Gemini by Example is a hands-on introduction to Google's Gemini SDK and API using annotated code examples. Check out the first example or browse the full list of sections below. This site takes inspiration from gobyexample.com, from which I learned many things about the Go programming language. You may use arrow keys to navigate between examples.

Examples here assume Python >=3.9 and the latest version of the Gemini SDK/API (the google-genai package). Try to upgrade to the latest versions if something isn't working.

Text

Images

Audio

Video

PDFs and other data types

Agentic behaviour

Token counting & context windows

Miscellaneous