{"record":{"id":"7bede6f90ac29c02","repo":"spring-projects/spring-ai","slug":"unsupported-media-type-supported-types-are-ima","errorCode":null,"errorMessage":"Unsupported media type: . Supported types are: images (image/*) and PDF documents (application/pdf)","messagePattern":"Unsupported media type: \\. Supported types are: images \\(image/\\*\\) and PDF documents \\(application/pdf\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatModel.java","lineNumber":1369,"sourceCode":"\t/**\n\t * Converts a Spring AI {@link Media} object to an Anthropic SDK\n\t * {@link ContentBlockParam}. Supports images (PNG, JPEG, GIF, WebP) and PDF\n\t * documents. Data can be provided as byte[] (base64 encoded) or HTTPS URL string.\n\t * @param media the media object containing MIME type and data\n\t * @return the appropriate ContentBlockParam (ImageBlockParam or DocumentBlockParam)\n\t * @throws IllegalArgumentException if the media type is unsupported\n\t */\n\tprivate ContentBlockParam getContentBlockParamByMedia(Media media) {\n\t\tMimeType mimeType = media.getMimeType();\n\t\tString data = fromMediaData(media.getData());\n\n\t\tif (isImageMedia(mimeType)) {\n\t\t\treturn createImageBlockParam(mimeType, data);\n\t\t}\n\t\telse if (isPdfMedia(mimeType)) {\n\t\t\treturn createDocumentBlockParam(data);\n\t\t}\n\t\tthrow new IllegalArgumentException(\"Unsupported media type: \" + mimeType\n\t\t\t\t+ \". Supported types are: images (image/*) and PDF documents (application/pdf)\");\n\t}\n\n\t/**\n\t * Checks if the given MIME type represents an image.\n\t * @param mimeType the MIME type to check\n\t * @return true if the type is image/*\n\t */\n\tprivate boolean isImageMedia(MimeType mimeType) {\n\t\treturn \"image\".equals(mimeType.getType());\n\t}\n\n\t/**\n\t * Checks if the given MIME type represents a PDF document.\n\t * @param mimeType the MIME type to check\n\t * @return true if the type is application/pdf\n\t */\n\tprivate boolean isPdfMedia(MimeType mimeType) {","sourceCodeStart":1351,"sourceCodeEnd":1387,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatModel.java#L1351-L1387","documentation":"AnthropicChatModel.createMediaBlockParam only supports image/* media and PDF documents (application/pdf) when converting a Media entry in a UserMessage into Anthropic content blocks. Any other MIME type (video, audio, text, application/json, or an unknown/blank type) hits the final throw. The library throws IllegalArgumentException because the Anthropic Messages API simply has no content-block representation for that media.","triggerScenarios":"Passing a Media with a MIME type that is neither image/* nor application/pdf into a UserMessage, e.g. new Media(MimeTypeUtils.APPLICATION_OCTET_STREAM, bytes), MimeType.valueOf(\"audio/mpeg\"), or a Media whose MIME type was not detected (empty string) and therefore does not match isImageMedia/isPdfMedia.","commonSituations":"Developers attaching audio, video, zip or plain-text files to prompts assuming multimodal support; building Media from a downloaded Resource with generic application/octet-stream content type; upgrading Spring AI and forgetting that only images and PDFs are accepted by the Anthropic model.","solutions":["Change the Media MIME type to an image type (image/png, image/jpeg, image/gif, image/webp) or application/pdf.","If the file is another format, convert it (e.g. render a document page to PNG, or embed text directly in the prompt text instead of as Media).","Verify the MIME type is not empty/generic: pass an explicit MimeType rather than relying on detection of application/octet-stream.","If you need non-image/PDF media, switch to a model module that supports it (e.g. a different Spring AI model integration)."],"exampleFix":"// before\nvar media = new Media(MimeTypeUtils.APPLICATION_OCTET_STREAM, pdfBytes);\n// after\nvar media = new Media(MimeType.valueOf(\"application/pdf\"), pdfBytes);","handlingStrategy":"validation","validationCode":"MimeType type = media.getMimeType();\nboolean supported = (type.getType().equals(\"image\")) || type.toString().equals(\"application/pdf\");\nif (!supported) throw new IllegalArgumentException(\"Anthropic supports only image/* or application/pdf, got: \" + type);","typeGuard":null,"tryCatchPattern":"try {\n    client.call(new Prompt(new UserMessage(text, List.of(media))));\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Unsupported media type\")) {\n        log.error(\"Media {} not supported by Anthropic: {}\", media.getMimeType(), e.getMessage());\n    } else throw e;\n}","preventionTips":["Whitelist image/* and application/pdf at the point where Media objects are constructed.","Never rely on detected MIME types like application/octet-stream; set explicit types.","Convert text/other documents to prompt text or PDF before sending to Anthropic."],"tags":["java","spring-ai","anthropic","unsupported-media-type","illegal-argument"],"backgroundTag":"unsupported-operation","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}