spring-projects/spring-ai · error · IllegalArgumentException
Unsupported media type:
Error message
Unsupported media type:
What it means
If a Media attached to the document is neither an accepted image, nor video, nor text mime type, the model throws IllegalArgumentException. This is the final else branch of the media dispatch in doSingleDocumentPrediction and indicates input content the Vertex AI multimodal embedding API cannot embed.
Source
Thrown at models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/multimodal/VertexAiMultimodalEmbeddingModel.java:211
logger.warn("Unsupported image mime type: " + media.getMimeType());
throw new IllegalArgumentException("Unsupported image mime type: " + media.getMimeType());
}
}
else if (media.getMimeType().isCompatibleWith(VIDEO_MIME_TYPE)) {
instanceBuilder.video(VideoBuilder.of(media.getMimeType())
.videoData(media.getData())
.startOffsetSec(mergedOptions.getVideoStartOffsetSec())
.endOffsetSec(mergedOptions.getVideoEndOffsetSec())
.intervalSec(mergedOptions.getVideoIntervalSec())
.build());
documentMetadata.put(ModalityType.VIDEO,
new DocumentMetadata(document.getId(), media.getMimeType(), media.getData()));
}
else {
if (logger.isWarnEnabled()) {
logger.warn("Unsupported media type: " + media.getMimeType());
}
throw new IllegalArgumentException("Unsupported media type: " + media.getMimeType());
}
}
List<Value> instances = List.of(VertexAiEmbeddingUtils.valueOf(instanceBuilder.build()));
PredictRequest.Builder predictRequestBuilder = PredictRequest.newBuilder()
.setEndpoint(endpointName.toString())
.setParameters(VertexAiEmbeddingUtils.jsonToValue(jsonHelper.toJson(Map.of())))
.addAllInstances(instances);
PredictResponse embeddingResponse = client.predict(predictRequestBuilder.build());
int index = 0;
List<Embedding> embeddingList = new ArrayList<>();
for (Value prediction : embeddingResponse.getPredictionsList()) {
if (prediction.getStructValue().containsFields("textEmbedding")) {
Value textEmbedding = prediction.getStructValue().getFieldsOrThrow("textEmbedding");
float[] textVector = VertexAiEmbeddingUtils.toVector(textEmbedding);View on GitHub (pinned to 98a7beda4f)
Solutions
- Remove or replace the unsupported media with image, video, or text content
- Use the correct Spring AI model for other content (e.g. a text embedding model for text-only docs)
- Explicitly set the MimeType so it matches one of the supported types
- Pre-validate Media mime types in your ingestion pipeline and skip/log unsupported items
Example fix
// before
doc.getMedia().add(new Media(MimeTypeUtils.parseMimeType("audio/mpeg"), audioBytes)); // throws
// after
Media media = new Media(MimeTypeUtils.parseMimeType("audio/mpeg"), audioBytes);
if (!isSupportedMime(media.getMimeType())) { log.warn("skipping unsupported media"); return; } Defensive patterns
Strategy: validation
Validate before calling
boolean embeddable = doc.getMedia().stream().allMatch(m -> m.getMimeType().getType().equals("image") || m.getMimeType().getType().equals("video") || m.getMimeType().getType().equals("text")); Type guard
static boolean isEmbeddableMedia(MimeType mt) { return List.of("image","video","text").contains(mt.getType()); } Try / catch
try { response = model.call(request); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Unsupported media type")) { /* split or drop the doc */ } throw e; } Prevention
- Filter media by modality before building documents
- Route audio/other content to dedicated models
- Set explicit, correct MimeType values in your pipeline
When it happens
Trigger: Building a Document whose Media MimeType is incompatible with IMAGE_MIME_TYPE, VIDEO_MIME_TYPE and TEXT_MIME_TYPE (e.g. audio/audio-mpeg, application/pdf-as-binary when not routed to document handling, application/zip) and calling the model.
Common situations: Trying to embed audio clips with the multimodal embedding model; passing arbitrary binary files with application/octet-stream; forgetting that the API supports only image/video/text modalities.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Unsupported image mime type:
- model cannot be null or empty
- java.io.IOException
- Title is only valid with task_type=RETRIEVAL_DOCUMENT
- Method must have exactly 1 parameter (List<McpSchema.Resourc
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/c5f34477714a5ea8.
Report an issue: GitHub.