can1357/oh-my-pi · error · ValidationError

Unknown image type: ${mimeType}

Error message

Unknown image type: ${mimeType}

What it means

createImageBlock maps an image MIME type to one of the four formats Bedrock's Converse API accepts: jpeg, png, gif, webp. Any other MIME type hits the default branch and throws a ValidationError naming the offending type. Bedrock simply has no wire representation for other image formats, so the library fails fast client-side.

Source

Thrown at packages/ai/src/providers/amazon-bedrock.ts:1148

 */
function createImageBlock(mimeType: string, data: string): ImageBlockWire["image"] {
	let format: "jpeg" | "png" | "gif" | "webp";
	switch (mimeType) {
		case "image/jpeg":
		case "image/jpg":
			format = "jpeg";
			break;
		case "image/png":
			format = "png";
			break;
		case "image/gif":
			format = "gif";
			break;
		case "image/webp":
			format = "webp";
			break;
		default:
			throw new AIError.ValidationError(`Unknown image type: ${mimeType}`);
	}
	return { source: { bytes: data }, format };
}

View on GitHub (pinned to 9690622007)

Solutions

  1. Convert the image to PNG or JPEG before sending (e.g. with sharp: sharp(input).png().toBuffer())
  2. If the source is SVG or vector, rasterize it to PNG first — Bedrock cannot ingest vector formats
  3. Validate the MIME type at ingestion time (sniff magic bytes, not just the declared type) and reject/convert unsupported formats early
  4. For HEIC (iPhone photos), transcode to JPEG before adding the image block

Example fix

// before
blocks.push({ type: "image", mimeType: "image/heic", data: heicBase64 });
// after: convert first
const png = await sharp(Buffer.from(heicBase64, "base64")).png().toBuffer();
blocks.push({ type: "image", mimeType: "image/png", data: png.toString("base64") });
Defensive patterns

Strategy: validation

Validate before calling

const BEDROCK_IMAGE_TYPES = new Set(["image/jpeg", "image/jpg", "image/png", "image/gif", "image/webp"]);
function assertBedrockImage(block: ImageBlock): void {
  if (!BEDROCK_IMAGE_TYPES.has(block.mimeType)) {
    throw new Error(`Convert ${block.mimeType} to png/jpeg before sending to Bedrock`);
  }
}

Type guard

function isBedrockSupportedImage(mimeType: string): boolean {
  return /^image\/(jpeg|jpg|png|gif|webp)$/.test(mimeType);
}

Try / catch

try {
  await provider.stream(context);
} catch (err) {
  if (err instanceof AIError.ValidationError && err.message.startsWith("Unknown image type:")) {
    const mime = err.message.split(": ")[1];
    // convert via sharp and retry once
    return provider.stream(await convertImages(context, mime));
  }
  throw err;
}

Prevention

When it happens

Trigger: Passing an ImageBlock with a mimeType outside {image/jpeg, image/jpg, image/png, image/gif, image/webp} — e.g. image/svg+xml, image/tiff, image/avif, image/heic — to a Bedrock request.

Common situations: Feeding screenshots from tools that emit WebP variants is fine, but HEIC photos from iOS devices, SVG assets, or AVIF images from modern web pipelines are not; file-upload features trusting the client-declared Content-Type.

Related errors


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