BatchML

API

Routes, credentials, shapes; the served OpenAPI document is the reference.

Routes

RoutePurpose
POST /v1/jobsSubmit a batch job; always replies 202
POST /v1/validateDry-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}/statusPoll a batch's status fields only, named by the batch_id a POST /v1/jobs reply carries
GET /v1/infoDescribe 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.

RoutesLimit
POST /v1/jobs, POST /v1/validate10 per minute per project
GET /v1/jobs/{batch_id}, GET /v1/jobs/{batch_id}/status, GET /v1/info60000 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 typeThe 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:

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.

ReasonHTTPMeaningWhat to do
UNAUTHENTICATED401No decodable caller identity on the requestSend a Google-signed ID token for a service account you control
CALLER_NOT_A_SERVICE_ACCOUNT403The caller's identity is not a user-managed service accountCall with a service account's ID token, not a user's
IMPERSONATION_DENIED403BatchML's service account could not mint a token for the account on your ID token, or its grant was revokedGrant it roles/iam.serviceAccountTokenCreator on that account (GCP guide, step 2)
SOURCE_ACCESS_DENIED403Reading the source bucket, its listing, or one input's metadata was denied as your caller service accountGrant that account the storage roles on the bucket (GCP guide, step 2)
DESTINATION_NOT_WRITABLE403Creating the request summary under your destination was deniedGrant roles/storage.objectCreator on the bucket
DESTINATION_NOT_READABLE403Reading that request summary's metadata was deniedGrant roles/storage.objectViewer on the bucket
BUCKET_OWNER_MISMATCH403The source bucket's owning project is not the API key's own projectUse a bucket your project owns, or call with that project's API key
PERIMETER_BLOCKED403The bucket read crossed a VPC Service Controls boundaryMove the bucket out of the perimeter, or allow the service inside it
INVALID_ARGUMENT400/422One 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 namesRead message; it names the defect
VALIDATION_ERROR422A malformed request body, including an object name over 1024 charactersFix the fields the reply's detail names
REQUESTER_PAYS_UNSUPPORTED422The source bucket has Requester Pays enabledUse a bucket without Requester Pays
CROSS_REGION_BUCKET422The bucket's location is not exactly the instance's regionUse a regional bucket in that region
BUCKET_ACL_MODE_UNSUPPORTED422The bucket has uniform bucket-level access disabledEnable uniform bucket-level access on the bucket
SOURCE_NOT_READABLE422Listing the source folder failed for a reason that is not permissionsRead message; fix the bucket-side condition it names
REQUEST_TOO_LARGE413The request body is over the instance's request capSplit the batch across several requests
INSTANCE_PAUSED409The instance is paused; no machine can run a taskWait for it to resume -- GET /v1/info reports paused
BATCH_STATE_UNREADABLE409A freshly issued batch_id already has a recordSubmit again; a fresh job gets a fresh id
UNKNOWN_BATCH404No batch for this batch_id: never issued, malformed, or past its 7-day retentionCheck the batch_id from the 202 reply
METHOD_NOT_ALLOWED405The path is declared but not for this HTTP methodCall a declared method
unsupported_typewith 202A file's type is not one the model acceptsConvert or rename the file; GET /v1/info lists the accepted types
file_too_large_to_loadwith 202A file is over the instance's per-file capSplit the file, or leave it out
source_missingwith 202The object was not found when the batch was listedConfirm the object is there, then submit again
OBJECT_NAME_UNSUPPORTEDwith 202An object name, or a declared prefix, contains a quote, a backslash or a control byteRename 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.