The Gemini Batch API runs thousands of prompts in the background at half the normal price. You give up instant answers and get a 24-hour target turnaround in return.
This guide shows the full flow in Python with the google-genai SDK: inline jobs, JSONL file jobs, polling, cancelling, reading results, real limits and a worked cost example.
- Discount: batch usage costs 50% of the standard price. Gemini 4 Hydrogen drops from $1.50 / $7.50 to $0.75 / $3.75 per 1M input / output tokens.
- Two ways to submit: inline requests (total under 20 MB) or a JSONL file uploaded with the File API (up to 2 GB).
- Turnaround: 24-hour target, often faster. Jobs still pending or running after 48 hours expire with no results.
- Methods:
client.batches.create(),get(),list(),cancel(),delete(), pluscreate_embeddings(). - Interactions API gap: batch works only with the legacy
generateContentrequest format for now. - Paid tier only: the Batch price column shows “Not available” on the free tier.
What the Gemini Batch API Is and When to Use It
A normal Gemini call waits for the answer. A batch job is different: you send many requests at once, Google queues them, and you collect all the answers later.
Google describes it as a way to process large volumes of requests asynchronously at 50% of the standard cost. The target turnaround is 24 hours, but most jobs finish much sooner.

Batch is a good fit when nobody is waiting on the screen. Typical jobs include:
- Data processing: classify, tag or summarize thousands of rows, tickets or reviews.
- Evaluations: run a test set of prompts against a model overnight.
- Content at scale: product descriptions, translations or metadata for a whole catalog.
- Embeddings: embed a large document set for search or RAG.
- Image generation: bulk Nano Banana images with higher rate limits.
Skip batch for chatbots, live agents or anything a user waits on. For those, use normal calls as shown in my Gemini API Python tutorial.
Batch Pricing and Supported Models
Every batch token costs half the standard paid-tier price for the same model. That covers input and output, and output includes thinking tokens. The table below uses Google’s official pricing page, checked on 4 December 2026.
| Model (ID) | Standard input / output per 1M | Batch input / output per 1M |
|---|---|---|
Gemini 4 Carbon (gemini-4-carbon) |
$4.00 / $20.00 | $2.00 / $10.00 |
Gemini 4 Neon (gemini-4-neon) |
$3.00 / $15.00 | $1.50 / $7.50 |
Gemini 4 Hydrogen (gemini-4-hydrogen) |
$1.50 / $7.50 | $0.75 / $3.75 |
Gemini 3.8 Flash (gemini-3.8-flash) |
$0.75 / $3.75* | $0.375 / $1.875* |
Gemini 3.5 Flash-Lite (gemini-3.5-flash-lite) |
$0.30 / $2.50 | $0.15 / $1.25 |
| Gemini 3.1 Pro Preview (prompts up to 200k) | $2.00 / $12.00 | $1.00 / $6.00 |
| Gemini Embedding 2 (text input) | $0.20 | $0.10 |
*Gemini 3.8 Flash standard prices are listed “through December 31, 2026”. From 1 January 2027 they double to $1.50 / $7.50, so the batch price becomes $0.75 / $3.75.

