Gemini Batch Inference API Usage Guide
Overview
Gemini Batch Inference allows you to process large volumes of requests asynchronously at approximately 50% lower cost than online inference. Ideal for batch processing tasks like document analysis, image labeling, or bulk content generation.Authentication
All API requests require authentication using an API key. Include your API key in the Authorization header:Submit Batch Job
Base URL
Endpoint
Request Format
Request Parameters
Supported Models
JSONL Input Format
Each line must be a valid JSON object with arequest field containing contents:
Text-only requests:
Response (Immediate)
After submitting, you receive arequest_id to track the job:
Check Job Status
Endpoint
Example
Response (In Progress)
Response (Completed)
Download and Parse Output
The output is a JSONL file where each line corresponds to one input request:status field indicates success. Failed requests will have an error message in status.
List Your Batch Jobs
Endpoint
Example
Request Status Values
Batch Job States (Vertex AI)
Pricing
Limits
Tips for Best Results
- Batch Size: Ideal for 100+ requests. For fewer requests, consider online inference.
- File References: Use
gs://URIs for images/documents stored in Google Cloud Storage. - Processing Time: Jobs typically complete within minutes to hours depending on volume.
- Cost Optimization: Use batch for non-time-sensitive workloads to save ~50%.
- Error Handling: Check
batch_job_completion_statsfor failed request counts. - Partial Results: Even if some requests fail, successful ones are still billed and available.