{"record":{"id":"8d95d2b67915edb6","repo":"can1357/oh-my-pi","slug":"openai-files-api-upload-request-failed","errorCode":null,"errorMessage":"OpenAI Files API upload request failed","messagePattern":"OpenAI Files API upload request failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/blob-broker/provider-files-openai.ts","lineNumber":98,"sourceCode":"\t\tasync upload(uploadRequest: ProviderFileUploadRequest): Promise<ProviderFileHandle> {\n\t\t\tconst form = new FormData();\n\t\t\tform.append(\"purpose\", \"vision\");\n\t\t\tform.append(\n\t\t\t\t\"file\",\n\t\t\t\tnew Blob([uploadRequest.bytes], { type: uploadRequest.mimeType }),\n\t\t\t\tfileName(uploadRequest),\n\t\t\t);\n\n\t\t\tlet response: Response;\n\t\t\ttry {\n\t\t\t\tresponse = await request(OPENAI_FILES_URL, {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\theaders: { Authorization: authorization },\n\t\t\t\t\tbody: form,\n\t\t\t\t\tsignal: uploadRequest.signal,\n\t\t\t\t});\n\t\t\t} catch {\n\t\t\t\tthrow new Error(\"OpenAI Files API upload request failed\");\n\t\t\t}\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`OpenAI Files API upload failed with HTTP ${response.status}`);\n\t\t\t}\n\n\t\t\tlet payload: unknown;\n\t\t\ttry {\n\t\t\t\tpayload = await response.json();\n\t\t\t} catch {\n\t\t\t\tthrow new Error(\"OpenAI Files API returned an invalid upload response\");\n\t\t\t}\n\t\t\tconst file = parseOpenAIFileResponse(payload);\n\t\t\tif (file.status === \"error\") throw new Error(\"OpenAI Files API reported that the upload failed\");\n\n\t\t\tconst deleteUrl = `${OPENAI_FILES_URL}/${encodeURIComponent(file.id)}`;\n\t\t\treturn {\n\t\t\t\tprovider: \"openai\",\n\t\t\t\tid: file.id,","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/blob-broker/provider-files-openai.ts#L80-L116","documentation":"The OpenAI Files API client wraps the low-level fetch call for POST https://api.openai.com/v1/files and deliberately swallows the original error, rethrowing this generic message. It means the HTTP request itself never completed — a network-level failure (DNS, TLS, connection reset) or an AbortSignal-triggered abort — not an HTTP error status from OpenAI. The client discards the underlying cause, so you only see this opaque message.","triggerScenarios":"Calling client.upload() when the machine is offline, DNS for api.openai.com fails, TLS is intercepted/broken, a proxy rejects the connection, or the AbortSignal passed in uploadRequest.signal fires mid-request.","commonSituations":"Corporate proxy/firewall blocking api.openai.com; flaky Wi-Fi or VPN drops; request aborted because the user cancelled or a timeout fired; misconfigured HTTPS_PROXY; IPv6/DNS issues in containers.","solutions":["Check basic connectivity: curl -sS https://api.openai.com/v1/models -H \"Authorization: Bearer $OPENAI_API_KEY\" and verify it returns 200","Inspect the abort path: confirm nothing calls AbortController.abort() (timeout, user cancel) before the upload finishes","Check proxy env vars (HTTPS_PROXY/HTTPS_PROXY) are correct and reachable; OpenAI blocks some proxy IPs","Retry with exponential backoff — transient network resets are common on large uploads"],"exampleFix":"// before: opaque error hides the cause\n} catch {\n  throw new Error(\"OpenAI Files API upload request failed\");\n}\n// after (caller side): capture and surface the cause with retry\ntry {\n  await client.upload({ bytes, mimeType, filename, signal });\n} catch (err) {\n  if (signal.aborted) throw err;\n  logger.warn(\"openai file upload network failure; retrying\", { err });\n  await backoffRetry(() => client.upload({ bytes, mimeType, filename, signal }));\n}","handlingStrategy":"retry","validationCode":"// pre-flight connectivity probe\nconst ctrl = new AbortController();\nconst ok = await fetch(\"https://api.openai.com/v1/models\", {\n  headers: { Authorization: `Bearer ${key}` },\n  signal: ctrl.signal,\n}).then((r) => r.ok).catch(() => false);\nif (!ok) throw new Error(\"api.openai.com unreachable before upload\");","typeGuard":"function isAbortError(err: unknown): boolean {\n  return err instanceof Error && err.name === \"AbortError\";\n}","tryCatchPattern":"try {\n  await client.upload(req);\n} catch (err) {\n  if (isAbortError(err) || req.signal.aborted) throw err; // don't retry cancels\n  logger.warn(\"openai upload network failure\", { err });\n  await withBackoff(() => client.upload(req), { retries: 3 });\n}","preventionTips":["Probe api.openai.com reachability before large/batch uploads","Use AbortSignal.timeout() so hung requests fail fast and predictably","Retry idempotent uploads with exponential backoff","Check proxy env vars (HTTPS_PROXY) when running in corporate networks"],"tags":["network","fetch","openai","upload"],"backgroundTag":"network-request-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}