Table of Contents

Class GoogleGenAIRealtimeClient

Namespace
Microsoft.Extensions.AI
Assembly
Google.GenAI.dll

Provides an Microsoft.Extensions.AI.IRealtimeClient implementation for Google GenAI's Live API.

public sealed class GoogleGenAIRealtimeClient : IRealtimeClient, IDisposable
Inheritance
GoogleGenAIRealtimeClient
Implements
IRealtimeClient
Inherited Members

Constructors

GoogleGenAIRealtimeClient(Client, string?)

Initializes a new instance wrapping an existing Client.

public GoogleGenAIRealtimeClient(Client client, string? defaultModelId = null)

Parameters

client Client

The Google GenAI client.

defaultModelId string

The default model to use for realtime sessions (e.g. "gemini-2.5-flash-native-audio-preview-12-2025").

Exceptions

ArgumentNullException

client is null.

GoogleGenAIRealtimeClient(string, string?)

Initializes a new instance using an API key.

public GoogleGenAIRealtimeClient(string apiKey, string? defaultModelId = null)

Parameters

apiKey string

The Google GenAI API key.

defaultModelId string

The default model to use for realtime sessions.

Exceptions

ArgumentNullException

apiKey is null or empty.

GoogleGenAIRealtimeClient(string, string, string?)

Initializes a new instance using a Google Cloud project and location.

public GoogleGenAIRealtimeClient(string project, string location, string? defaultModelId = null)

Parameters

project string

The Google Cloud project ID.

location string

The Google Cloud location (e.g. "us-central1").

defaultModelId string

The default model to use for realtime sessions.

Exceptions

ArgumentNullException

project or location is null or empty.

Methods

CreateSessionAsync(RealtimeSessionOptions?, CancellationToken)

Creates a new real-time session with the specified options.

public Task<IRealtimeClientSession> CreateSessionAsync(RealtimeSessionOptions? options = null, CancellationToken cancellationToken = default)

Parameters

options RealtimeSessionOptions

The session options.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<IRealtimeClientSession>

The created real-time session.

Dispose()

public void Dispose()

GetService(Type, object?)

Asks the Microsoft.Extensions.AI.IRealtimeClient for an object of the specified type serviceType.

public object? GetService(Type serviceType, object? serviceKey = null)

Parameters

serviceType Type

The type of object being requested.

serviceKey object

An optional key that can be used to help identify the target service.

Returns

object

The found object, otherwise null.

Remarks

The purpose of this method is to allow for the retrieval of strongly typed services that might be provided by the Microsoft.Extensions.AI.IRealtimeClient, including itself or any services it might be wrapping.

Exceptions

ArgumentNullException

serviceType is null.