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
platformIPlatformAdapterThe platform adapter used to manage API endpoints and authentication.
httpClientHttpClientThe HTTP client instance used for making API requests.
loggerILoggerAn 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
modelstringThe model, e.g.
gemini-2.5-flash,publishers/google/models/...or a full resource name.contentsIEnumerable<Content>The contents to tokenize.
cancellationTokenCancellationTokenThe 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
modelstringThe model to delete:
tunedModels/{id}on the Gemini API;models/{id}orprojects/{project}/locations/{location}/models/{id}on Vertex AI.cancellationTokenCancellationTokenThe 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
namestringThe resource name of the model.
cancellationTokenCancellationTokenThe cancellation token to observe while waiting for the task to complete.
Returns
- 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
pageSizeint?The maximum number of Models to return per page.
pageTokenstringA page token, received from a previous ListModelsAsync(int?, string?, CancellationToken) call, to retrieve the next page of results.
cancellationTokenCancellationTokenThe 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
modelstringThe model to update:
tunedModels/{id}on the Gemini API;models/{id}orprojects/{project}/locations/{location}/models/{id}on Vertex AI.configUpdateModelConfigThe fields to update. Only the fields that are set are sent.
cancellationTokenCancellationTokenThe cancellation token to observe while waiting for the task to complete.
Returns
- See Also