mastra-ai/mastra · error
Unsupported part type: ${type}
Error message
Unsupported part type: ${type} What it means
convertImageFilePart converts ImagePart/FilePart content to LanguageModelV2 file parts and switches only on part.type 'image' or 'file'. Any other part type reaching this function throws 'Unsupported part type: <type>', since this converter is only meant for image/file parts.
Source
Thrown at packages/core/src/agent/message-list/prompt/convert-file.ts:20
import type { LanguageModelV2FilePart, LanguageModelV2TextPart } from '@ai-sdk/provider-v5';
import { convertToDataContent, detectMediaType, imageMediaTypeSignatures } from '../../../stream/aisdk/v5/compat';
export function convertImageFilePart(
part: ImagePart | FilePart,
downloadedAssets?: Record<string, { mediaType: string | undefined; data: Uint8Array }>,
): LanguageModelV2TextPart | LanguageModelV2FilePart {
let originalData: DataContent | URL;
const type = part.type;
switch (type) {
case 'image':
originalData = part.image;
break;
case 'file':
originalData = part.data;
break;
default:
throw new Error(`Unsupported part type: ${type}`);
}
const { data: convertedData, mediaType: convertedMediaType } = convertToDataContent(originalData);
let mediaType: string | undefined = convertedMediaType ?? part.mediaType;
let data: Uint8Array | string | URL = convertedData; // binary | base64 | url
// If the content is a URL, we check if it was downloaded:
if (data instanceof URL && downloadedAssets) {
const downloadedFile = downloadedAssets[data.toString()];
if (downloadedFile) {
data = downloadedFile.data;
mediaType ??= downloadedFile.mediaType;
}
}
// Now that we have the normalized data either as a URL or a Uint8Array,
// we can create the LanguageModelV2Part.View on GitHub (pinned to 75dd419e61)
Solutions
- Make sure only 'image' and 'file' parts are passed to this conversion path; route 'text' parts through the text-part converter.
- Normalize custom part types to supported AI SDK part types before building the prompt.
- Check for AI SDK major-version mismatches between your app and @mastra/core's pinned provider versions.
- Log/inspect the offending part's type in the error message to find the producer.
Example fix
// before
parts.push({ type: 'audio', data } as any);
// after
parts.push({ type: 'file', data, mediaType: 'audio/mpeg' }); Defensive patterns
Strategy: type-guard
Validate before calling
function onlyImageOrFile(parts: Array<{ type: string }>) {
const bad = parts.filter(p => p.type !== 'image' && p.type !== 'file');
if (bad.length) throw new Error(`Non image/file parts must not reach file conversion: ${bad.map(p => p.type).join(',')}`);
} Type guard
function isImageOrFilePart(p: { type: string }): p is ({ type: 'image'; image: unknown } | { type: 'file'; data: unknown }) {
return p.type === 'image' || p.type === 'file';
} Try / catch
try {
converted = convertImageFilePart(part as any, downloadedAssets);
} catch (e) {
if (e instanceof Error && e.message.startsWith('Unsupported part type:')) {
console.error('Part routed to file converter with type:', (part as any).type);
return routeToCorrectConverter(part); // e.g. text-part handler
}
throw e;
} Prevention
- Partition content arrays by part type before conversion; route each to its own converter.
- Keep AI SDK versions aligned between your app and @mastra/core to avoid unknown part types.
- Add a unit test that round-trips every part type you emit.
When it happens
Trigger: A content array containing a part whose type is not 'image' or 'file' (e.g. 'text' handled elsewhere but mis-routed, or a provider-specific/novel part type) reaching convertedContent → convertImageFilePart during prompt conversion.
Common situations: Custom prompt builders that push unknown part types into image/file conversion paths; version drift between AI SDK part types and the v2 provider parts; typos like 'image_part'.
Related errors
- runId is required when resumeData is provided
- Agent ${agentId} not found
- Messages must be an array of UIMessage objects
- Path must include :agentId to route to the correct agent or
- Agent ID is required
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/5826b48fd241c4c3.
Report an issue: GitHub.