Search⌘ K
AI Features

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.

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 ...

Python 3.14.0
from google import genai
from google.genai import types
client = genai.Client(api_key="{{GOOGLE_GEMINI_API_KEY}}")
MODEL_ID = "gemini-3.6-flash"
response = client.models.generate_content(
model=MODEL_ID,
contents="My invoice shows two charges for March. What should I do?",
config=types.GenerateContentConfig(
system_instruction="You are a billing support assistant. Reply in plain text, in two sentences or fewer.",
temperature=0.2,
max_output_tokens=1024,
),
)
print(response.text)
print("Finish reason:", response.candidates[0].finish_reason)
print("Input tokens:", response.usage_metadata.prompt_token_count)
print("Output tokens:", response.usage_metadata.candidates_token_count)
  • Lines 1–2: We import the Google Gen AI SDK ...