Which models support batch
Each model page has a “Consumption options” row that says whether Batch API is supported. On the pricing page, supported models show a Batch tab.
- Supported: Gemini 4 Carbon, Neon and Hydrogen, Gemini 3.8 Flash, 3.6 Flash, 3.5 Flash-Lite, 3.1 Flash-Lite, 3.1 Pro Preview, Nano Banana 2.1, Gemini 3.1 Flash Lite Image, the TTS models, Gemini Embedding 2 and Gemini Embedding.
- Not supported: Genie 4 and Gemini Decision 1 (Google says so directly). The Live, Live Translate, Transcribe and Omni video models show no Batch tab.
- Deprecated: Gemini 4 Argon requests route to Gemini 4 Carbon from 15 December 2026, at Carbon rates.
Note: the free tier has no batch pricing. The Batch tab lists “Not available” under Free Tier, so link a billing account first.
For the full standard price list and free limits, see my Gemini API pricing guide.
Worked Cost Example: 100,000 Product Descriptions
Say a shop wants a fresh description for 100,000 products. Each request has about 600 input tokens (product data plus instructions) and returns about 300 output tokens, thinking included.
- Total input: 100,000 x 600 = 60M tokens.
- Total output: 100,000 x 300 = 30M tokens.
| Model | Standard cost | Batch cost | You save |
|---|---|---|---|
| Gemini 4 Hydrogen | 60 x $1.50 + 30 x $7.50 = $315 | 60 x $0.75 + 30 x $3.75 = $157.50 | $157.50 |
| Gemini 3.5 Flash-Lite | 60 x $0.30 + 30 x $2.50 = $93 | 60 x $0.15 + 30 x $1.25 = $46.50 | $46.50 |
| Gemini 4 Carbon | 60 x $4 + 30 x $20 = $840 | 60 x $2 + 30 x $10 = $420 | $420 |
There is one catch. On Tier 1, Gemini 4 Hydrogen allows 3,000,000 enqueued batch tokens across all your active jobs. At 600 input tokens per request, that is about 5,000 requests in the queue at a time.
Tip: split a big job like this into about 20 files of 5,000 requests. Submit the next file when one finishes. Flash-Lite models allow 10,000,000 enqueued tokens on Tier 1, so they take bigger chunks.
Prerequisites and Setup
You need Python, the SDK, a paid API key and about five minutes. I checked these steps against google-genai 3.7.0 (released 2 December 2026 on PyPI), which needs Python 3.11 or newer.
- Check Python. Run
python3 --versionand confirm it is 3.11 or higher. - Create a virtual environment. Run
python3 -m venv .venv, thensource .venv/bin/activate(on Windows:.venv\Scripts\activate). - Install the SDK. Run
pip install -U google-genai. Do not use the oldgoogle-generativeaipackage. - Get a key. Open Google AI Studio, click Get API key and create one. My Google AI Studio guide shows where to click.
- Turn on billing. Link a Cloud Billing account to the project so it moves to Tier 1. Batch pricing is paid tier only.
- Store the key. Run
export GEMINI_API_KEY="your-key". The client reads it automatically, so the key never appears in code.
Warning: batch creation is not idempotent. If your script crashes and you run it again, you create a second job and pay twice. Save the job name to a file right after you create it.
Example 1: An Inline Batch Job
Inline jobs are the quickest start. You pass a Python list of request dictionaries straight to client.batches.create(). Keep the whole request under 20 MB.
from google import genai
client = genai.Client() # reads GEMINI_API_KEY
inline_requests = [
{
"contents": [{"parts": [{"text": "Write a 2-line tagline for a steel water bottle."}], "role": "user"}]
},
{
"contents": [{"parts": [{"text": "Write a 2-line tagline for a bamboo toothbrush."}], "role": "user"}],
"config": {
"system_instruction": {"parts": [{"text": "You write short, friendly UK English copy."}]}
},
},
]
job = client.batches.create(
model="gemini-4-hydrogen",
src=inline_requests,
config={"display_name": "taglines-inline-1"},
)
print("Created:", job.name) # e.g. batches/123456789
with open("last_job.txt", "w") as f:
f.write(job.name)
Each item is a normal GenerateContentRequest. You can give one request its own config, such as a system instruction, while the others use defaults.
Example 2: A JSONL File Batch Job
For anything larger, Google recommends a JSON Lines file. Each line holds a key you choose and a request. The key comes back with each result, so you can match answers to rows.
import json
from google import genai
from google.genai import types
client = genai.Client()
products = [
("sku-001", "Steel water bottle, 750 ml, keeps drinks cold 24 h"),
("sku-002", "Bamboo toothbrush, soft bristles, pack of 4"),
("sku-003", "Cotton tote bag, 10 kg load, machine washable"),
]
with open("batch-requests.jsonl", "w") as f:
for sku, facts in products:
line = {
"key": sku,
"request": {
"contents": [{"parts": [{"text": f"Write a 60-word product description. Facts: {facts}"}]}]
},
}
f.write(json.dumps(line) + "\n")
uploaded = client.files.upload(
file="batch-requests.jsonl",
config=types.UploadFileConfig(display_name="batch-requests", mime_type="jsonl"),
)
print("Uploaded:", uploaded.name)
job = client.batches.create(
model="gemini-4-hydrogen",
src=uploaded.name,
config={"display_name": "product-descriptions-1"},
)
print("Created:", job.name)
The input file can be up to 2 GB. For images, PDFs or audio, upload those files with the File API first and reference them inside the JSONL lines.
Example 3: Poll, Read Results and Handle Errors
A job moves through states. Your script checks the state every 30 seconds or so until it reaches a final one.
| State | Meaning |
|---|---|
JOB_STATE_PENDING |
Created and waiting in the queue |
JOB_STATE_RUNNING |
Being processed |
JOB_STATE_SUCCEEDED |
Done; results are ready |
JOB_STATE_FAILED |
The job failed; read job.error |
JOB_STATE_CANCELLED |
You cancelled it |
JOB_STATE_EXPIRED |
Pending or running for more than 48 hours; no results |
This script polls the saved job, then reads results from either a file or an inline list. It also counts failed lines.
import json
import time
from google import genai
client = genai.Client()
job_name = open("last_job.txt").read().strip()
done = {"JOB_STATE_SUCCEEDED", "JOB_STATE_FAILED",
"JOB_STATE_CANCELLED", "JOB_STATE_EXPIRED"}
job = client.batches.get(name=job_name)
while job.state.name not in done:
print("State:", job.state.name)
time.sleep(30)
job = client.batches.get(name=job_name)
print("Final state:", job.state.name)
if job.state.name != "JOB_STATE_SUCCEEDED":
print("Error:", job.error)
elif job.dest and job.dest.file_name:
# File job: results are a JSONL file
raw = client.files.download(file=job.dest.file_name).decode("utf-8")
ok, failed = 0, 0
for line in raw.splitlines():
if not line:
continue
row = json.loads(line)
if row.get("response"):
text = row["response"]["candidates"][0]["content"]["parts"][0]["text"]
print(row.get("key"), "->", text[:80])
ok += 1
else:
print(row.get("key"), "ERROR:", row.get("error"))
failed += 1
print(f"{ok} ok, {failed} failed")
elif job.dest and job.dest.inlined_responses:
# Inline job: one result per request
for i, item in enumerate(job.dest.inlined_responses, start=1):
if item.response:
print(i, item.response.text)
elif item.error:
print(i, "ERROR:", item.error)
A job can succeed while some lines fail. Google advises checking failedRequestCount in the job’s batch stats and treating each output line as either a response or an error status.
Skip polling with webhooks
Since 4 May 2026 the Gemini API can push a notification instead. You register a webhook for the batch.succeeded and batch.failed events:
from google import genai
client = genai.Client(http_options={"api_version": "v1beta"})
webhook = client.webhooks.create(
name="MyBatchWebhook",
subscribed_events=["batch.succeeded", "batch.failed"],
uri="https://your-server.example/gemini-callback",
)
print("Created webhook:", webhook.name)
List, Cancel and Delete Jobs
Three short calls cover job housekeeping. Each takes the job name, such as batches/123456789.
from google import genai
client = genai.Client()
# List recent jobs (page_size is optional)
for j in client.batches.list(config={"page_size": 10}):
print(j.name, j.display_name, j.state.name)
# Cancel: stops processing new requests in the job
client.batches.cancel(name="batches/123456789")
# Delete: stops processing and removes the job from the list
client.batches.delete(name="batches/123456789")
Batch results are kept for 6 weeks by default, then deleted for good. Download and store anything you need before then.
Batch embeddings
Embeddings use a separate method, client.batches.create_embeddings(), with either a file or an inline list. The source is passed as a dictionary:
job = client.batches.create_embeddings(
model="gemini-embedding-2",
src={"file_name": uploaded.name},
config={"display_name": "docs-embeddings-1"},
)
For inline embedding jobs, read results from job.dest.inlined_embed_content_responses. My Gemini Embedding 2 tutorial covers the model itself.
The Same Job With curl
The REST method is batchGenerateContent on the model. Requests sit inside batch.input_config.requests.requests, and each one can carry a metadata.key.
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-4-hydrogen:batchGenerateContent" \
-X POST \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"batch": {
"display_name": "curl-batch-1",
"input_config": {
"requests": {
"requests": [
{"request": {"contents": [{"parts": [{"text": "Describe photosynthesis in 2 lines."}]}]}, "metadata": {"key": "request-1"}},
{"request": {"contents": [{"parts": [{"text": "Name 3 pizza toppings."}]}]}, "metadata": {"key": "request-2"}}
]
}
}
}
}'
# Check status later (use the name from the response)
curl "https://generativelanguage.googleapis.com/v1beta/batches/123456789" \
-H "x-goog-api-key: $GEMINI_API_KEY"
Google’s docs also say the OpenAI compatibility layer supports the Batch API. That helps if you already have code built on my OpenAI Batch API tutorial.
Which Features Work in Batch (and the Interactions API Gap)
Each batch request accepts the same settings as a normal call. Google’s docs show these working inside batch jobs:
- System instructions: per request, inside
config. - Tools: for example Google Search grounding with
{"google_search": {}}. Normal grounding fees still apply. - Structured output:
response_mime_typeplusresponse_schema, including Pydantic models. - Multimodal input: the same modalities as the normal API, via File API references.
- Image output: set
response_modalitiesto text and image on image models. - Context caching: pass a
cached_contentname per request. Cache hits bill at the normal caching rate.
Two limits matter. First, Gemini 4 models support implicit caching only, so explicit cached_content works with models such as Gemini 3.8 Flash. My context caching tutorial explains the difference.
Second, each batch line is one request with one response. A multi-step function calling loop does not fit, because you would need to send results back in a new request.
The Interactions API gap
Google now leads its docs with the Interactions API (client.interactions.create). However, the Batch API page says the feature is only available with the generateContent API.
The Interactions overview lists Batch API, Python automatic function calling and explicit caching as “not yet available”. So batch code uses contents and config, not the newer input format. See my Interactions API tutorial for the new style.
Note: sampling settings such as temperature, top_p and top_k are ignored on Gemini 4 and Gemini 3.6+ models, per Google’s troubleshooting guide. Leave them out of batch configs for those models.
Limits and Turnaround
Batch has its own rate limits, separate from normal calls. Here is what Google’s docs listed on 4 December 2026.
| Limit | Value |
|---|---|
| Concurrent batch requests | 100 |
| Inline request size | Under 20 MB in total |
| Input file size | 2 GB per file |
| File storage | 20 GB |
| Enqueued tokens, Tier 1 | Gemini 4 Carbon / Neon: 5M; Hydrogen: 3M; 3.8 Flash: 3M; 3.5 Flash-Lite: 10M; Embedding: 500K |
| Target turnaround | 24 hours (often faster) |
| Expiry | 48 hours pending or running, then JOB_STATE_EXPIRED |
| Result retention | 6 weeks by default |
| Free tier | Batch pricing not available |
Enqueued tokens count across all your active jobs for one model. The docs list separate values for Tier 2 and Tier 3, and you can see your own limits on the rate limit page in AI Studio. My rate limits guide explains how tiers work.
Gemini vs OpenAI vs Claude Batch
All three big providers sell batch processing at a 50% discount with a 24-hour window. The details differ.
| Feature | Gemini Batch API | OpenAI Batch API | Claude Message Batches |
|---|---|---|---|
| Discount | 50% | 50% | 50% |
| Inline submit | Yes, under 20 MB | No, file only | Yes, in one API call |
| File size | 2 GB | 200 MB, 50,000 requests | 256 MB, 100,000 requests |
| Window | 24 h target, expires at 48 h | 24 h | 24 h maximum |
For step-by-step code on the others, read my OpenAI Batch API tutorial and Claude Message Batches API tutorial.
Troubleshooting: Common Problems and Fixes
| Problem or error | Likely cause | Fix |
|---|---|---|
400 INVALID_ARGUMENT on create |
A JSONL line is not valid JSON, or a field is in the wrong place | Validate each line with json.loads. Keep contents inside request |
403 PERMISSION_DENIED |
Free-tier project, unpaid billing, or a key reported as leaked | Link billing, clear past-due balances, or create a new key in AI Studio |
429 RESOURCE_EXHAUSTED |
Too many active jobs, enqueued token limit, or spend limit hit | Wait for jobs to finish, split files smaller, or request a higher tier |
404 NOT_FOUND on get |
Wrong job name or the job was deleted | Use the full name, such as batches/123456789 |
Job ends as JOB_STATE_EXPIRED |
It was pending or running over 48 hours | Resubmit as several smaller batches |
| Job succeeded but rows are missing | Some lines failed on their own | Check failedRequestCount and the error field per line, then resubmit those keys |
| Two identical jobs and a double bill | The create call ran twice | Save the job name after create and check it before creating again |
Code using client.interactions fails in batch |
Batch supports only generateContent requests |
Write batch lines with contents and config |
For a wider list of status codes, see my Gemini API errors guide. The Python SDK already retries 429 and 5xx errors up to four times with backoff.
FAQ
How much cheaper is the Gemini Batch API?
Batch usage is priced at 50% of the standard paid-tier cost for the same model. For example, Gemini 4 Hydrogen costs $0.75 input and $3.75 output per 1M tokens in batch.
How long does a Gemini batch job take?
Google targets a 24-hour turnaround, and many jobs finish much faster. A job still pending or running after 48 hours expires with no results.
Can I use the Batch API on the free tier?
No. The Batch price column shows “Not available” for the free tier, so you need a project with billing linked.
Should I use inline requests or a JSONL file?
Use inline requests for small jobs under 20 MB in total. Use a JSONL file, up to 2 GB, for larger jobs and when you want your own keys on each result.
Does the Batch API work with the Interactions API?
Not yet. Google lists the Batch API as a generateContent feature that is not yet available in the Interactions API.
Can I combine batch with context caching?
Yes. Pass a cached_content name in a request’s config and cache hits bill at the normal caching rate. Gemini 4 models support implicit caching only.
How long are batch results stored?
Results are kept for 6 weeks by default and then deleted permanently, so download them soon after the job succeeds.
Sources
- Google: Gemini Batch API documentation
- Google: Gemini Developer API pricing
- Google: Gemini API rate limits
- Google: Interactions API overview
- Google: Gemini API troubleshooting guide
- Google: Gemini API release notes
- Google Developers Blog: Batch API embeddings and OpenAI compatibility
- PyPI: google-genai




