vercel/ai · error · UnsupportedFunctionalityError

file part media type ${fullMediaType}

Error message

file part media type ${fullMediaType}

What it means

Perplexity file support is effectively limited to PDFs. When a file part's resolved full media type is anything other than application/pdf, convertToPerplexityMessages throws UnsupportedFunctionalityError naming the offending media type, because Perplexity cannot ingest it (images must be sent as image parts, not file parts).

Source

Thrown at packages/perplexity/src/convert-to-perplexity-messages.ts:68

                      functionality: 'file parts with provider references',
                    });
                  }
                  case 'text': {
                    throw new UnsupportedFunctionalityError({
                      functionality: 'text file parts',
                    });
                  }
                  case 'url':
                  case 'data': {
                    const topLevelMediaType = getTopLevelMediaType(
                      part.mediaType,
                    );

                    if (topLevelMediaType === 'application') {
                      const fullMediaType = resolveFullMediaType({ part });

                      if (fullMediaType !== 'application/pdf') {
                        throw new UnsupportedFunctionalityError({
                          functionality: `file part media type ${fullMediaType}`,
                        });
                      }

                      return part.data.type === 'url'
                        ? {
                            type: 'file_url',
                            file_url: {
                              url: part.data.url.toString(),
                            },
                            file_name: part.filename,
                          }
                        : {
                            type: 'file_url',
                            file_url: {
                              url:
                                typeof part.data.data === 'string'
                                  ? part.data.data

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Convert the document to PDF before sending it to Perplexity
  2. Send images as image parts ({ type: 'image', ... }) rather than file parts
  3. Filter or reject non-PDF attachments in your app before invoking the model

Example fix

// before
{ type: 'file', data: new URL('https://example.com/shot.png'), mediaType: 'image/png' }
// after
{ type: 'image', image: new URL('https://example.com/shot.png') }
Defensive patterns

Strategy: validation

Validate before calling

for (const part of msg.content) {
  if (part.type === 'file') {
    const mediaType = part.mediaType ?? '';
    if (mediaType !== 'application/pdf') {
      throw new Error(`Perplexity only supports PDF file parts, got ${mediaType}`);
    }
  }
}

Type guard

function isPdfFilePart(part: { type: string; mediaType?: string }): part is { type: 'file'; mediaType: 'application/pdf' } {
  return part.type === 'file' && part.mediaType === 'application/pdf';
}

Try / catch

try {
  await generateText({ model: perplexity('sonar-pro'), messages });
} catch (e) {
  if (UnsupportedFunctionalityError.isInstance(e) && e.message.includes('file part media type')) {
    // convert to PDF, route as image part, or drop the attachment
  } else throw e;
}

Prevention

When it happens

Trigger: Sending a file part with a media type such as image/png, application/msword, text/csv, or audio/* (anything non-PDF) to a Perplexity chat model, including via URL or data parts.

Common situations: Uploading images as file parts instead of image parts; passing Office/CSV documents that only some providers accept; dynamically chosen attachments where media type is not filtered before dispatch.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/2ff275f707242147. Report an issue: GitHub.