← Blog

Gemini Resumable Upload Headers Need a Gateway Gate

Parminder Singh
Parminder Singh··8 min read
Summarize with AI

Gemini resumable upload uses a start request that declares protocol, command, content length, and content type, followed by a byte upload with an offset and finalize command. A gateway should bind those headers to an approved upload intent and protect the returned session URL. It should verify the final File resource before any model request references it.

Platform & Architectureai-securityllm-securitypolicy-enforcementzero-trustarchitectureaudit
Gemini Resumable Upload Headers Need a Gateway Gate

Gemini's REST example opens a resumable session with four X-Goog-Upload declarations. Google returns a session URL in a response header. The client then sends bytes in a second request with an offset plus upload, finalize. That is a small state machine spread across two authenticated HTTP exchanges. A gateway should bind both exchanges to one approved upload intent before any resulting File URI reaches inference.

I want the headers evaluated as a set. Checking only the API key or final byte count leaves the protocol transition under caller control.

TL;DR

  • Bind the start protocol and command to an approved upload intent. Match its expected length and media type.
  • Treat the returned upload URL as a scoped session capability and keep it out of general logs.
  • Enforce offset and command sequencing on the byte request. Reconcile the final File metadata afterward.
  • Keep file authorization and safe parsing with the application. Record gateway policy separately from provider results.

Resumable upload is a two-request state machine

Google's Files API guide shows the REST sequence. The initial request targets the Gemini upload endpoint and sets X-Goog-Upload-Protocol: resumable with X-Goog-Upload-Command: start. It also declares the byte length through X-Goog-Upload-Header-Content-Length and the media type through X-Goog-Upload-Header-Content-Type. The request body carries File metadata such as a display name.

The response supplies an x-goog-upload-url header. The example then sends the actual bytes to that URL with Content-Length, X-Goog-Upload-Offset: 0, and X-Goog-Upload-Command: upload, finalize. The returned JSON contains the File resource and its URI.

Model the exchange explicitly as intent approved, session started, bytes dispatched, and file finalized. Store provider results between transitions. A request that skips a state or changes its approved attributes should enter a named hold outcome. Reusing a completed session should produce the same result.

This operating model is an application and gateway pattern derived from Google's documented sequence. Google defines the protocol behavior. Your route defines who may start it and which declarations are acceptable.

The start request needs an approved intent

Create an upload intent before the start request. It should identify the authenticated principal or agent, tenant, target Gemini project, and provider credential profile. Record the route, expected media family, exact byte length, and protected content digest. Add the display-name policy and data class. Record the policy version as its own field. Give the intent a short application lifetime and single-use state.

The gateway compares the final serialized start request with that record. Require the resumable protocol and start command exactly as supported by the integration. Parse the declared content length as a bounded non-negative integer, then compare it with the approved length. Parse the upload media type under a strict media-type grammar and compare it with the type approved by application-side byte inspection.

Inspect the JSON metadata body as well. Enforce a display-name length policy and reject fields outside the route schema. The provider's File resource reference says displayName is optional and limited to 512 characters. A display name is useful to operators, but it should never select authorization or storage policy.

My blunt opinion is that letting generic client code choose X-Goog-Upload-Command turns a documented protocol into an unowned production API. One route adapter should own those values.

The returned upload URL needs capability handling

The session URL comes from a provider response header and controls the next upload step. Capture it only after the start response passes status, header-count, size, and syntax checks. Associate it with the upload intent and authenticated principal. Preserve the provider context and creation time in the same record. General application logs should receive a protected digest rather than the raw value.

Allow the byte request to use only the exact session URL issued for its active intent. Reject caller-supplied alternatives and cross-tenant substitutions. Restrict redirects according to the integration contract so the upload body cannot move to an unapproved destination under a permissive HTTP client.

A compact operations panel should look like two paper cards clipped together. The first shows the start command and declared length. Put the media type beneath them. The second shows the session digest, offset, byte request length, and finalize command. Draw a red line between mismatched values. That picture exposes a changed length faster than a page of request headers.

Keep raw session URLs in a narrowly accessible store with short retention. If incident response needs correlation, the digest and intent ID should connect gateway evidence with the protected operational record.

Byte dispatch must match the active session

For the single-shot sequence in Google's example, require offset zero and the combined upload, finalize command. Compare Content-Length with the approved intent and the start declaration before forwarding any body bytes. Stream through a hard byte ceiling so a misleading length header cannot create an unbounded transfer.

Compute a digest while the bytes pass if the route architecture supports it. Compare that digest with the application's approved value at the end of the stream. A mismatch should fail the application workflow and quarantine the resulting provider object if one was created. The gateway must avoid presenting a finalized File as approved merely because Google accepted the transport.

Handle disconnects as explicit attempts. A retry should use protocol behavior supported by the provider and a route policy written for that mode. The documented single-request example gives no basis for inventing arbitrary offsets. If your client adds multi-chunk behavior, test its status queries and offset reconciliation against the provider protocol. Test finalization separately before permitting that behavior in production.

