{"record":{"id":"59b57e5d0a1f43b6","repo":"vercel/ai","slug":"media-type-part-mediatype","errorCode":null,"errorMessage":"media type: ${part.mediaType}","messagePattern":"media type: (.+?)","errorType":"exception","errorClass":"UnsupportedFunctionalityError","httpStatus":null,"severity":"error","filePath":"packages/anthropic/src/convert-to-anthropic-prompt.ts","lineNumber":402,"sourceCode":"                                  }\n                                : {\n                                    type: 'text',\n                                    media_type: 'text/plain',\n                                    data: convertBytesDataToString(\n                                      part.data.data,\n                                    ),\n                                  },\n                            title: metadata.title ?? part.filename,\n                            ...(metadata.context && {\n                              context: metadata.context,\n                            }),\n                            ...(enableCitations && {\n                              citations: { enabled: true },\n                            }),\n                            cache_control: cacheControl,\n                          });\n                        } else {\n                          throw new UnsupportedFunctionalityError({\n                            functionality: `media type: ${part.mediaType}`,\n                          });\n                        }\n                        break;\n                      }\n                    }\n\n                    break;\n                  }\n                }\n              }\n\n              break;\n            }\n            case 'tool': {\n              for (let i = 0; i < content.length; i++) {\n                const part = content[i];\n","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/anthropic/src/convert-to-anthropic-prompt.ts#L384-L420","documentation":"convertToAnthropicPrompt throws UnsupportedFunctionalityError when a source message part has a media type that the Anthropic prompt converter does not recognize or support (e.g. an image/* or file media type outside the supported set, or unsupported formats inside document/image blocks). The message is built from the offending part's `mediaType`.","triggerScenarios":"Sending messages containing file/image parts whose `mediaType` is not one of the types the converter handles (e.g. audio parts, unusual MIME types like 'video/mp4', or unsupported document media types) to a Claude model via generateText/streamText.","commonSituations":"Piping user-uploaded attachments of arbitrary MIME types straight into Claude; reusing prompt arrays built for a multimodal provider (e.g. Gemini/OpenAI) with Anthropic; citation-enabled document blocks with non-PDF media types.","solutions":["Inspect the message parts and remove or convert parts whose mediaType Anthropic does not support (supported: image/jpeg, image/png, image/gif, image/webp; application/pdf documents).","Convert unsupported media to a supported format (e.g. transcode audio elsewhere, convert documents to PDF) before sending.","Filter the prompt by mediaType before passing it to the Anthropic model."],"exampleFix":"// before\nmessages: [{ role: 'user', content: [{ type: 'file', data, mediaType: 'audio/wav' }] }]\n// after\n// transcribe audio separately, then send text or a supported image/PDF part\nmessages: [{ role: 'user', content: [{ type: 'file', data, mediaType: 'application/pdf' }] }]","handlingStrategy":"validation","validationCode":"const SUPPORTED = new Set(['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'application/pdf']);\nfor (const msg of messages) {\n  for (const part of Array.isArray(msg.content) ? msg.content : []) {\n    if ('mediaType' in part && !SUPPORTED.has(part.mediaType)) {\n      throw new Error(`Unsupported media type for Anthropic: ${part.mediaType}`);\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await generateText({ model: anthropic(modelId), messages });\n} catch (error) {\n  if (UnsupportedFunctionalityError.isInstance(error) && error.functionality?.startsWith('media type:')) {\n    // sanitize the offending part and retry\n    return await generateText({ model: anthropic(modelId), messages: filterUnsupportedParts(messages) });\n  }\n  throw error;\n}","preventionTips":["Whitelist MIME types at upload/ingest time before prompts are built.","Convert unsupported media (audio/video) upstream to text or supported formats.","Test multimodal prompts against each target provider's supported media list."],"tags":["unsupported-functionality","multimodal","content-conversion"],"backgroundTag":"unsupported-media-type","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}