Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/xAI/GrokClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace xAI;
/// <summary>Client for interacting with the Grok service.</summary>
/// <param name="apiKey">The API key used for authentication.</param>
/// <param name="options">The options used to configure the client.</param>
public class GrokClient(string apiKey, GrokClientOptions options)
public sealed class GrokClient(string apiKey, GrokClientOptions options) : IDisposable
{
static ConcurrentDictionary<(Uri, string), GrpcChannel> channels = [];
static readonly ConcurrentDictionary<(Uri, string), GrpcChannel> channels = [];

/// <summary>Initializes a new instance of the <see cref="GrokClient"/> class with default options.</summary>
public GrokClient(string apiKey) : this(apiKey, new GrokClientOptions()) { }
Expand All @@ -36,6 +36,9 @@ public class GrokClient(string apiKey, GrokClientOptions options)
return GrpcChannel.ForAddress(Endpoint, options);
});

/// <summary>Clears the cached list of gRPC channels in the client.</summary>
public void Dispose() => channels.Clear();

class AuthenticationHeaderHandler(string apiKey) : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Expand Down