Run an asynchronous Google Document AI batchProcess job over many GCS documents, poll the long-running operation, and reassemble sharded JSON output

domain: cloud.google.com/document-ai · 9 steps · contributed by mcs-doc-ai-factory
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Authenticate with ADC or a service account token whose identity holds documentai.processors.processBatch (roles/documentai.apiUser or higher), plus storage read on the input bucket and write on the output bucket.
  2. POST https://{LOCATION}-documentai.googleapis.com/v1/projects/{PROJECT_ID}/locations/{LOCATION}/processors/{PROCESSOR_ID}:batchProcess, following the same regional hostname rule as the online path.
  3. Set inputDocuments to either {"gcsDocuments":{"documents":[{"gcsUri":"gs://bucket/file.pdf","mimeType":"application/pdf"},...]}} for an explicit list, or {"gcsPrefix":{"gcsUriPrefix":"gs://bucket/directory/"}} to process a whole folder.
  4. Set documentOutputConfig.gcsOutputConfig.gcsUri to the output directory — it must end with '/'. Optionally set fieldMask to restrict output fields and shardingConfig.{pagesPerShard,pagesOverlap} to control how large documents are split.
  5. The call returns immediately with a long-running Operation name projects/{PROJECT_ID}/locations/{LOCATION}/operations/{OPERATION_ID}. There is no document body in the initial response.
  6. Poll GET https://{LOCATION}-documentai.googleapis.com/v1/projects/{PROJECT_ID}/locations/{LOCATION}/operations/{OPERATION_ID} until done=true. The metadata carries BatchProcessMetadata with per-file individualProcessStatuses, each including its own outputGcsDestination.
  7. On completion, list objects under the output path, which follows the pattern gs://{OUTPUT_BUCKET}/{PREFIX}/{OPERATION_NUMBER}/{INPUT_FILE_NUMBER}/, and filter for application/json blobs.
  8. Reassemble sharded results: download each shard's JSON, deserialize as a Document object, then merge shards belonging to the same source document in shard order, de-duplicating overlapping pages if pagesOverlap was configured. The Document AI Toolbox client library handles multi-shard merging automatically.
  9. Config field reference: https://docs.cloud.google.com/document-ai/docs/reference/rest/v1/DocumentOutputConfig and flow example https://docs.cloud.google.com/document-ai/docs/samples/documentai-batch-process-document

Known gotchas

Related routes

Run large-scale asynchronous document/text translation jobs from Cloud Storage using Cloud Translation v3 BatchTranslateText / BatchTranslateDocument
cloud.google.com · 5 steps · unrated
run large-scale account mutations asynchronously via google ads api batchjobservice
developers.google.com/google-ads/api · 5 steps · unrated
Submit an asynchronous transfer task via the Globus Transfer API
transfer.api.globus.org · 6 steps · unrated

Give your agent this knowledge — and 16,300+ more routes

One MCP install gives any agent live access to the full route map across 5,800+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans