Table of Contents

Class GenerativeAIChatClient

Namespace
GenerativeAI.Microsoft
Assembly
GenerativeAI.Microsoft.dll

Supports all classes in the .NET class hierarchy and provides low-level services to derived classes. This is the ultimate base class of all .NET classes; it is the root of the type hierarchy.

public sealed class GenerativeAIChatClient : IChatClient, IDisposable
Inheritance
GenerativeAIChatClient
Implements
IChatClient
Inherited Members
Extension Methods

Constructors

GenerativeAIChatClient(IPlatformAdapter, string, bool)

public GenerativeAIChatClient(IPlatformAdapter adapter, string modelName = "models/gemini-3.8-flash", bool autoCallFunction = true)

Parameters

adapter IPlatformAdapter
modelName string
autoCallFunction bool

GenerativeAIChatClient(string, string, bool)

public GenerativeAIChatClient(string apiKey, string modelName = "models/gemini-3.8-flash", bool autoCallFunction = true)

Parameters

apiKey string
modelName string
autoCallFunction bool

Properties

AutoCallFunction

Gets or sets a value indicating whether the function calls in the generative AI chat client are automatically invoked without requiring explicit user input. Default: false

public bool AutoCallFunction { get; set; }

Property Value

bool

Remarks

When set to false, the function calls are handled manually, providing flexibility for scenarios where explicit user control over function invocation is required or when using M.E.A.I.'s FunctionInvokingChatClient.

model

Gets the underlying GenerativeModel instance.

public GenerativeModel model { get; }

Property Value

GenerativeModel

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetResponseAsync(IEnumerable<ChatMessage>, ChatOptions?, CancellationToken)

Sends chat messages and returns the response.

public Task<ChatResponse> GetResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)

Parameters

messages IEnumerable<ChatMessage>

The sequence of chat messages to send.

options ChatOptions

The chat options with which to configure the request.

cancellationToken CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

Task<ChatResponse>

The response messages generated by the client.

Exceptions

ArgumentNullException

messages is null.

GetService(Type, object?)

Asks the Microsoft.Extensions.AI.IChatClient 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.IChatClient, including itself or any services it might be wrapping. For example, to access the Microsoft.Extensions.AI.ChatClientMetadata for the instance, GetService(Type, object) may be used to request it.

Exceptions

ArgumentNullException

serviceType is null.

GetStreamingResponseAsync(IEnumerable<ChatMessage>, ChatOptions?, CancellationToken)

Sends chat messages and streams the response.

public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)

Parameters

messages IEnumerable<ChatMessage>

The sequence of chat messages to send.

options ChatOptions

The chat options with which to configure the request.

cancellationToken CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

IAsyncEnumerable<ChatResponseUpdate>

The response messages generated by the client.

Exceptions

ArgumentNullException

messages is null.