Skip to content

feat(ai-gemini): expose stateful Interactions API (previous_interaction_id) #501

Description

@tombeckenham

Problem

The @google/genai SDK (v1.43+) exposes a preview Interactions API that provides server-side conversation state — the Gemini equivalent of OpenAI's Responses API (previous_response_id / conversation). This lets callers skip storing and replaying message history on their side.

// @google/genai
const interaction1 = await ai.interactions.create({
  model: 'gemini-2.5-flash',
  input: 'Hi, my name is Amir.',
})

const interaction2 = await ai.interactions.create({
  model: 'gemini-2.5-flash',
  input: 'What is my name?',
  previous_interaction_id: interaction1.id, // server-side state
})

Today the ai-gemini text adapter routes through the stateless client.models.generateContent / generateContentStream path (packages/typescript/ai-gemini/src/adapters/text.ts:131,177), so there's no way to take advantage of this — even via providerOptions.

For comparison, ai-openai already supports the equivalent pattern: it uses the Responses API (client.responses.create) and exposes previous_response_id / conversation via providerOptions (packages/typescript/ai-openai/src/text/text-provider-options.ts:30,49).

Proposal

Add first-class support for Gemini's Interactions API. Two reasonable shapes:

  1. New tree-shakeable adapter — e.g. geminiInteractions() alongside geminiText(), calling client.interactions.create under the hood. Matches the existing tree-shakeable adapter convention.
  2. Opt-in via providerOptions — e.g. providerOptions.previous_interaction_id on the existing text adapter, with the adapter routing to client.interactions.create when that option (or a dedicated flag) is present.

Option 1 is probably cleaner given the Interactions API has a different request/response shape than generateContent, and it keeps the stateless path simple.

Notes / caveats

  • The Interactions API is currently marked preview/experimental in @google/genai — worth flagging in docs and JSDoc.
  • Response-id capture: callers need a way to read the interaction id off the returned response to pass back next turn. Needs a small addition to the chat result shape, or a provider-specific metadata field.
  • Tool calling, streaming, and multimodal input parity with the existing text adapter should be confirmed against the Interactions API surface before shipping.

Context

Came up in discussion — users want to avoid plumbing conversation history through their own storage when the provider already offers it server-side. OpenAI side is already covered; Gemini side is the gap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions