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 for more details.
The Interactions API is experimental and may change in future versions. You will see the following warning when using it:
Requires google-genai>=2.0.

Installation

Authentication

Set the GOOGLE_API_KEY environment variable. You can get one from Google AI Studio.

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

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.
Read more about multi-turn conversations here.

Thinking

Enable extended reasoning with the thinking_level parameter. Accepts "low" 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

For long-running tasks like Deep Research, enable background execution. The API offloads the task and returns results when complete.

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