API
Routes, credentials, shapes; the served OpenAPI document is the reference.
Routes
| Route | Purpose |
|---|---|
POST /v1/jobs | Submit a batch job; always replies 202 |
POST /v1/validate | Dry-run the admission checks: no job is created, nothing runs and nothing is billed |
GET /v1/jobs/{batch_id} | Read a whole batch: its status plus the request as submitted; kept 7 days after its last write |
GET /v1/jobs/{batch_id}/status | Poll a batch's status fields only, named
by the batch_id a POST /v1/jobs reply carries |
GET /v1/info | Describe this instance: its name
({model}-{region-short}, e.g. gemma-4-e2b-usc1), its model
and region as separate fields, the file types it accepts, its task shape, and its
admission limits |
Credentials
Every call carries an x-api-key header (GCP guide) and a
Google-signed ID token for a service account you control, its email included. Either missing
rejects the call.
Rate limits
Per Google Cloud project, per minute, across all models and regions. Over the limit:
429 RESOURCE_EXHAUSTED -- wait for the next minute and retry. Need more?
Contact support.
| Routes | Limit |
|---|---|
POST /v1/jobs, POST /v1/validate | 10 per minute per project |
GET /v1/jobs/{batch_id}, GET /v1/jobs/{batch_id}/status,
GET /v1/info | 60000 per minute per project |
Size caps
Each instance sets its own admission caps and publishes them at GET /v1/info:
the request body's size (max_request_bytes, 0.95 MiB -- a larger body is refused as
REQUEST_TOO_LARGE before it is parsed), the batch's total input bytes
(max_batch_bytes), the files per task, the tasks and files per batch, and each
file's size (max_file_bytes; the per-model figures are on the
Models page).
Request and response
A job names one input folder (source_prefix) with bare-name task file lists under
it and an output destination in the same bucket. A task's files are its own: for
models that take one, the first .json file is the task's config file, the inputs
follow it (see Models). Unknown fields
are rejected; the service issues every batch_id. POST /v1/jobs replies
202 with the issued batch_id and the batch's status -- its
state, tasks counts and expires_at. A submitted job
concludes -- completed, or definitively failed -- within 24 hours; waits for capacity sit inside
that window, and expires_at names the batch's own deadline. Errors carry one
envelope with a machine-readable reason.
curl -X POST "<endpoint>/v1/jobs" \
-H "x-api-key: $API_KEY" \
-H "Authorization: Bearer $(gcloud auth print-identity-token \
--impersonate-service-account=$CALLER_SA \
--audiences=<endpointServiceName> --include-email)" \
-H "Content-Type: application/json" \
-d '{"source_prefix": "gs://my-bucket/in/",
"tasks": [["a.txt"], ["b.txt"]],
"destination": "gs://my-bucket/out/"}'
Admission also writes one object of its own, as your caller service account, into your
bucket: a create-only request summary at
{destination}_batchml/{batch_id}.request.json -- the request's shape, never its
task list. It is never overwritten and nothing reads it later; delete it whenever you like. A
submit that admits nothing writes nothing at all, and POST /v1/validate writes only
this summary, with validate in place of the batch_id.
Structured output
Gemma 4 E2B answers as JSON when the task's config file -- its first .json input --
carries an answer_schema, a JSON Schema for the answer; the shaped answer lands in
the task's .content.json. Allowed keywords:
type, properties, required, enum,
const, items, additionalProperties,
description, title -- anything else is rejected before the job runs.
The model may ignore a constraint it cannot enforce. To pull four key facts out of every
document:
{"type": "object",
"properties": {"title": {"type": "string", "description": "The document's title"},
"date": {"type": "string", "description": "The document's date"},
"parties": {"type": "array", "items": {"type": "string"},
"description": "The people or organisations the document names"},
"amount": {"type": "string", "description": "The total amount, with its currency"}},
"required": ["title", "date", "parties", "amount"],
"additionalProperties": false}
Generation options
The same config file may carry a generation object with the sampling keys
temperature, top_p, top_k, max_tokens,
seed, stop, repetition_penalty,
frequency_penalty and presence_penalty -- anything else is rejected
before the job runs, and a key you leave out uses the model's own serving default. A
max_tokens above the model's output limit is capped at that limit, never a
rejection -- the answer runs to the smaller of the two.
Results
Each finished task writes its answer to your bucket beside the task's result file, both named
by the job's batch_id and the task's position in tasks: the answer -- a
content object {destination}{batch_id}.{task_index}.content.<ext>, or, for
Whisper large-v3, a folder of chunk files (below) -- and the result file
{destination}{batch_id}.{task_index}.json about the task -- never the answer. No
result file: the task is not done.
| Content type | The task's content object |
|---|---|
application/json | {batch_id}.{task_index}.content.json |
text/plain; charset=utf-8 | {batch_id}.{task_index}.content.txt |
Whisper large-v3's answer is a folder of chunk files, not one content object: the audio is
cut at quiet points into pieces of at most 590 seconds (about ten minutes), and each piece's
transcript is written once, into the task's own folder, as
{batch_id}.{task_index}/chunk.NNNNN.content.json
(NNNNN counts up from 00000). A file of ten minutes or less produces
exactly one chunk file. A chunk file is one JSON object with the keys input,
index, start, end, text,
start_sample and samples -- the times in seconds, absolute within the
whole audio file -- and the task's result file names the folder through its
content: {"prefix": "{batch_id}.{task_index}/", "count": N}. A
finished task's output folder:
demo-1.0/chunk.00000.content.json
demo-1.0/chunk.00001.content.json
demo-1.0.json
One chunk file, whole:
{"input": "panel.wav", "index": 1, "start": 592.4, "end": 1180.6, "text": "Welcome back, everyone.", "start_sample": 9478400, "samples": 9411200}
A completed task's result file:
{"schema_version": 2,
"batch_id": "demo-1",
"task_index": 0,
"status": "completed",
"content": {"file": "demo-1.0.content.json", "content_type": "application/json", "bytes": 6420},
"inputs": [{"name": "invoice.pdf", "generation": 1700000000123456}],
"usage": {"ai_usage": <measured>, "volume_in_gb": 0.0000021},
"metadata": {"model": "demo", "region": "us-central1", "product_version": "v1.0.0"},
"model_metadata": {"files": 1},
"error": null}
A failed task's:
{"schema_version": 2,
"batch_id": "demo-1",
"task_index": 1,
"status": "failed",
"content": null,
"inputs": [{"name": "notes.exe", "generation": 1700000000987654}],
"usage": {"ai_usage": <measured>, "volume_in_gb": 0.0000021},
"metadata": {"model": "demo", "region": "us-central1", "product_version": "v1.0.0"},
"model_metadata": {},
"error": {"kind": "adapter_rejected", "detail": "the input is not a document this model reads"}}
The shape is the same for every model, and every key is always present:
schema_version: the result file's format version,2.batch_id,task_index: the batch and the task's position intasks-- the two halves of every object name above.status:completedorfailed.content: where the answer is -- a{file, content_type, bytes}reference to the content object, or, for Whisper large-v3, a{prefix, count}reference to its chunk folder;nullexactly whenfailed.inputs: the input files the task read, in request order -- each with itsnameand thegenerationit pinned.usage: the task's measuredai_usage-- its usage at the model's rate (see Models), before the minimums and the discount -- and the input volume in GiB.metadata: themodel, theregionthat processed the task, and the BatchMLproduct_version.model_metadata: the model's own details, free-form, capped at 4 KiB.error: on a failure, a machine-readablekindand adetail;nullexactly whencompleted.
Errors
An error is one envelope: an HTTP status, a message in prose, and one detail
whose reason is the code to branch on. A refusal made before the API's own logic
runs -- a missing or invalid API key or ID token, a wrong audience, the service not enabled in
your project, or a per-minute quota over the limit (the 429 above) -- carries
Google's own body, {"code", "message"}, with no reason.
| Reason | HTTP | Meaning | What to do |
|---|---|---|---|
UNAUTHENTICATED | 401 | No decodable caller identity on the request | Send a Google-signed ID token for a service account you control |
CALLER_NOT_A_SERVICE_ACCOUNT | 403 | The caller's identity is not a user-managed service account | Call with a service account's ID token, not a user's |
IMPERSONATION_DENIED | 403 | BatchML's service account could not mint a token for the account on your ID token, or its grant was revoked | Grant it
roles/iam.serviceAccountTokenCreator on that account (GCP guide,
step 2) |
SOURCE_ACCESS_DENIED | 403 | Reading the source bucket, its listing, or one input's metadata was denied as your caller service account | Grant that account the storage roles on the bucket (GCP guide, step 2) |
DESTINATION_NOT_WRITABLE | 403 | Creating the request summary
under your destination was denied | Grant
roles/storage.objectCreator on the bucket |
DESTINATION_NOT_READABLE | 403 | Reading that request summary's metadata was denied | Grant roles/storage.objectViewer on the bucket |
BUCKET_OWNER_MISMATCH | 403 | The source bucket's owning project is not the API key's own project | Use a bucket your project owns, or call with that project's API key |
PERIMETER_BLOCKED | 403 | The bucket read crossed a VPC Service Controls boundary | Move the bucket out of the perimeter, or allow the service inside it |
INVALID_ARGUMENT | 400/422 | One structural defect: duplicate
tasks, a task's file count, a destination in another bucket, or a source folder
holding far more objects than the batch names | Read message; it names the
defect |
VALIDATION_ERROR | 422 | A malformed request body, including an object name over 1024 characters | Fix the fields the reply's detail names |
REQUESTER_PAYS_UNSUPPORTED | 422 | The source bucket has Requester Pays enabled | Use a bucket without Requester Pays |
CROSS_REGION_BUCKET | 422 | The bucket's location is not exactly the instance's region | Use a regional bucket in that region |
BUCKET_ACL_MODE_UNSUPPORTED | 422 | The bucket has uniform bucket-level access disabled | Enable uniform bucket-level access on the bucket |
SOURCE_NOT_READABLE | 422 | Listing the source folder failed for a reason that is not permissions | Read message; fix the bucket-side
condition it names |
REQUEST_TOO_LARGE | 413 | The request body is over the instance's request cap | Split the batch across several requests |
INSTANCE_PAUSED | 409 | The instance is paused; no machine can run a task | Wait for it to resume -- GET /v1/info reports
paused |
BATCH_STATE_UNREADABLE | 409 | A freshly issued
batch_id already has a record | Submit again; a fresh job gets a fresh id |
UNKNOWN_BATCH | 404 | No batch for this batch_id:
never issued, malformed, or past its 7-day retention | Check the batch_id
from the 202 reply |
METHOD_NOT_ALLOWED | 405 | The path is declared but not for this HTTP method | Call a declared method |
unsupported_type | with 202 | A file's type is not one the model accepts | Convert or rename the file; GET /v1/info lists the
accepted types |
file_too_large_to_load | with 202 | A file is over the instance's per-file cap | Split the file, or leave it out |
source_missing | with 202 | The object was not found when the batch was listed | Confirm the object is there, then submit again |
OBJECT_NAME_UNSUPPORTED | with 202 | An object name, or a declared prefix, contains a quote, a backslash or a control byte | Rename the object |
The per-file reasons ride the reply's rejected_files list, beside the
202: the batch still runs on the files it accepted.
Versioning
Additions ship on v1; an incompatible change ships v2 alongside it,
with 6 months' retirement notice for the superseded version.
Reference
Full schemas: the served OpenAPI document, available from the Marketplace listing or on request via support.