ChatClientBase<T>

Base Classes · AiDotNet.Agentic.Models.Connectors

Base class for IChatClient implementations that talk to an HTTP chat API. Provides the shared HTTP client, validation, retry-with-backoff for non-streaming calls, and API-key checks, leaving the provider-specific request/response mapping to subclasses.

Implements: IChatClient<T>

Known derived types: AnthropicChatClient<T>, CohereChatClient<T>, GeminiChatClient<T>, OpenAIChatClient<T>

For Beginners

Every cloud chat provider needs the same plumbing — send an HTTP request, retry if the network hiccups, give up cleanly on a bad API key. This class does all of that once, so each provider class only has to describe how its specific API formats requests and responses.

How It Works

Template-method pattern: this base owns the cross-cutting concerns (transport, retries, timeouts, error wrapping); a concrete connector implements GetResponseCoreAsync and GetStreamingResponseCoreAsync with the provider’s wire format. Streaming calls are not retried (a partially-consumed stream cannot be safely replayed).

Properties

Property Summary
string ModelId { get; set; }

Methods

Method Summary
IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IReadOnlyList<ChatMessage> messages, ChatOptions options, CancellationToken cancellationToken)
Task<ChatResponse> GetResponseAsync(IReadOnlyList<ChatMessage> messages, ChatOptions options, CancellationToken cancellationToken)