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.
Installation
Authentication
Set theGOOGLE_API_KEY environment variable. You can get one from Google AI Studio. The Interactions API requires a Gemini API key and is not available on Vertex AI.
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
Prior turns are stored server-side and referenced by ID, so only the new message is sent each turn. This is the key advantage of the Interactions API. Multi-turn requires a database so theinteraction_id from each turn is persisted on the assistant message and read back on the next turn.
Thinking
Enable extended reasoning with thethinking_level parameter. Accepts "minimal", "low", "medium", 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
Deep Research runs long-running tasks in the background. It forcesbackground=True and store=True on the request; the non-streaming path polls until the result is ready, waiting agent_poll_interval seconds between polls up to agent_max_wait seconds. Background execution is handled automatically and has no user-facing flag on GeminiInteractions.
See Deep Research.
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 applied automatically 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.