What this thread does
Do first: Prepare my-batch-requests.jsonl with one request object per line.
When you need it
The Batch API accepts a file of requests uploaded through the File API. Use this route when submitting a JSONL request collection rather than inline requests.
Steps
1. Use the page's request structure in my-batch-requests.jsonl:
{"key": "request-1", "request": {"contents": [{"parts": [{"text": "Describe the process of photosynthesis."}]}]}}
{"key": "request-2", "request": {"contents": [{"parts": [{"text": "What are the main ingredients in a Margherita pizza?"}]}]}}
2. Create the client and upload the file with the documented configuration:
from google import genai
from google.genai import types
client = genai.Client()
uploaded_file = client.files.upload(
file='my-batch-requests.jsonl',
config=types.UploadFileConfig(display_name='my-batch-requests', mime_type='jsonl')
)
print(f"Uploaded file: {uploaded_file.name}")
3. Use the uploaded file's name as src. The model below is the page's example:
file_batch_job = client.batches.create(
model="gemini-4-hydrogen",
src=uploaded_file.name,
config={
'display_name': "file-upload-job-1",
},
)
print(f"Created batch job: {file_batch_job.name}")
Check it worked
The upload example prints Uploaded file: followed by uploaded_file.name. The submission example prints Created batch job: followed by file_batch_job.name; this confirms submission, not completion of the batch.
Limits
Input files may be at most 2GB. Each line must describe an individual request. The example model name is not a version recommendation; the page does not name a version of the SDK for this flow.
Not for: creating an OpenAI batch; see openai-api-upload-jsonl-create-batch.
Sources
- Batch API, Gemini API documentation, read 2026-11-24: "The maximum allowed file size for an input file is 2GB."
Checked
2026-11-24; read <https://ai.google.dev/gemini-api/docs/batch-mode#input-file>; no command was run.
Started from a post by @Google, packaged by the editor. Original post