generateContent endpoint. Instead of sending the full conversation history on every turn, it stores prior turns server-side and references them via previous_interaction_id. This reduces token costs and latency through implicit caching.
See the Interactions API documentation for more details.
Installation
Authentication
Set theGOOGLE_API_KEY environment variable. You can get one from Google AI Studio.
Example
View more examples here.
How It Works
- On the first turn, the agent sends the user message and receives a response along with an
interaction_id. - On subsequent turns, only the new message is sent with
previous_interaction_idreferencing the prior turn. - The server reconstructs the full context from stored history, applying implicit caching to reduce cost.
Agent class handles interaction_id tracking automatically.
Capabilities
Multi-turn
Server-side history management
Thinking
Reasoning with thinking levels
Google Search
Built-in web search
Tool Use
Function calling
Structured Output
Pydantic schema enforcement
Background Execution
Long-running tasks
Multi-turn Conversations
The key advantage of the Interactions API. Prior turns are stored server-side and referenced by ID, so only the new message is sent each turn.Thinking
Enable extended reasoning with thethinking_level parameter. Accepts "low" or "high".
Google Search
Enable built-in Google Search by settingsearch=True. No external tool needed.
Tool Use
Function calling works the same as with theGemini class.
Structured Output
Use Pydantic models to enforce a JSON schema on the response.Background Execution
For long-running tasks like Deep Research, enable background execution. The API offloads the task and returns results when complete.Interactions API vs generateContent
Params
GeminiInteractions is a subclass of the Model class and has access to the same params.