The Gemini API
Explore how Gemini requests and responses are structured, including contents, system instructions, finish reasons, and token usage. Learn to use function calling and structured output to build reliable agent components, and choose between Flash and Pro models based on task requirements.
We'll cover the following...
Almost every Google FDE system design eventually comes down to a call to a Gemini model. An agent built with ADK, a retrieval pipeline, or a ticket classifier all depend on the same basic exchange: the application sends a request with context and instructions, and the model returns a response. Interviewers expect candidates to understand this exchange well enough to explain how an agent decides to call a tool, how its output becomes reliable data, and why one model tier fits a task better than another.
The sections below cover the structure of a Gemini request and response, function calling, structured output, and the trade-offs between the Flash and Pro model tiers. The code examples use the Google Gen AI SDK for Python, which works with both the Gemini Developer API and Google Cloud’s enterprise platform.
The anatomy of a request
A Gemini request has a small number of parts, and each one controls a different aspect of the model’s behavior.
Part | Purpose | Example |
Model | Selects the model tier and version | A Flash or Pro model ID |
Contents | The conversation so far, as a list of turns | A user question, previous model replies |
System instruction | Persistent guidance on role, tone, and rules | “You are a billing support assistant.” |
Generation config | Controls output behavior | Temperature, maximum output tokens, response format |
Tools | Functions or services the model may call | An order lookup function |
Contents are organized into turns, and each turn has a role, either user or model, and one or more parts. A part can be text, an image, a document, a function call, or a function result. This structure is what allows a single API to handle chat, multimodal input, and tool use.
The model is stateless. It does not remember earlier requests, so the application sends the relevant conversation history with each call. In production, this is why session management matters: an agent’s memory is whatever the application chooses to include in the next request.
The following example sends a simple request with a system instruction and generation ...
Lines 1–2: We import the Google Gen AI SDK ...