Table of Contents

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

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 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

name string

The resource name of the batch job to cancel.

cancellationToken CancellationToken

A 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

model string

The name of the model to use for batch generation.

source BatchJobSource

The source configuration specifying input data location (GCS, BigQuery, or inlined requests).

destination BatchJobDestination

Optional destination configuration for output data.

webhookConfig WebhookConfig

Optional webhook configuration for receiving notifications when the batch operation completes (sent as batch.webhookConfig). Only supported by the Gemini Developer API.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<BatchJob>

A task that represents the asynchronous operation, containing the created BatchJob.

Exceptions

NotSupportedException

Thrown when webhookConfig is 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

model string

The name of the model to use for batch generation.

source BatchJobSource

The source configuration specifying input data location (GCS, BigQuery, or inlined requests).

destination BatchJobDestination

Optional destination configuration for output data.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<BatchJob>

A task that represents the asynchronous operation, containing the created BatchJob.

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

model string

The name of the embedding model to use.

source BatchJobSource

The source configuration specifying input data for embeddings.

destination BatchJobDestination

Optional destination configuration for embedding output.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<BatchJob>

A task that represents the asynchronous operation, containing the created BatchJob.

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

name string

The resource name of the batch job to delete.

cancellationToken CancellationToken

A 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

name string

The resource name of the batch job to retrieve.

cancellationToken CancellationToken

A 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

pageSize int?

The maximum number of batch jobs to return per page. If not specified, uses the server default.

pageToken string

A page token from a previous call to retrieve the next page of results.

cancellationToken CancellationToken

A 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

See Also