Table of Contents

Class ModelClient

Namespace
GenerativeAI.Clients
Assembly
GenerativeAI.dll

A client for interacting with the Gemini API Models endpoint.

public class ModelClient : BaseClient
Inheritance
ModelClient
Inherited Members
Extension Methods

Constructors

ModelClient(IPlatformAdapter, HttpClient?, ILogger?)

A client for interacting with the Gemini API Models endpoint, providing methods to retrieve and list available models for use with the Generative AI platform.

public ModelClient(IPlatformAdapter platform, HttpClient? httpClient = null, ILogger? logger = null)

Parameters

platform IPlatformAdapter

The platform adapter used to manage API endpoints and authentication.

httpClient HttpClient

The HTTP client instance used for making API requests.

logger ILogger

An optional logger instance for logging operations.

Remarks

The ModelClient serves as an abstraction to interact with the API's model-related endpoints. It is responsible for retrieving model metadata and listing available models on the platform.

See Also

Methods

ComputeTokensAsync(string, IEnumerable<Content>, CancellationToken)

Returns the tokens and token ids of the given contents (Vertex AI only), like models.compute_tokens of the google-genai SDK. Use CountTokensAsync of GenerativeModel to count tokens on both platforms.

public Task<ComputeTokensResponse> ComputeTokensAsync(string model, IEnumerable<Content> contents, CancellationToken cancellationToken = default)

Parameters

model string

The model, e.g. gemini-2.5-flash, publishers/google/models/... or a full resource name.

contents IEnumerable<Content>

The contents to tokenize.

cancellationToken CancellationToken

The cancellation token to observe while waiting for the task to complete.

Returns

Task<ComputeTokensResponse>

The ComputeTokensResponse with the tokens info for each content.

Exceptions

NotSupportedException

Called on the Gemini Developer API.

DeleteModelAsync(string, CancellationToken)

Deletes a tuned model, like models.delete of the google-genai SDK.

public Task DeleteModelAsync(string model, CancellationToken cancellationToken = default)

Parameters

model string

The model to delete: tunedModels/{id} on the Gemini API; models/{id} or projects/{project}/locations/{location}/models/{id} on Vertex AI.

cancellationToken CancellationToken

The cancellation token to observe while waiting for the task to complete.

Returns

Task

A task that completes when the model was deleted (or the deletion was accepted).

See Also

GetModelAsync(string, CancellationToken)

Gets information about a specific Model such as its version number, token limits, parameters and other metadata.

public Task<Model> GetModelAsync(string name, CancellationToken cancellationToken = default)

Parameters

name string

The resource name of the model.

cancellationToken CancellationToken

The cancellation token to observe while waiting for the task to complete.

Returns

Task<Model>

The Model information.

See Also

ListModelsAsync(int?, string?, CancellationToken)

Lists the Models available through the Gemini API.

public Task<ListModelsResponse> ListModelsAsync(int? pageSize = null, string? pageToken = null, CancellationToken cancellationToken = default)

Parameters

pageSize int?

The maximum number of Models to return per page.

pageToken string

A page token, received from a previous ListModelsAsync(int?, string?, CancellationToken) call, to retrieve the next page of results.

cancellationToken CancellationToken

The cancellation token to observe while waiting for the task to complete.

Returns

Task<ListModelsResponse>

A ListModelsResponse containing a list of Models and associated metadata.

See Also

UpdateModelAsync(string, UpdateModelConfig, CancellationToken)

Updates a tuned model's display name, description and/or default checkpoint (PATCH), like models.update of the google-genai SDK.

public Task<Model> UpdateModelAsync(string model, UpdateModelConfig config, CancellationToken cancellationToken = default)

Parameters

model string

The model to update: tunedModels/{id} on the Gemini API; models/{id} or projects/{project}/locations/{location}/models/{id} on Vertex AI.

config UpdateModelConfig

The fields to update. Only the fields that are set are sent.

cancellationToken CancellationToken

The cancellation token to observe while waiting for the task to complete.

Returns

Task<Model>

The updated Model.

See Also

See Also