Class Models
Provides methods to interact with the Gen AI models. This class is not intended to be instantiated directly, instead it should be accessed through the Client class.
public sealed class Models
- Inheritance
-
Models
- Inherited Members
- Extension Methods
Constructors
Models(ApiClient)
public Models(ApiClient apiClient)
Parameters
apiClientApiClient
Methods
ComputeTokensAsync(string, Content, ComputeTokensConfig?, CancellationToken)
Computes the number of tokens for a single content item.
public Task<ComputeTokensResponse> ComputeTokensAsync(string model, Content contents, ComputeTokensConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the GenAI model to use for token computation.
contentsContentA Content instance to compute tokens for.
configComputeTokensConfigA ComputeTokensConfig instance that specifies the optional configurations.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<ComputeTokensResponse>
A Task<TResult> that represents the asynchronous operation. The task result contains a ComputeTokensResponse instance with token information.
Exceptions
- NotSupportedException
Thrown when called with a client that is not in Gemini Enterprise Agent Platform mode.
ComputeTokensAsync(string, List<Content>, ComputeTokensConfig?, CancellationToken)
Computes the number of tokens for the given content.
public Task<ComputeTokensResponse> ComputeTokensAsync(string model, List<Content> contents, ComputeTokensConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the GenAI model to use for token computation.
contentsList<Content>A List<T> to compute tokens for.
configComputeTokensConfigA ComputeTokensConfig instance that specifies the optional configurations.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<ComputeTokensResponse>
A Task<TResult> that represents the asynchronous operation. The task result contains a ComputeTokensResponse instance with token information.
Exceptions
- NotSupportedException
Thrown when called with a non-Gemini Enterprise Agent Platform (previously known as Vertex AI) client.
ComputeTokensAsync(string, string, ComputeTokensConfig?, CancellationToken)
Computes the number of tokens for a text string.
public Task<ComputeTokensResponse> ComputeTokensAsync(string model, string contents, ComputeTokensConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the GenAI model to use for token computation.
contentsstringA string of text to compute tokens for.
configComputeTokensConfigA ComputeTokensConfig instance that specifies the optional configurations.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<ComputeTokensResponse>
A Task<TResult> that represents the asynchronous operation. The task result contains a ComputeTokensResponse instance with token information.
Exceptions
- NotSupportedException
Thrown when called with a with a client that is not in Gemini Enterprise Agent Platform mode.
CountTokensAsync(string, Content, CountTokensConfig?, CancellationToken)
Counts the number of tokens in the provided content.
public Task<CountTokensResponse> CountTokensAsync(string model, Content contents, CountTokensConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the GenAI model to use for token counting.
contentsContentA Content to count tokens for.
configCountTokensConfigA CountTokensConfig instance that specifies the optional configurations.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<CountTokensResponse>
A Task<TResult> that represents the asynchronous operation. The task result contains a CountTokensResponse instance with the total token count and other metadata.
CountTokensAsync(string, List<Content>, CountTokensConfig?, CancellationToken)
Counts the number of tokens in the provided content.
public Task<CountTokensResponse> CountTokensAsync(string model, List<Content> contents, CountTokensConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the GenAI model to use for token counting.
contentsList<Content>A List<T> to count tokens for.
configCountTokensConfigA CountTokensConfig instance that specifies the optional configurations.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<CountTokensResponse>
A Task<TResult> that represents the asynchronous operation. The task result contains a CountTokensResponse instance with the total token count and other metadata.
CountTokensAsync(string, string, CountTokensConfig?, CancellationToken)
Counts the number of tokens in the provided content.
public Task<CountTokensResponse> CountTokensAsync(string model, string contents, CountTokensConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the GenAI model to use for token counting.
contentsstringA text string to send to count tokens for.
configCountTokensConfigA CountTokensConfig instance that specifies the optional configurations.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<CountTokensResponse>
A Task<TResult> that represents the asynchronous operation. The task result contains a CountTokensResponse instance with the total token count and other metadata.
DeleteAsync(string, DeleteModelConfig?, CancellationToken)
Deletes a specific model resource by its name.
public Task<DeleteModelResponse> DeleteAsync(string model, DeleteModelConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringconfigDeleteModelConfigcancellationTokenCancellationToken
Returns
EditImageAsync(string, string, List<IReferenceImage>, EditImageConfig?, CancellationToken)
public Task<EditImageResponse> EditImageAsync(string model, string prompt, List<IReferenceImage> referenceImages, EditImageConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringpromptstringreferenceImagesList<IReferenceImage>configEditImageConfigcancellationTokenCancellationToken
Returns
EmbedContentAsync(string, Content, EmbedContentConfig?, CancellationToken)
Calculates embeddings for the given content.
public Task<EmbedContentResponse> EmbedContentAsync(string model, Content contents, EmbedContentConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe model to use.
contentsContentThe content to embed.
configEmbedContentConfigOptional configuration for embeddings.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<EmbedContentResponse>
A Task<TResult> that represents the asynchronous operation.
EmbedContentAsync(string, List<Content>, EmbedContentConfig?, CancellationToken)
Calculates embeddings for the given content.
public Task<EmbedContentResponse> EmbedContentAsync(string model, List<Content> contents, EmbedContentConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe model to use.
contentsList<Content>The content to embed.
configEmbedContentConfigOptional configuration for embeddings.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<EmbedContentResponse>
A Task<TResult> that represents the asynchronous operation.
EmbedContentAsync(string, string, EmbedContentConfig?, CancellationToken)
Calculates embeddings for the given text string.
public Task<EmbedContentResponse> EmbedContentAsync(string model, string contents, EmbedContentConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe model to use.
contentsstringThe text string to embed.
configEmbedContentConfigOptional configuration for embeddings.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<EmbedContentResponse>
A Task<TResult> that represents the asynchronous operation.
GenerateContentAsync(string, Content, GenerateContentConfig?, CancellationToken)
Generates content given a GenAI model and a single content item.
public Task<GenerateContentResponse> GenerateContentAsync(string model, Content contents, GenerateContentConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the GenAI model to use for generation.
contentsContentA Content instance to send to the generative model.
configGenerateContentConfigA GenerateContentConfig instance that specifies the optional configurations.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<GenerateContentResponse>
A Task<TResult> that represents the asynchronous operation. The task result contains a GenerateContentResponse instance with response contents and other metadata.
GenerateContentAsync(string, List<Content>, GenerateContentConfig?, CancellationToken)
Generates content given a GenAI model and a list of content.
public Task<GenerateContentResponse> GenerateContentAsync(string model, List<Content> contents, GenerateContentConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the GenAI model to use for generation.
contentsList<Content>A List<T> to send to the generative model.
configGenerateContentConfigA GenerateContentConfig instance that specifies the optional configurations.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<GenerateContentResponse>
A Task<TResult> that represents the asynchronous operation. The task result contains a GenerateContentResponse instance with response contents and other metadata.
GenerateContentAsync(string, string, GenerateContentConfig?, CancellationToken)
Generates content given a GenAI model and a text string.
public Task<GenerateContentResponse> GenerateContentAsync(string model, string contents, GenerateContentConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the GenAI model to use for generation.
contentsstringA text string to send to the generative model.
configGenerateContentConfigA GenerateContentConfig instance that specifies the optional configurations.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<GenerateContentResponse>
A Task<TResult> that represents the asynchronous operation. The task result contains a GenerateContentResponse instance with response contents and other metadata.
GenerateContentStreamAsync(string, Content, GenerateContentConfig?, CancellationToken)
Generates content with streaming responses given a GenAI model and a single content item.
public IAsyncEnumerable<GenerateContentResponse> GenerateContentStreamAsync(string model, Content contents, GenerateContentConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the GenAI model to use for generation.
contentsContentA Content instance to send to the generative model.
configGenerateContentConfigA GenerateContentConfig instance that specifies the optional configurations.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- IAsyncEnumerable<GenerateContentResponse>
An async enumerable of GenerateContentResponse chunks.
GenerateContentStreamAsync(string, List<Content>, GenerateContentConfig?, CancellationToken)
Generates content with streaming responses given a GenAI model and a list of content.
public IAsyncEnumerable<GenerateContentResponse> GenerateContentStreamAsync(string model, List<Content> contents, GenerateContentConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the GenAI model to use for generation.
contentsList<Content>A List<T> to send to the generative model.
configGenerateContentConfigA GenerateContentConfig instance that specifies the optional configurations.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- IAsyncEnumerable<GenerateContentResponse>
An async enumerable of GenerateContentResponse chunks.
GenerateContentStreamAsync(string, string, GenerateContentConfig?, CancellationToken)
Generates content with streaming responses given a GenAI model and a text string.
public IAsyncEnumerable<GenerateContentResponse> GenerateContentStreamAsync(string model, string contents, GenerateContentConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the GenAI model to use for generation.
contentsstringA text string to send to the generative model.
configGenerateContentConfigA GenerateContentConfig instance that specifies the optional configurations.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- IAsyncEnumerable<GenerateContentResponse>
An async enumerable of GenerateContentResponse chunks.
GenerateImagesAsync(string, string, GenerateImagesConfig?, CancellationToken)
Generates images given a GenAI model and a prompt.
public Task<GenerateImagesResponse> GenerateImagesAsync(string model, string prompt, GenerateImagesConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the GenAI model to use for generation.
promptstringA text prompt string to send to the generative model.
configGenerateImagesConfigA GenerateImagesConfig instance that specifies the optional configurations.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<GenerateImagesResponse>
A Task<TResult> that represents the asynchronous operation. The task result contains a GenerateImagesResponse instance with response contents and other metadata.
GenerateVideosAsync(string, GenerateVideosSource, GenerateVideosConfig?, CancellationToken)
public Task<GenerateVideosOperation> GenerateVideosAsync(string model, GenerateVideosSource source, GenerateVideosConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringsourceGenerateVideosSourceconfigGenerateVideosConfigcancellationTokenCancellationToken
Returns
GetAsync(string, GetModelConfig?, CancellationToken)
Retrieves a specific model resource by its name.
public Task<Model> GetAsync(string model, GetModelConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringconfigGetModelConfigcancellationTokenCancellationToken
Returns
ListAsync(ListModelsConfig?, CancellationToken)
Lists models asynchronously.
public Task<Pager<Model, ListModelsConfig, ListModelsResponse>> ListAsync(ListModelsConfig? config = null, CancellationToken cancellationToken = default)
Parameters
configListModelsConfigA ListModelsConfig instance that specifies the optional configuration for the list request.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<Pager<Model, ListModelsConfig, ListModelsResponse>>
A Pager object that contains one page of models. When iterating over the pager, it automatically fetches the next page if there are more.
RecontextImageAsync(string, RecontextImageSource, RecontextImageConfig?, CancellationToken)
public Task<RecontextImageResponse> RecontextImageAsync(string model, RecontextImageSource source, RecontextImageConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringsourceRecontextImageSourceconfigRecontextImageConfigcancellationTokenCancellationToken
Returns
SegmentImageAsync(string, SegmentImageSource, SegmentImageConfig?, CancellationToken)
public Task<SegmentImageResponse> SegmentImageAsync(string model, SegmentImageSource source, SegmentImageConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringsourceSegmentImageSourceconfigSegmentImageConfigcancellationTokenCancellationToken
Returns
UpdateAsync(string, UpdateModelConfig?, CancellationToken)
Updates a specific model resource.
public Task<Model> UpdateAsync(string model, UpdateModelConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe model to update.
configUpdateModelConfigAn UpdateModelConfig instance that specifies parameters to update.
cancellationTokenCancellationTokenA CancellationToken to cancel the operation.
Returns
- Task<Model>
A Task<TResult> that represents the asynchronous operation. The task result contains the updated Model instance.
UpscaleImageAsync(string, Image, string, UpscaleImageConfig?, CancellationToken)
public Task<UpscaleImageResponse> UpscaleImageAsync(string model, Image image, string upscaleFactor, UpscaleImageConfig? config = null, CancellationToken cancellationToken = default)
Parameters
modelstringimageImageupscaleFactorstringconfigUpscaleImageConfigcancellationTokenCancellationToken