Build Stateful Agentic Apps with the Gemini Interactions API

85 min remaining
Step 2 of 12•5 min

2. Understand the Interactions API

With generateContent, every request is independent. To hold a conversation, your code keeps the history and sends all of it, every turn, in the exact order the model expects. With the Interactions API, each call to client.interactions.create() produces an interaction resource that is stored on the server (store defaults to True). The response holds the new steps the model produced: thoughts, function calls and its output. To continue, you send only the new input and the ID of the interaction to continue from.

turns_example.py(python)
12345678910
# Turn 1
interaction = client.interactions.create(model=MODEL, input="Main power lost.", tools=TOOLS)
 
# Turn 2: send only what is new, plus where to continue from
interaction = client.interactions.create(
model=MODEL,
previous_interaction_id=interaction.id,
input=[{"type": "function_result", "call_id": call.id, "name": call.name, "result": "..."}],
tools=TOOLS,
)

Stateless vs stateful

FeaturegenerateContentInteractions API
Where history livesIn your codeOn the server, linked by interaction ID
What you send each turnThe whole history, every timeOnly the new input or tool results
What the model readsThe whole historyThe whole history too, loaded on the server, with implicit caching
Tool calls and resultsfunctionCall and functionResponse partsfunction_call steps and function_result inputs matched by call_id
Response shapeCandidates with partsTyped steps: thought, function_call, model_output
StatusFinish reasoncompleted, requires_action, in_progress, failed, cancelled, incomplete

What carries over, and what does not

previous_interaction_id carries over the conversation history only. The model, tools, system_instruction and generation_config apply to a single interaction, so you send them on every request. Forgetting this is the most common bug: the agent quietly loses its instructions after the first turn.

SDK and Model Requirements

The Interactions API requires the unified Google Gen AI SDK (google-genai >= 2.3.0) and uses gemini-3.8-flash as the recommended default model. Legacy SDKs (google-generativeai, google-cloud-aiplatform) are not supported for the Interactions API, and deprecated model families (gemini-2.5-*, gemini-2.0-*, gemini-1.5-*) should not be used.

The trade-offs

  • Retention: Stored interactions are kept for 1 day on the free tier and up to 55 days on paid tiers. Long-lived sessions need a plan.
  • Opting out: store=False keeps nothing on the server, but it also turns off previous_interaction_id and background execution.
  • Context still costs: The model still reads the full history on every turn. You stop managing it, and implicit caching lowers the cost, but long sessions still grow.
  • Your environment is still yours: The server remembers the conversation, not the state of the systems your tools change. You will see why this matters when you branch a session.
Check Your Knowledge

When continuing a session with previous_interaction_id, what is automatically carried over by the server?