can1357/oh-my-pi · error

OpenAI Files API reported that the upload failed

Error message

OpenAI Files API reported that the upload failed

What it means

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.

Source

Thrown at packages/coding-agent/src/blob-broker/provider-files-openai.ts:111

					headers: { Authorization: authorization },
					body: form,
					signal: uploadRequest.signal,
				});
			} catch {
				throw new Error("OpenAI Files API upload request failed");
			}
			if (!response.ok) {
				throw new Error(`OpenAI Files API upload failed with HTTP ${response.status}`);
			}

			let payload: unknown;
			try {
				payload = await response.json();
			} catch {
				throw new Error("OpenAI Files API returned an invalid upload response");
			}
			const file = parseOpenAIFileResponse(payload);
			if (file.status === "error") throw new Error("OpenAI Files API reported that the upload failed");

			const deleteUrl = `${OPENAI_FILES_URL}/${encodeURIComponent(file.id)}`;
			return {
				provider: "openai",
				id: file.id,
				mimeType: uploadRequest.mimeType,
				bytes: file.bytes,
				delete: {
					method: "DELETE",
					url: deleteUrl,
					headers: { Authorization: authorization },
				},
			};
		},
		async delete(handle: ProviderFileHandle): Promise<void> {
			if (handle.provider !== "openai" || typeof handle.id !== "string" || handle.id.trim().length === 0) {
				throw new Error("Cannot delete an invalid OpenAI file handle");
			}

View on GitHub (pinned to 9690622007)

Solutions

  1. Verify the image bytes are valid and decodable before upload (e.g. decode with an image library or check magic bytes)
  2. Ensure uploadRequest.mimeType matches the actual content type of the bytes
  3. Re-encode the image (e.g. to PNG/JPEG) and retry; corrupted source files are the usual cause
  4. If the file looks valid, retry once — transient processing errors do occur — then check status.openai.com

Example fix

// before: blind upload of raw bytes
await client.upload({ bytes, mimeType: "image/png", filename, signal });
// after: validate image decodes before spending the upload
const image = await decodeImage(bytes); // throws on corrupt/truncated data
await client.upload({ bytes: reEncode(image, "image/png"), mimeType: "image/png", filename, signal });
Defensive patterns

Strategy: validation

Validate before calling

// verify the bytes decode as an image before upload
const blob = new Blob([bytes], { type: mimeType });
const bmp = await createImageBitmap(blob).catch(() => null);
if (!bmp) throw new Error("refusing upload: bytes are not a decodable image");

Try / catch

try {
  await client.upload(req);
} catch (err) {
  if (String(err.message).includes("reported that the upload failed")) {
    // re-encode or regenerate the asset once, then retry
    return client.upload({ ...req, bytes: await reEncodeImage(req.bytes) });
  }
  throw err;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/5674ddcce7bee319. Report an issue: GitHub.