Gemini Batch Request Identifiers Need Item-Level Correlation
Gemini Batch API input files pair each GenerateContent request with a user-defined identifier, and Google returns that identifier with the corresponding output. Production systems should make identifiers unique within a batch, bind them to immutable request manifests, validate every returned item, and keep batch job state separate from each request response, error, policy decision, and downstream disposition.

Gemini Batch API input files wrap each GenerateContentRequest with a user-defined key. Google's batch guide says the response carries the same identifier so the client can identify which output belongs to which request. Inline REST requests can also place an identifier in request metadata, and the returned inline item carries the associated metadata.
That identifier needs an item-level audit contract. A batch name identifies the asynchronous container. It cannot identify the authenticated request behind a response line. It also cannot show which item failed or which result the application accepted.
TL;DR
- Assign a unique, opaque client identifier to every request within a Gemini batch.
- Bind each identifier to an immutable manifest containing identity and route policy plus model and request digest, with submission position recorded separately.
- Validate the returned identifier and item output before accepting any response, even when the batch job reaches
JOB_STATE_SUCCEEDED. - Keep batch state and item response or error as evidence. Record application disposition, retry lineage, and downstream effects separately.
Google returns the user-defined identifier with file outputs
The Gemini Batch API guide describes two submission forms. Inline requests embed a list of generation requests in the batch creation call. Input-file batches upload JSON Lines, with one JSON object per line containing a user-defined identifier and a valid GenerateContentRequest under request.
Google states the purpose directly: the user-defined identifier appears in the response to indicate which output belongs to which request. Its example sends request-1 and request-2, then says the output for request-1 is annotated with the same identifier.
Treat the identifier as opaque correlation evidence. Preserve case and punctuation under your accepted identifier grammar. Avoid trimming or converting it to a number. 00042 and 42 can represent different application records even if a loose parser treats them as the same value.
A practical identifier can be a random application value with no user data embedded in it. Email addresses and account numbers turn an operational join field into a leakage path. Ticket subjects or prompt fragments create the same problem. The protected manifest can map the opaque value back to the application record.
Inline and file batches expose different envelopes
Google recommends inline requests for smaller batches whose total request size stays under 20 MB. Larger jobs can use an input file, and the guide documents a maximum file size of 2 GB. These are transport choices around the same item-level generation problem, but their output envelopes differ.
The batchGenerateContent API reference says inline batches return inlinedResponses. Each InlinedResponse contains an output union with either an error status or a response. It also carries output-only metadata associated with the request. REST examples place the identifier inside that request metadata.
For file-backed jobs, the guide describes a JSONL output where each line is a GenerateContentResponse or a status object. The detailed input-file contract supplies the identifier wrapper used for correlation. Parse the documented envelope for the API version and submission mode rather than forcing both forms through an untyped list of response bodies.
The API reference also says output responses are written in the same order as input requests for file and inline output. Keep the submitted position as supporting evidence, but join on the returned identifier where the documented correlation envelope provides one. Position is valuable for detecting contradictions. It should not silently repair a missing or mismatched identifier.
The submission manifest anchors every identifier
Create the item manifest before the batch leaves the application. One row per identifier should retain the batch operation ID, submission mode, zero-based input position, authenticated user or agent, tenant, requested model, normalized route, policy version, request digest, and creation timestamp.
Include the intended output contract and data classification. If the item is allowed to call tools or use cached content, record those policy decisions separately. The manifest should also contain the local business-operation ID so responders can connect a batch item to the event that requested it.
Make each identifier unique within the batch. Google calls the field user-defined, but a production route needs a stricter local invariant. Duplicate identifiers create an ambiguous join even if response order remains intact. Reject the batch before upload or dispatch rather than inventing suffixes after the caller has committed its manifest.
The AI audit log schema supplies the surrounding identity and authorization fields. Batch correlation adds a container record plus immutable child item records. A batch dashboard can summarize those children, while incident evidence still points to one exact request.
On a review screen, show the batch name in a gray header strip. List item identifiers below it in monospace, one per row, with the input position at left and disposition at right. A red missing-identifier badge should occupy the same column as normal values so a responder sees the broken join immediately.
Job state and item outcome are different facts
Google documents batch states including pending, running, succeeded, failed, cancelled, and expired. A succeeded state means the job completed and results can be retrieved.
The output contract permits an item-level response or error for inline requests, while file output can contain a generation response or a status object. Production ingestion must therefore walk every item after container completion. It must validate the identifier and parse the output union before inspecting generation metadata and assigning an application disposition.
Keep the record in separate layers. The container has a provider job state, and each child has a provider item outcome. The application records its own disposition under a controlled vocabulary. Downstream effect state belongs in another layer. A valid model response can still fail the application's schema or safety policy, while an item error can leave other children available for review.
Transport or container completion opens the next validation stage. It never grants application acceptance.
My opinion is that a green batch badge without item counts is operationally dishonest. It hides the exact failures an asynchronous system makes harder to notice.
Returned identifiers require exact validation
For every output item, require an identifier present in the submitted manifest. Compare it exactly after only the documented serialization decoding. Mark blank, wrong-type, oversized, malformed, duplicate, and unknown values with separate findings.
Then verify the supporting position. Google documents same-order output, so a known identifier arriving at another submitted position is contradictory evidence. Preserve the complete output and stop automatic acceptance for that item. Avoid swapping rows until the identifiers line up because that conceals the contract violation the audit should surface.
Missing output needs a reconciliation pass after the provider result is fully downloaded. Compare the returned identifier set with the submitted manifest. Every submitted identifier needs a named terminal state. The recognized states are response observed and item error observed; use output missing when neither arrives. Extra identifiers should enter quarantine because they lack an authorized request record.
Response validation continues after correlation. Inspect responseId and modelVersion, then examine prompt feedback and candidate finish reasons. Validate required safety evidence and any structured-output contract. The Gemini usage metadata validation guide covers provider token evidence at the same item level. Token totals belong to the child attempt, not only to the batch summary.
Correlation is neither authorization nor idempotency
A matching identifier proves that the output can be joined to the submitted manifest under the batch contract. Authorization was established when the authenticated request entered the route and policy evaluated its model, data, tools, and parameters.
Do not let a caller choose another tenant's manifest identifier and inherit its permission. Scope the lookup by tenant plus batch operation. Better still, generate opaque identifiers server-side after authorization. The manifest can retain a caller-supplied business ID in another protected field.
The identifier also provides no documented duplicate-effect protection. If an accepted batch output triggers an email or database update, the application needs a separate idempotency value and effect ledger. Tool actions and queued publications need the same protection. Batch retries make that distinction visible because the same business operation may be submitted in a new provider batch.
A per-route AI policy can require server-generated identifiers and maximum item counts. It can also define approved models, allowed batch modes, response schemas, and handling for partial failures. It can prohibit downstream effects until every required item-level check has passed.
Retries need new attempts and stable business lineage
Google says expired jobs have no results to retrieve and suggests resubmitting or splitting requests into smaller batches. A failed or expired container should remain immutable in the audit. The replacement batch gets a new provider batch name and a new local attempt record.
Keep the original business-operation ID for each item. Generate a fresh submission identifier when your namespace represents an attempt, or retain a stable item ID in the manifest and add a separate attempt identifier. Document the choice. Reusing one undifferentiated identifier across several batches makes duplicate outputs difficult to distinguish.
Retry only the eligible children. A batch with 900 accepted responses and 100 item errors should not automatically resubmit all 1,000 requests. Build the next manifest from the selected failed items, reference each parent item, and apply current policy again before dispatch.
The safe idempotent LLM retries guide describes why operation and attempt IDs need separate fields. Batch correlation sits below that structure. It connects one provider output to one attempt, while downstream idempotency protects any real-world effect.
Release fixtures should corrupt the join
Place a Gemini-compatible batch stub behind the deployed HTTP route. Submit four items with distinct opaque identifiers and request digests. Return four valid correlated outputs in the documented order, then confirm each response lands on the correct child record with its model and disposition evidence.
In the next fixture, return the same valid outputs in a different order. Because Google documents same-order output, the system should record an order contradiction even though exact identifiers still make the association visible. Hold automatic downstream processing until route policy resolves the finding.
Add one missing identifier, one unknown identifier, a duplicate returned identifier, an explicit item error, and a submitted identifier with no output. Follow with a correct identifier attached to response bytes whose digest or expected model evidence belongs to another item. Every case should preserve raw evidence and create a stable named finding.
Finish with a terminal succeeded container holding a mixture of valid responses and item errors. The batch summary should show the provider state plus child counts. Only validated children should become eligible for application acceptance. Then expire another job and retry one child in a new batch, proving that the parent attempt remains visible and no downstream effect executes twice.
DeepInspect
DeepInspect can inspect authenticated user or agent HTTP requests deliberately routed between an application and Gemini's Batch API. At that boundary, it can require unique request identifiers and bind them to identity-aware manifests. It can also validate returned items, apply per-route response policy, and write container plus item decisions into audit records.
The application owns business-operation IDs and manifest creation. It also owns provider file storage, polling or webhook orchestration, retry selection, downstream effect idempotency, and local actions after accepted results. Direct batch traffic that bypasses the proxy remains outside DeepInspect's enforcement.
Book a technical deep dive at deepinspect.ai.
Frequently asked questions
- Are Gemini batch identifiers supplied by Google?
The input-file identifier is user-defined. The client places it beside the request, and Google's guide says the response uses the same value to identify the corresponding output. Generate opaque values and store their meaning in a protected application manifest.
- Must batch request identifiers be unique?
Google's guide explains correlation but the cited page does not state a uniqueness guarantee for caller values. Your gateway should require uniqueness within the batch because duplicates make item-level association ambiguous before provider processing begins.
- Can response order replace the identifier?
Google's API reference says responses are returned in the same order as input requests. Preserve position as supporting contract evidence. Use the returned identifier for the documented item join and flag any disagreement rather than silently trusting one field over the other.
- Does JOB_STATE_SUCCEEDED mean every request succeeded?
It means the batch completed and results can be retrieved. Inspect each output item because the schema permits item responses and item errors. File output can contain a generation response or a status object.
- Can a batch identifier authorize a downstream action?
No. Authorization comes from authenticated identity and route policy. A matching identifier only correlates an output with a submitted manifest item. Downstream actions need their own permission check and idempotency protection.
- How should partial batch retries work?
Create a new batch attempt containing only eligible failed or missing items. Link every new item to its prior business operation and attempt. Preserve the old provider batch and identifiers. Retain item outcomes and dispositions instead of overwriting them.