can1357/oh-my-pi · error
Gemini Files API upload initialization request failed
Error message
Gemini Files API upload initialization request failed
What it means
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).
Source
Thrown at packages/coding-agent/src/blob-broker/provider-files-gemini.ts:109
async upload(request: ProviderFileUploadRequest): Promise<ProviderFileHandle> {
const byteLength = request.bytes.byteLength;
let startResponse: Response;
try {
startResponse = await fetchImpl(GEMINI_FILES_UPLOAD_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Goog-Upload-Command": "start",
"X-Goog-Upload-Header-Content-Length": String(byteLength),
"X-Goog-Upload-Header-Content-Type": request.mimeType,
"X-Goog-Upload-Protocol": "resumable",
"x-goog-api-key": credential,
},
body: JSON.stringify(request.filename ? { file: { display_name: request.filename } } : { file: {} }),
signal: request.signal,
});
} catch {
throw new Error("Gemini Files API upload initialization request failed");
}
if (!startResponse.ok) {
throw new Error(`Gemini Files API upload initialization failed with HTTP ${startResponse.status}`);
}
const uploadUrl = startResponse.headers.get("X-Goog-Upload-URL")?.trim();
if (!uploadUrl)
throw new Error("Gemini Files API upload initialization response is missing X-Goog-Upload-URL");
let finalizeResponse: Response;
try {
finalizeResponse = await fetchImpl(uploadUrl, {
method: "POST",
headers: {
"Content-Length": String(byteLength),
"X-Goog-Upload-Command": "upload, finalize",
"X-Goog-Upload-Offset": "0",
},View on GitHub (pinned to 9690622007)
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.
Example fix
// before: no diagnostics
await client.upload({ bytes, mimeType, signal });
// after: catch and retry with backoff on transient failures
try {
return await client.upload({ bytes, mimeType, signal });
} catch (e) {
if (String(e.message).includes("initialization request failed")) return retryWithBackoff(upload);
throw e;
} Defensive patterns
Strategy: retry
Validate before calling
const reachable = await $`curl -sS -o /dev/null -w '%{http_code}' https://generativelanguage.googleapis.com/v1beta`.quiet().nothrow();
if (!reachable || reachable.text() === "000") throw new Error("No network path to Gemini API"); Type guard
null
Try / catch
try {
const handle = await client.upload(request);
} catch (error) {
if (error instanceof Error && error.message.includes("initialization request failed")) {
if (request.signal?.aborted) throw error; // cancelled by caller, do not retry
return uploadWithBackoff(request);
} else throw error;
} Prevention
- 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
When it happens
Trigger: fetchImpl() on the upload start request rejects: offline machine, DNS failure, TLS interception, connection reset, or request.signal aborted (AbortError).
Common situations: No internet / DNS misconfiguration; corporate proxy blocking generativelanguage.googleapis.com; firewall egress rules; request aborted by user cancel or timeout; IPv6 connectivity issues.
Related errors
- Gemini Files API upload finalization request failed
- AnthropicConnectionError
- OpenAI Files API upload request failed
- ${destination} upload failed with HTTP ${status}
- the upload response did not contain a valid direct URL
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/32da0df9cd6a3b9b.
Report an issue: GitHub.