Implementation:Googleapis Python genai Batches
| Knowledge Sources | |
|---|---|
| Domains | Batch_Processing, Generative_AI |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
Concrete tool for batch prediction processing provided by the Google Gen AI SDK.
Description
The Batches and AsyncBatches classes provide API modules for creating, managing, and monitoring batch prediction jobs. They support text generation, embedding, and multi-modal batch processing with sources from GCS, BigQuery, or inlined requests. Both Gemini Developer API and Vertex AI backends are supported.
Usage
Import these classes when you need to process large volumes of content generation or embedding requests as batch jobs rather than individual API calls, enabling cost-efficient offline processing.
Code Reference
Source Location
- Repository: Googleapis_Python_genai
- File: google/genai/batches.py
- Lines: 1504-2600 (Batches at L1504-2046, AsyncBatches at L2049-2600)
Signature
class Batches(_api_module.BaseModule):
def create(
self,
*,
model: str,
src: types.BatchJobSourceUnionDict,
config: Optional[types.CreateBatchJobConfigOrDict] = None,
) -> types.BatchJob: ...
def get(self, *, name: str, config: Optional[types.GetBatchJobConfigOrDict] = None) -> types.BatchJob: ...
def cancel(self, *, name: str, config: Optional[types.CancelBatchJobConfigOrDict] = None) -> None: ...
def delete(self, *, name: str, config: Optional[types.DeleteBatchJobConfigOrDict] = None) -> types.DeleteResourceJob: ...
def list(self, *, config: Optional[types.ListBatchJobsConfigOrDict] = None) -> Pager[types.BatchJob]: ...
def create_embeddings(
self,
*,
model: str,
src: types.EmbeddingsBatchJobSourceOrDict,
config: Optional[types.CreateEmbeddingsBatchJobConfigOrDict] = None,
) -> types.BatchJob: ...
Import
from google import genai
client = genai.Client(api_key="...")
# Access via: client.batches
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| model | str | Yes | Model ID for batch processing (e.g. "gemini-2.0-flash") |
| src | BatchJobSourceUnionDict | Yes | Data source (GCS URI, BigQuery table, inlined requests, or file name) |
| config | CreateBatchJobConfigOrDict | No | Batch job configuration including destination |
| name | str | For get/cancel/delete | Batch job resource name |
Outputs
| Name | Type | Description |
|---|---|---|
| create() returns | BatchJob | Created batch job with name, state, metadata |
| get() returns | BatchJob | Batch job details and current state |
| list() returns | Pager[BatchJob] | Paginated list of batch jobs |
| delete() returns | DeleteResourceJob | Deletion operation result |
Usage Examples
Create Batch Job from GCS
from google import genai
from google.genai import types
client = genai.Client(vertexai=True, project="my-project", location="us-central1")
# Create batch job from GCS source
batch_job = client.batches.create(
model="gemini-2.0-flash",
src="gs://my-bucket/input.jsonl",
config=types.CreateBatchJobConfig(
dest="gs://my-bucket/output/"
),
)
print(f"Batch job: {batch_job.name}, State: {batch_job.state}")
List and Monitor Batch Jobs
# List all batch jobs
for job in client.batches.list():
print(f"{job.name}: {job.state}")
# Get specific batch job status
job = client.batches.get(name="batches/my-batch-job-id")
print(f"State: {job.state}")