{"record":{"id":"c5f34477714a5ea8","repo":"spring-projects/spring-ai","slug":"unsupported-media-type","errorCode":null,"errorMessage":"Unsupported media type: ","messagePattern":"Unsupported media type: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/multimodal/VertexAiMultimodalEmbeddingModel.java","lineNumber":211,"sourceCode":"\t\t\t\t\tlogger.warn(\"Unsupported image mime type: \" + media.getMimeType());\n\t\t\t\t\tthrow new IllegalArgumentException(\"Unsupported image mime type: \" + media.getMimeType());\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (media.getMimeType().isCompatibleWith(VIDEO_MIME_TYPE)) {\n\t\t\t\tinstanceBuilder.video(VideoBuilder.of(media.getMimeType())\n\t\t\t\t\t.videoData(media.getData())\n\t\t\t\t\t.startOffsetSec(mergedOptions.getVideoStartOffsetSec())\n\t\t\t\t\t.endOffsetSec(mergedOptions.getVideoEndOffsetSec())\n\t\t\t\t\t.intervalSec(mergedOptions.getVideoIntervalSec())\n\t\t\t\t\t.build());\n\t\t\t\tdocumentMetadata.put(ModalityType.VIDEO,\n\t\t\t\t\t\tnew DocumentMetadata(document.getId(), media.getMimeType(), media.getData()));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (logger.isWarnEnabled()) {\n\t\t\t\t\tlogger.warn(\"Unsupported media type: \" + media.getMimeType());\n\t\t\t\t}\n\t\t\t\tthrow new IllegalArgumentException(\"Unsupported media type: \" + media.getMimeType());\n\t\t\t}\n\t\t}\n\n\t\tList<Value> instances = List.of(VertexAiEmbeddingUtils.valueOf(instanceBuilder.build()));\n\n\t\tPredictRequest.Builder predictRequestBuilder = PredictRequest.newBuilder()\n\t\t\t.setEndpoint(endpointName.toString())\n\t\t\t.setParameters(VertexAiEmbeddingUtils.jsonToValue(jsonHelper.toJson(Map.of())))\n\t\t\t.addAllInstances(instances);\n\n\t\tPredictResponse embeddingResponse = client.predict(predictRequestBuilder.build());\n\n\t\tint index = 0;\n\t\tList<Embedding> embeddingList = new ArrayList<>();\n\t\tfor (Value prediction : embeddingResponse.getPredictionsList()) {\n\t\t\tif (prediction.getStructValue().containsFields(\"textEmbedding\")) {\n\t\t\t\tValue textEmbedding = prediction.getStructValue().getFieldsOrThrow(\"textEmbedding\");\n\t\t\t\tfloat[] textVector = VertexAiEmbeddingUtils.toVector(textEmbedding);","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/multimodal/VertexAiMultimodalEmbeddingModel.java#L193-L229","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ndoc.getMedia().add(new Media(MimeTypeUtils.parseMimeType(\"audio/mpeg\"), audioBytes)); // throws\n// after\nMedia media = new Media(MimeTypeUtils.parseMimeType(\"audio/mpeg\"), audioBytes);\nif (!isSupportedMime(media.getMimeType())) { log.warn(\"skipping unsupported media\"); return; }","handlingStrategy":"validation","validationCode":"boolean embeddable = doc.getMedia().stream().allMatch(m -> m.getMimeType().getType().equals(\"image\") || m.getMimeType().getType().equals(\"video\") || m.getMimeType().getType().equals(\"text\"));","typeGuard":"static boolean isEmbeddableMedia(MimeType mt) { return List.of(\"image\",\"video\",\"text\").contains(mt.getType()); }","tryCatchPattern":"try { response = model.call(request); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Unsupported media type\")) { /* split or drop the doc */ } throw e; }","preventionTips":["Filter media by modality before building documents","Route audio/other content to dedicated models","Set explicit, correct MimeType values in your pipeline"],"tags":["java","google-vertex-ai","mime-type","unsupported-media"],"backgroundTag":"unsupported-operation","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}