spring-projects/spring-ai · error · java.lang.IllegalArgumentException
Unsupported media format:
Error message
Unsupported media format:
What it means
BedrockMediaFormat.getFormatAsString maps a MimeType to its Bedrock string form. If the type is neither a supported document, image, nor video format, this IllegalArgumentException is thrown. Bedrock's Converse API accepts only a fixed set of media MIME types.
Source
Thrown at models/spring-ai-bedrock-converse/src/main/java/org/springframework/ai/bedrock/converse/api/BedrockMediaFormat.java:98
Media.Format.VIDEO_MP4, VideoFormat.MP4,
Media.Format.VIDEO_WEBM, VideoFormat.WEBM,
Media.Format.VIDEO_FLV, VideoFormat.FLV,
Media.Format.VIDEO_MPEG, VideoFormat.MPEG,
Media.Format.VIDEO_WMV, VideoFormat.WMV,
Media.Format.VIDEO_THREE_GP, VideoFormat.THREE_GP);
// @formatter:on
public static String getFormatAsString(MimeType mimeType) {
if (isSupportedDocumentFormat(mimeType)) {
return getDocumentFormat(mimeType).toString();
}
else if (isSupportedImageFormat(mimeType)) {
return getImageFormat(mimeType).toString();
}
else if (isSupportedVideoFormat(mimeType)) {
return getVideoFormat(mimeType).toString();
}
throw new IllegalArgumentException("Unsupported media format: " + mimeType);
}
public static Boolean isSupportedDocumentFormat(MimeType mimeType) {
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);
}
View on GitHub (pinned to 98a7beda4f)
Solutions
- Check BedrockMediaFormat.isSupportedDocumentFormat/isSupportedImageFormat/isSupportedVideoFormat first and handle unsupported types yourself.
- Convert the media to a supported format before sending.
- Fix MIME typos: use image/jpeg, not image/jpg.
- Upgrade the Spring AI version if the format you need was added in a newer BedrockMediaFormat map.
Example fix
// before
String fmt = BedrockMediaFormat.getFormatAsString(media.getMimeType());
// after
if (!BedrockMediaFormat.isSupportedImageFormat(media.getMimeType())) {
throw new IllegalArgumentException("Convert media: " + media.getMimeType());
}
String fmt = BedrockMediaFormat.getFormatAsString(media.getMimeType()); Defensive patterns
Strategy: validation
Validate before calling
MimeType mt = media.getMimeType();
if (!(Boolean.TRUE.equals(BedrockMediaFormat.isSupportedImageFormat(mt))
|| Boolean.TRUE.equals(BedrockMediaFormat.isSupportedVideoFormat(mt))
|| Boolean.TRUE.equals(BedrockMediaFormat.isSupportedDocumentFormat(mt)))) {
throw new IllegalArgumentException("MIME type not supported by Bedrock: " + mt);
} Type guard
boolean hasStringFormat(MimeType mt) {
try { BedrockMediaFormat.getFormatAsString(mt); return true; }
catch (IllegalArgumentException e) { return false; }
} Try / catch
try {
fmt = BedrockMediaFormat.getFormatAsString(mt);
} catch (IllegalArgumentException e) {
fmt = null; // handle unsupported type upstream
} Prevention
- Check the three isSupported*Format helpers before calling getFormatAsString
- Use exact MIME constants (MimeTypeUtils) instead of hand-written strings
- Convert exotic formats to supported ones at ingestion time
- Pin library versions and re-check maps after upgrades
When it happens
Trigger: Calling getFormatAsString with an unsupported MimeType, e.g. image/svg+xml, audio/mpeg, application/zip, or misspelled types like image/jpg.
Common situations: Rendering the media type name for prompts or config; passing audio to a chat model; using newer formats (webp/avif) not in the library's supported map; typos in MIME strings.
Related errors
- Unsupported media format:
- Unsupported document format:
- Invalid video content type:
- Invalid Image content type:
- Unsupported image format:
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/7d3fc3df5d8db2d6.
Report an issue: GitHub.