Table of Contents

Class InteractionsClient

Namespace
GenerativeAI.Clients
Assembly
GenerativeAI.dll

A client for the Gemini Interactions API (/interactions): stateful model and agent interactions (e.g. Deep Research, Antigravity) with server-side state, background execution, Server-Sent Event streaming, stream resumption and continuation of long decodes. Works with the Gemini Developer API and Vertex AI.

public class InteractionsClient : BaseClient
Inheritance
InteractionsClient
Inherited Members
Extension Methods

Constructors

InteractionsClient(IPlatformAdapter, HttpClient?, ILogger?)

Initializes a new instance of the InteractionsClient class.

public InteractionsClient(IPlatformAdapter platform, HttpClient? httpClient = null, ILogger? logger = null)

Parameters

platform IPlatformAdapter

The platform adapter (Google AI or Vertex AI).

httpClient HttpClient

Optional HTTP client.

logger ILogger

Optional logger.

Properties

EnableAutomaticContinuation

Whether CreateAsync(CreateInteractionRequest, CancellationToken) automatically resumes an interaction whose status is RequiresContinuation (default true, as in python-genai). The returned interaction is the last hop, with the steps of all hops.

public bool EnableAutomaticContinuation { get; set; }

Property Value

bool

MaxContinuations

The maximum number of continuation requests per create call (default 10).

public int MaxContinuations { get; set; }

Property Value

int

MaxStreamReconnects

How many times StreamAsync(CreateInteractionRequest, CancellationToken) resumes a stream that fails after the interaction was created, using the last received event ID (default 3; 0 disables it).

public int MaxStreamReconnects { get; set; }

Property Value

int

Methods

CancelAsync(string, CancellationToken)

Cancels a running (background) interaction.

public Task<Interaction> CancelAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string

The interaction ID.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Interaction>

The interaction after cancellation.

ContinueAsync(Interaction, CreateInteractionRequest?, CancellationToken)

Continues an interaction whose status is RequiresContinuation (see CreateContinuationRequest(Interaction, CreateInteractionRequest?)). Each continuation re-prefills and bills input tokens; background interactions are continued by the server.

public Task<Interaction> ContinueAsync(Interaction interaction, CreateInteractionRequest? originalRequest = null, CancellationToken cancellationToken = default)

Parameters

interaction Interaction

The interaction to continue.

originalRequest CreateInteractionRequest

The request that created the interaction, if available.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Interaction>

The new interaction produced by the continuation hop.

CreateAsync(CreateInteractionRequest, CancellationToken)

Creates an interaction and returns it once the request completes (or, with Background, as soon as it has been queued).

public Task<Interaction> CreateAsync(CreateInteractionRequest request, CancellationToken cancellationToken = default)

Parameters

request CreateInteractionRequest

The request. Stream is ignored; use StreamAsync(CreateInteractionRequest, CancellationToken).

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Interaction>

The interaction.

See Also

CreateAsync(string, InteractionInput, CancellationToken)

Creates a model interaction from a model ID and an input.

public Task<Interaction> CreateAsync(string model, InteractionInput input, CancellationToken cancellationToken = default)

Parameters

model string

The model ID (see InteractionModels).

input InteractionInput

The input: a string, content blocks or steps.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Interaction>

The interaction.

CreateContinuationRequest(Interaction, CreateInteractionRequest?)

Builds the request that continues an interaction whose status is RequiresContinuation, following python-genai: the ContinuationToken is passed back unchanged; when the original request was stored (the default) the interaction is referenced by previous_interaction_id and no input is sent, otherwise (store=false) the original input is sent again.

public static CreateInteractionRequest CreateContinuationRequest(Interaction interaction, CreateInteractionRequest? originalRequest = null)

Parameters

interaction Interaction

The interaction to continue.

originalRequest CreateInteractionRequest

The request that created the interaction. When omitted, the model/agent of interaction are used and the interaction is assumed to be stored.

Returns

CreateInteractionRequest

The continuation request.

DeleteAsync(string, CancellationToken)

Deletes an interaction.

public Task DeleteAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string

The interaction ID.

cancellationToken CancellationToken

A cancellation token.

Returns

Task

A task that completes when the interaction has been deleted.

GetAsync(string, bool?, CancellationToken)

Retrieves an interaction by ID.

public Task<Interaction> GetAsync(string id, bool? includeInput = null, CancellationToken cancellationToken = default)

Parameters

id string

The interaction ID (an interactions/ prefix is accepted).

includeInput bool?

If true, includes the input in the response.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Interaction>

The interaction.

GetInteractionsUrl()

Gets the base URL of the interactions collection, e.g. https://generativelanguage.googleapis.com/v1beta/interactions or https://{location}-aiplatform.googleapis.com/{version}/projects/{project}/locations/{location}/interactions.

protected string GetInteractionsUrl()

Returns

string

The collection URL.

ResumeStreamAsync(string, string?, bool?, CancellationToken)

Streams the events of an existing interaction (GET /interactions/{id}?stream=true), e.g. a background interaction, or resumes a dropped stream after lastEventId.

public IAsyncEnumerable<InteractionSseEvent> ResumeStreamAsync(string id, string? lastEventId = null, bool? includeInput = null, CancellationToken cancellationToken = default)

Parameters

id string

The interaction ID.

lastEventId string

If set, resumes the stream from the event after this event ID.

includeInput bool?

If true, includes the input in the interaction.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<InteractionSseEvent>

The stream of events.

StreamAsync(CreateInteractionRequest, CancellationToken)

Creates an interaction and streams its Server-Sent Events (interaction.created, step.start, step.delta, step.stop, interaction.status_update, interaction.completed, error). Keep the last EventId to resume a dropped stream with ResumeStreamAsync(string, string?, bool?, CancellationToken).

public IAsyncEnumerable<InteractionSseEvent> StreamAsync(CreateInteractionRequest request, CancellationToken cancellationToken = default)

Parameters

request CreateInteractionRequest

The request; Stream is set to true.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<InteractionSseEvent>

The stream of events.

WaitForCompletionAsync(string, TimeSpan?, TimeSpan?, CancellationToken)

Polls an interaction (typically one created with Background) until it is no longer InProgress or Queued.

public Task<Interaction> WaitForCompletionAsync(string id, TimeSpan? pollInterval = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

id string

The interaction ID.

pollInterval TimeSpan?

Delay between polls (default 10 seconds).

timeout TimeSpan?

Optional overall timeout; a TimeoutException is thrown when exceeded.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Interaction>

The interaction in its final (or action/continuation-required) state.

See Also