spring-projects/spring-ai · error · java.lang.IllegalArgumentException
Unsupported image format:
Error message
Unsupported image format:
What it means
BedrockMediaFormat.getImageFormat() looks up the spring MimeMimeType in IMAGE_MAP, which maps MimeTypes to Bedrock Converse ImageFormat values. When the mime type has no entry, an IllegalArgumentException is thrown meaning Bedrock Converse does not support this image format. Only Bedrock-supported formats are mapped.
Source
Thrown at models/spring-ai-bedrock-converse/src/main/java/org/springframework/ai/bedrock/converse/api/BedrockMediaFormat.java:120
return DOCUMENT_MAP.containsKey(mimeType);
}
public static DocumentFormat getDocumentFormat(MimeType mimeType) {
DocumentFormat format = DOCUMENT_MAP.get(mimeType);
if (format == null) {
throw new IllegalArgumentException("Unsupported document format: " + mimeType);
}
return format;
}
public static Boolean isSupportedImageFormat(MimeType mimeType) {
return IMAGE_MAP.containsKey(mimeType);
}
public static ImageFormat getImageFormat(MimeType mimeType) {
ImageFormat format = IMAGE_MAP.get(mimeType);
if (format == null) {
throw new IllegalArgumentException("Unsupported image format: " + mimeType);
}
return format;
}
public static Boolean isSupportedVideoFormat(MimeType mimeType) {
return VIDEO_MAP.containsKey(mimeType);
}
public static VideoFormat getVideoFormat(MimeType mimeType) {
VideoFormat format = VIDEO_MAP.get(mimeType);
if (format == null) {
throw new IllegalArgumentException("Unsupported video format: " + mimeType);
}
return format;
}
}
View on GitHub (pinned to 98a7beda4f)
Solutions
- Convert the media to a Bedrock-supported format (png, jpeg, gif, webp) and set its MimeType accordingly.
- Check IMAGE_MAP for supported types before sending (use isSupportedImageFormat).
- Verify the Media object's mimeType field is populated, not null or empty.
- Switch model or API if the unsupported format is required.
Example fix
// before
new Media(MimeTypeUtils.parseMimeType("image/tiff"), tiffResource);
// after
new Media(MimeTypeUtils.parseMimeType("image/png"), pngResource); Defensive patterns
Strategy: validation
Validate before calling
if (!BedrockMediaFormat.isSupportedImageFormat(media.getMimeType())) {
throw new IllegalArgumentException("Image format not supported by Bedrock: " + media.getMimeType());
} Type guard
boolean isSupportedImage(MimeType mt) {
return mt != null && BedrockMediaFormat.isSupportedImageFormat(mt);
} Try / catch
try {
String fmt = BedrockMediaFormat.getFormatAsString(media);
} catch (IllegalArgumentException e) {
// log and skip or convert media to a supported format
} Prevention
- Always set an explicit supported MimeType on Media objects
- Call isSupportedImageFormat before building prompts
- Convert non-supported images to png/jpeg upstream
When it happens
Trigger: Calling getFormatAsString/getImageFormat with an image MimeType not in IMAGE_MAP, e.g. image/tiff, image/bmp, image/webp, or a null/blank mediaType on a Media object passed into a Bedrock Converse ChatModel prompt.
Common situations: Passing a Media with a filename-derived mime type that Bedrock rejects; users assuming all common image types are supported; Media built without an explicit mime type.
Related errors
- Unsupported video format:
- Unsupported media format:
- Unsupported media format:
- Unsupported document format:
- SSE connection '<connectionName>' requires a 'url' property.
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/e9ae15aefefd9d2c.
Report an issue: GitHub.