{"record":{"id":"5674ddcce7bee319","repo":"can1357/oh-my-pi","slug":"openai-files-api-reported-that-the-upload-failed","errorCode":null,"errorMessage":"OpenAI Files API reported that the upload failed","messagePattern":"OpenAI Files API reported that the upload failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/blob-broker/provider-files-openai.ts","lineNumber":111,"sourceCode":"\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,\n\t\t\t\tmimeType: uploadRequest.mimeType,\n\t\t\t\tbytes: file.bytes,\n\t\t\t\tdelete: {\n\t\t\t\t\tmethod: \"DELETE\",\n\t\t\t\t\turl: deleteUrl,\n\t\t\t\t\theaders: { Authorization: authorization },\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\tasync delete(handle: ProviderFileHandle): Promise<void> {\n\t\t\tif (handle.provider !== \"openai\" || typeof handle.id !== \"string\" || handle.id.trim().length === 0) {\n\t\t\t\tthrow new Error(\"Cannot delete an invalid OpenAI file handle\");\n\t\t\t}","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/blob-broker/provider-files-openai.ts#L93-L129","documentation":"Thrown when the Files API accepted the upload and returned a parseable file object whose status field is exactly \"error\" — OpenAI itself reports the file failed processing. The request and response were structurally fine; the upload was rejected server-side after acknowledgement.","triggerScenarios":"client.upload() parses a valid OpenAIFileResponse with file.status === \"error\". OpenAI marks a file errored when the content fails validation for the declared purpose (e.g. purpose=vision with a corrupt or unsupported image).","commonSituations":"Uploading a truncated or corrupted image; a zero-byte or misnamed file; a mime type that doesn't match actual bytes; provider-side processing limits.","solutions":["Verify the image bytes are valid and decodable before upload (e.g. decode with an image library or check magic bytes)","Ensure uploadRequest.mimeType matches the actual content type of the bytes","Re-encode the image (e.g. to PNG/JPEG) and retry; corrupted source files are the usual cause","If the file looks valid, retry once — transient processing errors do occur — then check status.openai.com"],"exampleFix":"// before: blind upload of raw bytes\nawait client.upload({ bytes, mimeType: \"image/png\", filename, signal });\n// after: validate image decodes before spending the upload\nconst image = await decodeImage(bytes); // throws on corrupt/truncated data\nawait client.upload({ bytes: reEncode(image, \"image/png\"), mimeType: \"image/png\", filename, signal });","handlingStrategy":"validation","validationCode":"// verify the bytes decode as an image before upload\nconst blob = new Blob([bytes], { type: mimeType });\nconst bmp = await createImageBitmap(blob).catch(() => null);\nif (!bmp) throw new Error(\"refusing upload: bytes are not a decodable image\");","typeGuard":null,"tryCatchPattern":"try {\n  await client.upload(req);\n} catch (err) {\n  if (String(err.message).includes(\"reported that the upload failed\")) {\n    // re-encode or regenerate the asset once, then retry\n    return client.upload({ ...req, bytes: await reEncodeImage(req.bytes) });\n  }\n  throw err;\n}","preventionTips":["Validate/decode images client-side before upload","Keep mimeType consistent with the actual byte content","Re-encode screenshots/generated assets to PNG/JPEG before sending","Retest with a known-good image to isolate content vs service issues"],"tags":["openai","upload","file-processing"],"backgroundTag":"upload-rejected","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}