The HTTP request smuggling controls are relevant at this boundary because upload requests combine several length declarations across HTTP and provider-specific headers. The gateway should reject conflicting transfer framing before it evaluates Gemini semantics.

Final File metadata closes the upload decision

A successful byte request returns File information. Reconcile it with the upload intent before making the URI available to model code. Compare provider sizeBytes and mimeType with the approved record where those fields are present. Compare sha256Hash in a separate check. Store the immutable File name, output-only URI, creation time, expiration time, and processing state.

Google defines PROCESSING as unavailable for inference. It defines ACTIVE as processed and available. FAILED is a processing failure. Finalized transport therefore needs a second release gate for provider processing state. Poll through a bounded application workflow or defer the model request until current metadata reports ACTIVE.

The Gemini file MIME type validation guide covers the type comparison that follows upload. URI scope policy should also bind the File resource to the project, credential context, principal, and tenant that created it. A finalized object has passed provider transport. Application authorization and route admission still decide if it may enter inference.

Record both outcomes. provider_upload_finalized describes the remote result. application_file_released describes the local decision. Keeping them apart prevents a transport success from becoming a silent security approval.

Failure outcomes need protocol precision

Give each broken transition a stable reason. Useful examples include protocol_mismatch and start_command_invalid. Length or type changes map to intent_length_mismatch or media_type_mismatch. Session and offset checks have their own outcomes: session_unregistered or offset_invalid. Finalization and digest checks use finalize_missing or content_digest_mismatch. Provider status and returned error details belong beside the local reason.

Destructive fixtures should alter one header at a time. Remove the resumable protocol declaration. Change start to an unknown command. Declare one byte count at session creation and send another on the body request. Substitute a different MIME type, reuse a finalized session URL, change offset zero, omit finalize, and add conflicting HTTP transfer framing.

Add response fixtures for a missing upload URL, duplicate upload URL headers, an oversized header value, a redirect to an unapproved origin, malformed File JSON, and a returned File whose size conflicts with the intent. Then exercise PROCESSING and ACTIVE. Exercise FAILED plus an unknown state value before inference.

The AI audit log schema can hold the principal, route, policy version, request digest, and disposition. Extend it with intent ID and a digest of the start request. Add normalized header findings and a protected session reference. Record the attempt number and enforced offset. Preserve the streamed byte count, content-digest result, File name, provider state, and final release decision.

Header gates need bounded resource use

Upload routes process large bodies, so policy must run before buffering. Evaluate identity and intent state at the headers. Check the destination, commands, and declared lengths before accepting the body. Reject oversize values before accepting the body. Stream permitted bytes through a fixed ceiling and stop forwarding when the count exceeds the intent.

Google's file input methods guide distinguishes inline data and Files API uploads, including different size and lifetime characteristics. Route the two methods separately. An inline base64 payload needs decoded-size limits and has no resumable session. A Files API upload needs session-state checks and a later File-resource release decision.

Rate limits also belong to the application and edge policy. Limit active intents per principal and concurrent upload sessions. Set limits for aggregate bytes per tenant and failed starts within a review window. Those are local abuse controls rather than properties promised by the Files API documentation.

Keep the upload path narrow. It should create Gemini File resources for an approved inference workflow, not serve as a general-purpose forwarding endpoint for arbitrary destinations or HTTP bodies.

DeepInspect

DeepInspect can inspect authenticated user or agent HTTP traffic deliberately routed through its proxy to Gemini upload endpoints and later model requests. It can bind resumable headers to an approved intent and restrict session URL use. It can enforce length and offset policy, hold malformed transitions, and record a signed decision before forwarding traffic.

The application owns file authorization, byte inspection, content digest approval, and malware analysis. It also owns upload-intent state, retry design, and File release into a business workflow. Google owns resumable-session behavior and provider File metadata. It also owns processing state and model handling. Direct uploads, local filesystem activity, STDIO traffic, and calls that bypass the proxy remain outside DeepInspect's enforcement and evidence.

Book a technical deep dive at deepinspect.ai.

Frequently asked questions

Which headers belong on the Gemini start request?

Google's REST example uses the resumable protocol header and the start command. It also uses an expected content-length header and an expected content-type header. It sends JSON metadata in the request body. Validate those values together against the approved upload intent.

How should the upload URL be stored?

Treat it as a scoped operational capability. Bind it to the intent and principal. Restrict access to the raw value and put a protected digest in ordinary audit records. Accept byte uploads only through the exact active session record.

Should Content-Length match the start declaration?

A controlled route should require the body request length and streamed byte count to agree. Both should match the approved intent length. Stop the stream at the hard ceiling and produce a specific mismatch outcome instead of relying on a later provider error.

Is finalize enough to make the File ready for inference?

Finalization closes the byte upload. The File resource can still report PROCESSING, which Google describes as unavailable for inference. Release the reference only after current metadata satisfies the route. That requires an ACTIVE state and matching file properties.

Who owns malware scanning and safe file parsing?

The application owns byte inspection and malware analysis. It also owns archive controls and safe parsing, along with data classification and business authorization. The gateway can enforce the authenticated HTTP upload contract and preserve evidence. Google owns provider-side upload processing after receipt.