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
Deep Research
Autonomous research with citations
Antigravity
Autonomous sandboxed agent
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.Managed Agents
Settingagent instead of id switches GeminiInteractions to Google’s managed agent path (agent + agent_config instead of model + generation_config). Two agents are supported:
agent is mutually exclusive with id. Per-agent semantics (background execution, sandbox provisioning) are forced by the SDK based on the agent ID.
Deep Research
Deep Research plans the task, searches the web, and returns a researched report with citations. The model forcesbackground=True and store=True, and the non-streaming path polls until the result is ready.
Read more about Deep Research here.
Antigravity
Antigravity is a general-purpose autonomous agent that plans, runs code, browses the web, and produces artifacts inside a managed Linux sandbox. Unlike Deep Research, it runs in the foreground.environment parameter selects the sandbox:
Read more about Antigravity here.
Interactions API vs generateContent
Params
GeminiInteractions is a subclass of the Model class and has access to the same params.