Class BatchClient
- Namespace
- GenerativeAI.Clients
- Assembly
- GenerativeAI.dll
A client for interacting with the Gemini API Batch endpoint. Provides methods for creating, managing, and monitoring batch processing jobs.
public class BatchClient : BaseClient
- Inheritance
-
BatchClient
- Inherited Members
- Extension Methods
Constructors
BatchClient(IPlatformAdapter, HttpClient?, ILogger?)
Initializes a new instance of the BatchClient class.
public BatchClient(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 BatchClient provides functionality for batch processing operations, including creating batch jobs for content generation and embeddings, monitoring job status, and managing batch job lifecycle.
Methods
CancelAsync(string, CancellationToken)
Cancels a running batch job asynchronously.
public Task CancelAsync(string name, CancellationToken cancellationToken = default)
Parameters
namestringThe resource name of the batch job to cancel.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous cancel operation.
Remarks
Once cancelled, a batch job cannot be resumed. Partial results may be available depending on how much processing was completed before cancellation.
- See Also
CreateAsync(string, BatchJobSource, BatchJobDestination?, WebhookConfig?, CancellationToken)
Creates a batch job for content generation asynchronously, optionally with a per-job webhook configuration.
public Task<BatchJob> CreateAsync(string model, BatchJobSource source, BatchJobDestination? destination, WebhookConfig? webhookConfig, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the model to use for batch generation.
sourceBatchJobSourceThe source configuration specifying input data location (GCS, BigQuery, or inlined requests).
destinationBatchJobDestinationOptional destination configuration for output data.
webhookConfigWebhookConfigOptional webhook configuration for receiving notifications when the batch operation completes (sent as
batch.webhookConfig). Only supported by the Gemini Developer API.cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
Exceptions
- NotSupportedException
Thrown when
webhookConfigis set on Vertex AI.
- See Also
CreateAsync(string, BatchJobSource, BatchJobDestination?, CancellationToken)
Creates a batch job for content generation asynchronously.
public Task<BatchJob> CreateAsync(string model, BatchJobSource source, BatchJobDestination? destination = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the model to use for batch generation.
sourceBatchJobSourceThe source configuration specifying input data location (GCS, BigQuery, or inlined requests).
destinationBatchJobDestinationOptional destination configuration for output data.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
Remarks
Batch jobs are asynchronous operations that process multiple requests efficiently. The job status can be monitored using GetAsync(string, CancellationToken) with the returned job name.
- See Also
CreateEmbeddingsAsync(string, BatchJobSource, BatchJobDestination?, CancellationToken)
Creates a batch job for embedding generation asynchronously.
public Task<BatchJob> CreateEmbeddingsAsync(string model, BatchJobSource source, BatchJobDestination? destination = null, CancellationToken cancellationToken = default)
Parameters
modelstringThe name of the embedding model to use.
sourceBatchJobSourceThe source configuration specifying input data for embeddings.
destinationBatchJobDestinationOptional destination configuration for embedding output.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
Remarks
This method creates a batch job specifically for generating embeddings from text inputs. It's optimized for processing large volumes of embedding requests efficiently.
- See Also
DeleteBatchJobAsync(string, CancellationToken)
Deletes a batch job asynchronously.
public Task DeleteBatchJobAsync(string name, CancellationToken cancellationToken = default)
Parameters
namestringThe resource name of the batch job to delete.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- Task
A task that represents the asynchronous delete operation.
Remarks
Deleting a batch job removes its metadata but does not affect output files that have already been written to the destination.
- See Also
GetAsync(string, CancellationToken)
Retrieves a batch job by its name asynchronously.
public Task<BatchJobResponse> GetAsync(string name, CancellationToken cancellationToken = default)
Parameters
namestringThe resource name of the batch job to retrieve.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- Task<BatchJobResponse>
A task that represents the asynchronous operation, containing the BatchJob details.
Remarks
Use this method to check the status and progress of a batch job. The name should be in the format returned when the job was created.
- See Also
ListAsync(int?, string?, CancellationToken)
Lists batch jobs with pagination support.
public Task<ListBatchJobsResponse> ListAsync(int? pageSize = null, string? pageToken = null, CancellationToken cancellationToken = default)
Parameters
pageSizeint?The maximum number of batch jobs to return per page. If not specified, uses the server default.
pageTokenstringA page token from a previous call to retrieve the next page of results.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- Task<ListBatchJobsResponse>
A task that represents the asynchronous operation, containing a ListBatchJobsResponse with batch jobs and pagination details.
Remarks
Use the NextPageToken from the response to retrieve subsequent pages.
- See Also