vercel/ai · error · UnsupportedFunctionalityError
media type: ${part.mediaType}
Error message
media type: ${part.mediaType} What it means
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`.
Source
Thrown at packages/anthropic/src/convert-to-anthropic-prompt.ts:402
}
: {
type: 'text',
media_type: 'text/plain',
data: convertBytesDataToString(
part.data.data,
),
},
title: metadata.title ?? part.filename,
...(metadata.context && {
context: metadata.context,
}),
...(enableCitations && {
citations: { enabled: true },
}),
cache_control: cacheControl,
});
} else {
throw new UnsupportedFunctionalityError({
functionality: `media type: ${part.mediaType}`,
});
}
break;
}
}
break;
}
}
}
break;
}
case 'tool': {
for (let i = 0; i < content.length; i++) {
const part = content[i];
View on GitHub (pinned to 69428b1f8b)
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.
Example fix
// before
messages: [{ role: 'user', content: [{ type: 'file', data, mediaType: 'audio/wav' }] }]
// after
// transcribe audio separately, then send text or a supported image/PDF part
messages: [{ role: 'user', content: [{ type: 'file', data, mediaType: 'application/pdf' }] }] Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED = new Set(['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'application/pdf']);
for (const msg of messages) {
for (const part of Array.isArray(msg.content) ? msg.content : []) {
if ('mediaType' in part && !SUPPORTED.has(part.mediaType)) {
throw new Error(`Unsupported media type for Anthropic: ${part.mediaType}`);
}
}
} Try / catch
try {
return await generateText({ model: anthropic(modelId), messages });
} catch (error) {
if (UnsupportedFunctionalityError.isInstance(error) && error.functionality?.startsWith('media type:')) {
// sanitize the offending part and retry
return await generateText({ model: anthropic(modelId), messages: filterUnsupportedParts(messages) });
}
throw error;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- AI_UnsupportedFunctionalityError
- 'element streams in no-schema mode' functionality not suppor
- 'element streams in object mode' functionality not supported
- 'element streams in enum mode' functionality not supported.
- AI_UnsupportedFunctionalityError
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/59b57e5d0a1f43b6.
Report an issue: GitHub.