{"record":{"id":"32da0df9cd6a3b9b","repo":"can1357/oh-my-pi","slug":"gemini-files-api-upload-initialization-request-fai","errorCode":null,"errorMessage":"Gemini Files API upload initialization request failed","messagePattern":"Gemini Files API upload initialization request failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/blob-broker/provider-files-gemini.ts","lineNumber":109,"sourceCode":"\t\tasync upload(request: ProviderFileUploadRequest): Promise<ProviderFileHandle> {\n\t\t\tconst byteLength = request.bytes.byteLength;\n\t\t\tlet startResponse: Response;\n\t\t\ttry {\n\t\t\t\tstartResponse = await fetchImpl(GEMINI_FILES_UPLOAD_URL, {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t\t\"X-Goog-Upload-Command\": \"start\",\n\t\t\t\t\t\t\"X-Goog-Upload-Header-Content-Length\": String(byteLength),\n\t\t\t\t\t\t\"X-Goog-Upload-Header-Content-Type\": request.mimeType,\n\t\t\t\t\t\t\"X-Goog-Upload-Protocol\": \"resumable\",\n\t\t\t\t\t\t\"x-goog-api-key\": credential,\n\t\t\t\t\t},\n\t\t\t\t\tbody: JSON.stringify(request.filename ? { file: { display_name: request.filename } } : { file: {} }),\n\t\t\t\t\tsignal: request.signal,\n\t\t\t\t});\n\t\t\t} catch {\n\t\t\t\tthrow new Error(\"Gemini Files API upload initialization request failed\");\n\t\t\t}\n\t\t\tif (!startResponse.ok) {\n\t\t\t\tthrow new Error(`Gemini Files API upload initialization failed with HTTP ${startResponse.status}`);\n\t\t\t}\n\n\t\t\tconst uploadUrl = startResponse.headers.get(\"X-Goog-Upload-URL\")?.trim();\n\t\t\tif (!uploadUrl)\n\t\t\t\tthrow new Error(\"Gemini Files API upload initialization response is missing X-Goog-Upload-URL\");\n\n\t\t\tlet finalizeResponse: Response;\n\t\t\ttry {\n\t\t\t\tfinalizeResponse = await fetchImpl(uploadUrl, {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"Content-Length\": String(byteLength),\n\t\t\t\t\t\t\"X-Goog-Upload-Command\": \"upload, finalize\",\n\t\t\t\t\t\t\"X-Goog-Upload-Offset\": \"0\",\n\t\t\t\t\t},","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/blob-broker/provider-files-gemini.ts#L91-L127","documentation":"The initial 'start' resumable-upload POST to https://generativelanguage.googleapis.com/upload/v1beta/files threw (network-level failure), so the client discards the original cause and throws this generic message. This is a fetch-level failure — DNS, TLS, connection refused/reset, abort via request.signal — not an HTTP error status (that produces a different message).","triggerScenarios":"fetchImpl() on the upload start request rejects: offline machine, DNS failure, TLS interception, connection reset, or request.signal aborted (AbortError).","commonSituations":"No internet / DNS misconfiguration; corporate proxy blocking generativelanguage.googleapis.com; firewall egress rules; request aborted by user cancel or timeout; IPv6 connectivity issues.","solutions":["Verify network connectivity to generativelanguage.googleapis.com (curl -v https://generativelanguage.googleapis.com).","Check whether the upload was cancelled — the request.signal you passed may have aborted (AbortError).","Check proxy/VPN/firewall settings; set HTTPS_PROXY if your network requires it.","Retry with backoff — transient connection resets are common for large uploads.","Note the original cause is swallowed; add a debug FetchImpl wrapper if you need the underlying error."],"exampleFix":"// before: no diagnostics\nawait client.upload({ bytes, mimeType, signal });\n// after: catch and retry with backoff on transient failures\ntry {\n  return await client.upload({ bytes, mimeType, signal });\n} catch (e) {\n  if (String(e.message).includes(\"initialization request failed\")) return retryWithBackoff(upload);\n  throw e;\n}","handlingStrategy":"retry","validationCode":"const reachable = await $`curl -sS -o /dev/null -w '%{http_code}' https://generativelanguage.googleapis.com/v1beta`.quiet().nothrow();\nif (!reachable || reachable.text() === \"000\") throw new Error(\"No network path to Gemini API\");","typeGuard":"null","tryCatchPattern":"try {\n  const handle = await client.upload(request);\n} catch (error) {\n  if (error instanceof Error && error.message.includes(\"initialization request failed\")) {\n    if (request.signal?.aborted) throw error; // cancelled by caller, do not retry\n    return uploadWithBackoff(request);\n  } else throw error;\n}","preventionTips":["Configure HTTPS_PROXY for corporate networks before starting uploads","Always pass an AbortSignal and distinguish abort from network failure before retrying","Add exponential backoff with jitter for connection-level failures","Monitor egress/DNS health in the deployment environment"],"tags":["network","upload","connection"],"backgroundTag":"network-request-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}