Class ApiClient
Abstract base class for an API client which issues HTTP requests to the GenAI APIs.
public abstract class ApiClient : IDisposable, IAsyncDisposable
- Inheritance
-
ApiClient
- Implements
- Derived
- Inherited Members
Constructors
ApiClient(bool?, bool?, string?, string?, string?, ICredential?, HttpOptions?, ClientOptions?)
Constructs an ApiClient.
protected ApiClient(bool? enterprise = null, bool? vertexAI = null, string? apiKey = null, string? project = null, string? location = null, ICredential? credentials = null, HttpOptions? customHttpOptions = null, ClientOptions? clientOptions = null)
Parameters
enterprisebool?vertexAIbool?apiKeystringprojectstringlocationstringcredentialsICredentialcustomHttpOptionsHttpOptionsclientOptionsClientOptions
Properties
ApiKey
public string? ApiKey { get; }
Property Value
ClientOptions
public ClientOptions ClientOptions { get; protected set; }
Property Value
Credentials
public ICredential? Credentials { get; }
Property Value
CustomBaseUrl
public string? CustomBaseUrl { get; }
Property Value
HttpClient
protected HttpClient HttpClient { get; }
Property Value
HttpOptions
public HttpOptions HttpOptions { get; protected set; }
Property Value
Location
public string? Location { get; }
Property Value
Project
public string? Project { get; }
Property Value
VertexAI
public bool VertexAI { get; }
Property Value
Methods
Dispose()
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposingbool
DisposeAsync()
Asynchronously disposes the client and its underlying resources.
public virtual ValueTask DisposeAsync()
Returns
MergeHttpOptions(HttpOptions?)
Merges the given HttpOptions with the client's current HttpOptions.
protected HttpOptions MergeHttpOptions(HttpOptions? optionsToApply)
Parameters
optionsToApplyHttpOptionsThe HttpOptions to apply.
Returns
- HttpOptions
A new HttpOptions instance with merged values.
RequestAsync(HttpMethod, string, string, HttpOptions?, CancellationToken)
Sends an HTTP request given the HTTP method, path, and request JSON string.
public abstract Task<ApiResponse> RequestAsync(HttpMethod httpMethod, string path, string requestJson, HttpOptions? requestHttpOptions, CancellationToken cancellationToken = default)
Parameters
httpMethodHttpMethodpathstringrequestJsonstringrequestHttpOptionsHttpOptionscancellationTokenCancellationToken
Returns
RequestStreamAsync(HttpMethod, string, string, HttpOptions?, CancellationToken)
Sends an HTTP request for streaming responses that return Server-Sent Events.
public abstract IAsyncEnumerable<ApiResponse> RequestStreamAsync(HttpMethod httpMethod, string path, string requestJson, HttpOptions? requestHttpOptions, CancellationToken cancellationToken = default)
Parameters
httpMethodHttpMethodThe HTTP method to use.
pathstringThe API path.
requestJsonstringThe request body as JSON string.
requestHttpOptionsHttpOptionsOptional HTTP options.
cancellationTokenCancellationTokenThe cancellation token to use.
Returns
- IAsyncEnumerable<ApiResponse>
An async enumerable of ApiResponse chunks.