{"record":{"id":"9df8909536647ef1","repo":"wavetermdev/waveterm","slug":"unsupported-media-type-s-must-be-uploaded-to-f","errorCode":null,"errorMessage":"unsupported media type '%s' (must be uploaded to Files API and sent as file_id)","messagePattern":"unsupported media type '(.+?)' \\(must be uploaded to Files API and sent as file_id\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/anthropic/anthropic-convertmessage.go","lineNumber":654,"sourceCode":"\t\t\t\ttextData = string(decoded)\n\t\t\t}\n\t\t\treturn &anthropicMessageContentBlock{\n\t\t\t\tType: \"document\",\n\t\t\t\tSource: &anthropicSource{\n\t\t\t\t\tType:      \"text\",\n\t\t\t\t\tData:      textData,\n\t\t\t\t\tMediaType: part.MimeType,\n\t\t\t\t\tFileName:  part.FileName,\n\t\t\t\t},\n\t\t\t}, nil\n\t\t} else {\n\t\t\t// HTTP/HTTPS URL → not supported inline, would need to fetch\n\t\t\treturn nil, fmt.Errorf(\"text/plain file with URL not supported (must be fetched and converted to base64 or uploaded to Files API)\")\n\t\t}\n\n\tdefault:\n\t\t// Other media types → not supported inline, must upload and use file_id\n\t\treturn nil, fmt.Errorf(\"unsupported media type '%s' (must be uploaded to Files API and sent as file_id)\", part.MimeType)\n\t}\n}\n\n// ConvertToUIMessage converts an anthropicChatMessage to a UIMessage\nfunc (m *anthropicChatMessage) ConvertToUIMessage() *uctypes.UIMessage {\n\tvar parts []uctypes.UIMessagePart\n\n\t// Iterate over all content blocks\n\tfor _, block := range m.Content {\n\t\tswitch block.Type {\n\t\tcase \"text\":\n\t\t\t// Convert text blocks to UIMessagePart\n\t\t\tparts = append(parts, uctypes.UIMessagePart{\n\t\t\t\tType: \"text\",\n\t\t\t\tText: block.Text,\n\t\t\t})\n\t\tcase \"image\":\n\t\t\t// Convert image blocks to data-userfile UIMessagePart (only for user role)","sourceCodeStart":636,"sourceCodeEnd":672,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/anthropic/anthropic-convertmessage.go#L636-L672","documentation":"The Anthropic inline conversion path only supports image/*, application/pdf, and text/plain mimetypes. Any other media type (audio, video, office docs, etc.) cannot be sent inline and must be uploaded to the Anthropic Files API and referenced by file_id, so conversion fails with this message.","triggerScenarios":"ConvertFileAIMessagePart (via ConvertAIMessageToAnthropicChatMessage) with a file part whose MimeType is not image/*, application/pdf, or text/plain/* — e.g. 'audio/mpeg', 'application/zip', 'video/mp4'.","commonSituations":"Attaching audio/video recordings or arbitrary binary attachments to a chat message; assuming the SDK supports the same media types as other AI providers.","solutions":["Upload the file via the Anthropic Files API and pass the returned file_id instead of inline content","Convert the file to a supported type (PDF, PNG/JPEG/etc., or plain text) before sending","If the content is truly text, set MimeType to text/plain and supply base64 data"],"exampleFix":"// before\npart := uctypes.AIMessagePart{MimeType: \"audio/wav\", URL: dataURL}\n// after\nfile, _ := client.Files.Upload(ctx, wavData, \"audio/wav\", \"clip.wav\")\npart := uctypes.AIMessagePart{MimeType: \"audio/wav\", FileID: file.ID}","handlingStrategy":"validation","validationCode":"func inlineSupported(mime string) bool {\n    return strings.HasPrefix(mime, \"image/\") || mime == \"application/pdf\" || strings.HasPrefix(mime, \"text/plain\")\n}\nif !inlineSupported(part.MimeType) { /* upload to Files API first */ }","typeGuard":"func isInlinableMime(mime string) bool {\n    return strings.HasPrefix(mime, \"image/\") || mime == \"application/pdf\" || strings.HasPrefix(mime, \"text/plain\")\n}","tryCatchPattern":null,"preventionTips":["Upload audio/video/office files to the Anthropic Files API and use file_id","Restrict user-uploaded attachments to supported mimetypes at intake","Convert unsupported formats (e.g. docx→pdf) before sending"],"tags":["go","anthropic","unsupported-media-type"],"backgroundTag":"unsupported-media-type","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}