Table of Contents

Class ApiClient

Namespace
Google.GenAI
Assembly
Google.GenAI.dll

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

enterprise bool?
vertexAI bool?
apiKey string
project string
location string
credentials ICredential
customHttpOptions HttpOptions
clientOptions ClientOptions

Properties

ApiKey

public string? ApiKey { get; }

Property Value

string

ClientOptions

public ClientOptions ClientOptions { get; protected set; }

Property Value

ClientOptions

Credentials

public ICredential? Credentials { get; }

Property Value

ICredential

CustomBaseUrl

public string? CustomBaseUrl { get; }

Property Value

string

HttpClient

protected HttpClient HttpClient { get; }

Property Value

HttpClient

HttpOptions

public HttpOptions HttpOptions { get; protected set; }

Property Value

HttpOptions

Location

public string? Location { get; }

Property Value

string

Project

public string? Project { get; }

Property Value

string

VertexAI

public bool VertexAI { get; }

Property Value

bool

Methods

Dispose()

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

DisposeAsync()

Asynchronously disposes the client and its underlying resources.

public virtual ValueTask DisposeAsync()

Returns

ValueTask

A ValueTask that represents the asynchronous dispose operation.

MergeHttpOptions(HttpOptions?)

Merges the given HttpOptions with the client's current HttpOptions.

protected HttpOptions MergeHttpOptions(HttpOptions? optionsToApply)

Parameters

optionsToApply HttpOptions

The 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

httpMethod HttpMethod
path string
requestJson string
requestHttpOptions HttpOptions
cancellationToken CancellationToken

Returns

Task<ApiResponse>

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

httpMethod HttpMethod

The HTTP method to use.

path string

The API path.

requestJson string

The request body as JSON string.

requestHttpOptions HttpOptions

Optional HTTP options.

cancellationToken CancellationToken

The cancellation token to use.

Returns

IAsyncEnumerable<ApiResponse>

An async enumerable of ApiResponse chunks.