Skip to main content
The Interactions API is an alternative to Gemini’s 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.
The Interactions API is experimental and may change in future versions. Requires google-genai>=2.0.

Installation

Authentication

Set the GOOGLE_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

  1. On the first turn, the agent sends the user message and receives a response along with an interaction_id.
  2. On subsequent turns, only the new message is sent with previous_interaction_id referencing the prior turn.
  3. The server reconstructs the full context from stored history, applying implicit caching to reduce cost.
This is transparent to the user. The 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 the interaction_id from each turn is persisted on the assistant message and read back on the next turn.
Read more about multi-turn conversations here.

Thinking

Enable extended reasoning with the thinking_level parameter. Accepts "minimal", "low", "medium", or "high".
Read more about thinking here. Enable built-in Google Search by setting search=True. No external tool needed.
Read more about Google Search here.

Tool Use

Function calling works the same as with the Gemini class.
Read more about tool use here.

Structured Output

Use Pydantic models to enforce a JSON schema on the response.
Read more about structured output here.

Background Execution

Deep Research runs long-running tasks in the background. It forces background=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

Setting agent 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 forces background=True and store=True, and the non-streaming path polls until the result is ready.
Deep Research config knobs: 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.
The 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.