{"record":{"id":"a55134dc9c94aec8","repo":"vercel/ai","slug":"google-batch-input-files-must-not-exceed-2-gb","errorCode":null,"errorMessage":"Google batch input files must not exceed 2 GB.","messagePattern":"Google batch input files must not exceed 2 GB\\.","errorType":"validation","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"packages/google/src/google-batch.ts","lineNumber":266,"sourceCode":"    if (fileParts == null) {\n      const { value } = await postJsonToApi({\n        url: createUrl,\n        headers,\n        body: inlineBatchBody,\n        failedResponseHandler: googleFailedResponseHandler,\n        successfulResponseHandler: createJsonResponseHandler(\n          googleBatchOperationSchema,\n        ),\n        abortSignal: options.abortSignal,\n        fetch: this.batchConfig.fetch,\n      });\n      operation = value;\n    } else {\n      const inputFile = new Blob(fileParts, { type: 'application/jsonl' });\n      // Blob snapshots the strings, so release the potentially large input array.\n      fileParts.length = 0;\n      if (inputFile.size > googleBatchInputFileMaxBytes) {\n        throw new InvalidArgumentError({\n          argument: 'requests',\n          message: 'Google batch input files must not exceed 2 GB.',\n        });\n      }\n\n      const { value: uploadUrl } = await postJsonToApi({\n        url: `${this.getBaseOrigin()}/upload/v1beta/files`,\n        headers: combineHeaders(headers, {\n          'X-Goog-Upload-Protocol': 'resumable',\n          'X-Goog-Upload-Command': 'start',\n          'X-Goog-Upload-Header-Content-Length': String(inputFile.size),\n          'X-Goog-Upload-Header-Content-Type': 'application/jsonl',\n        }),\n        body: {\n          file: {\n            display_name: `${displayName}-input`,\n          },\n        },","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/google/src/google-batch.ts#L248-L284","documentation":"Batch jobs upload requests as a single JSONL file to Google's Batch API, which caps input file size at 2 GB (googleBatchInputFileMaxBytes). experimental_doStartBatch checks the assembled Blob size before uploading and throws InvalidArgumentError if the file exceeds the limit, because Google would reject the upload anyway.","triggerScenarios":"Calling `model.experimental_doStartBatch({ requests })` (or the batch helper) with a request array whose serialized JSONL exceeds 2,147,483,648 bytes - typically very large prompts, inline file/image data, or simply too many requests.","commonSituations":"Batch-embedding large document corpora with inline attachments; long-running backfills of thousands of requests with big system prompts; accidentally embedding base64 media in batch requests.","solutions":["Split the requests into multiple batches, each under 2 GB, and start several batch jobs.","Remove or shrink inline data (use Cloud Storage URIs / file references instead of base64) to reduce JSONL size.","Trim prompts or move large static content out of per-request payloads (e.g. into context caching where supported)."],"exampleFix":"// before\nawait model.experimental_doStartBatch({ requests: allRequests }); // > 2GB\n// after\nfor (const chunk of chunks(allRequests, 10_000)) {\n  await model.experimental_doStartBatch({ requests: chunk });\n}","handlingStrategy":"validation","validationCode":"const MAX_BYTES = 2 * 1024 ** 3;\nfunction validateBatchSize(requests) {\n  const size = new Blob(requests.map(r => JSON.stringify(r) + '\\n')).size;\n  if (size > MAX_BYTES) throw new Error(`Batch payload ${size} bytes exceeds 2 GB; split into multiple batches.`);\n  return size;\n}","typeGuard":"null","tryCatchPattern":"try {\n  await model.experimental_doStartBatch({ requests });\n} catch (e) {\n  if (e?.name === 'AI_InvalidArgumentError' && /2 GB/.test(e.message ?? '')) {\n    // split requests into chunks and start multiple batch jobs\n  } else throw e;\n}","preventionTips":["Estimate serialized JSONL size before starting a batch and chunk accordingly.","Avoid inline base64 media in batch requests; use Cloud Storage URIs.","Monitor batch payload growth in CI with a size assertion on fixtures."],"tags":["google","batch","validation","limit"],"backgroundTag":"payload-size-limit-exceeded","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}