{"record":{"id":"bc2186cb01a15718","repo":"vercel/ai","slug":"unsupported-image-mime-type-mimetype-expected","errorCode":null,"errorMessage":"Unsupported image mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_IMAGE_MIME_TYPES).join(', ')}","messagePattern":"Unsupported image mime type: (.+?), expected one of: (.+?)","errorType":"exception","errorClass":"UnsupportedFunctionalityError","httpStatus":null,"severity":"error","filePath":"packages/amazon-bedrock/src/convert-to-amazon-bedrock-chat-messages.ts","lineNumber":657,"sourceCode":"  }\n\n  return { system, messages };\n}\n\n// wrap invalid tool call input because Bedrock requires it to be an object\nfunction toBedrockToolInput(input: unknown): JSONObject {\n  return typeof input === 'object' && input !== null && !Array.isArray(input)\n    ? (input as JSONObject)\n    : { rawInvalidInput: input as JSONValue };\n}\n\nfunction getAmazonBedrockImageFormat(\n  mimeType: string,\n): AmazonBedrockImageFormat {\n  const format =\n    BEDROCK_IMAGE_MIME_TYPES[mimeType as AmazonBedrockImageMimeType];\n  if (!format) {\n    throw new UnsupportedFunctionalityError({\n      functionality: `image mime type: ${mimeType}`,\n      message: `Unsupported image mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_IMAGE_MIME_TYPES).join(', ')}`,\n    });\n  }\n\n  return format;\n}\n\nfunction getAmazonBedrockDocumentFormat(\n  mimeType: string,\n): AmazonBedrockDocumentFormat {\n  const format =\n    BEDROCK_DOCUMENT_MIME_TYPES[mimeType as AmazonBedrockDocumentMimeType];\n  if (!format) {\n    throw new UnsupportedFunctionalityError({\n      functionality: `file mime type: ${mimeType}`,\n      message: `Unsupported file mime type: ${mimeType}, expected one of: ${Object.keys(BEDROCK_DOCUMENT_MIME_TYPES).join(', ')}`,\n    });","sourceCodeStart":639,"sourceCodeEnd":675,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/amazon-bedrock/src/convert-to-amazon-bedrock-chat-messages.ts#L639-L675","documentation":"getAmazonBedrockImageFormat maps an image MIME type to a Bedrock image format and throws UnsupportedFunctionalityError when the MIME type is absent from BEDROCK_IMAGE_MIME_TYPES. Bedrock only accepts jpeg, png, gif, and webp images, and requires the format field to match the payload.","triggerScenarios":"Passing an image part with a mediaType outside {image/jpeg, image/png, image/gif, image/webp} — e.g. image/svg+xml, image/tiff, image/heic, or an empty/missing media type.","commonSituations":"Sending screenshots in HEIC from iOS, SVGs generated by tools, or TIFF scans; also occurs when mediaType is omitted so it defaults to something Bedrock cannot map.","solutions":["Convert the image to PNG or JPEG before sending (sharp/canvas on server, browser canvas API on client).","Set an explicit supported mediaType on the image part instead of relying on inference.","Check the error message's 'expected one of' list and match one of those MIME types.","For SVG, rasterize it to PNG first — Bedrock cannot ingest vector images."],"exampleFix":"// before\n{ type: 'image', mediaType: 'image/svg+xml', data: svgBytes }\n// after\nconst png = await sharp(svgBytes).png().toBuffer();\n{ type: 'image', mediaType: 'image/png', data: png }","handlingStrategy":"validation","validationCode":"const SUPPORTED_IMAGE = ['image/jpeg','image/png','image/gif','image/webp'];\nif (!SUPPORTED_IMAGE.includes(imagePart.mediaType)) {\n  imagePart = { ...imagePart, mediaType: 'image/png', data: await convertToPng(imagePart.data) };\n}","typeGuard":"function isBedrockSupportedImage(mediaType) {\n  return ['image/jpeg','image/png','image/gif','image/webp'].includes(mediaType);\n}","tryCatchPattern":"try {\n  return await generateText({ model, messages });\n} catch (error) {\n  if (UnsupportedFunctionalityError.isInstance(error) && error.message.includes('Unsupported image mime type')) {\n    // convert images to PNG and retry once\n    messages = await convertAllImagesToPng(messages);\n    return generateText({ model, messages });\n  }\n  throw error;\n}","preventionTips":["Normalize all user-uploaded images to PNG or JPEG at ingest time.","Always set mediaType explicitly on image parts instead of relying on inference.","Reject HEIC/SVG/TIFF uploads early in your API with a clear client-side message."],"tags":["unsupported-functionality","bedrock","image","mime-type"],"backgroundTag":"unsupported-media-type","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}