{"record":{"id":"2ff275f707242147","repo":"vercel/ai","slug":"file-part-media-type-fullmediatype","errorCode":null,"errorMessage":"file part media type ${fullMediaType}","messagePattern":"file part media type (.+?)","errorType":"exception","errorClass":"UnsupportedFunctionalityError","httpStatus":null,"severity":"error","filePath":"packages/perplexity/src/convert-to-perplexity-messages.ts","lineNumber":68,"sourceCode":"                      functionality: 'file parts with provider references',\n                    });\n                  }\n                  case 'text': {\n                    throw new UnsupportedFunctionalityError({\n                      functionality: 'text file parts',\n                    });\n                  }\n                  case 'url':\n                  case 'data': {\n                    const topLevelMediaType = getTopLevelMediaType(\n                      part.mediaType,\n                    );\n\n                    if (topLevelMediaType === 'application') {\n                      const fullMediaType = resolveFullMediaType({ part });\n\n                      if (fullMediaType !== 'application/pdf') {\n                        throw new UnsupportedFunctionalityError({\n                          functionality: `file part media type ${fullMediaType}`,\n                        });\n                      }\n\n                      return part.data.type === 'url'\n                        ? {\n                            type: 'file_url',\n                            file_url: {\n                              url: part.data.url.toString(),\n                            },\n                            file_name: part.filename,\n                          }\n                        : {\n                            type: 'file_url',\n                            file_url: {\n                              url:\n                                typeof part.data.data === 'string'\n                                  ? part.data.data","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/perplexity/src/convert-to-perplexity-messages.ts#L50-L86","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Convert the document to PDF before sending it to Perplexity","Send images as image parts ({ type: 'image', ... }) rather than file parts","Filter or reject non-PDF attachments in your app before invoking the model"],"exampleFix":"// before\n{ type: 'file', data: new URL('https://example.com/shot.png'), mediaType: 'image/png' }\n// after\n{ type: 'image', image: new URL('https://example.com/shot.png') }","handlingStrategy":"validation","validationCode":"for (const part of msg.content) {\n  if (part.type === 'file') {\n    const mediaType = part.mediaType ?? '';\n    if (mediaType !== 'application/pdf') {\n      throw new Error(`Perplexity only supports PDF file parts, got ${mediaType}`);\n    }\n  }\n}","typeGuard":"function isPdfFilePart(part: { type: string; mediaType?: string }): part is { type: 'file'; mediaType: 'application/pdf' } {\n  return part.type === 'file' && part.mediaType === 'application/pdf';\n}","tryCatchPattern":"try {\n  await generateText({ model: perplexity('sonar-pro'), messages });\n} catch (e) {\n  if (UnsupportedFunctionalityError.isInstance(e) && e.message.includes('file part media type')) {\n    // convert to PDF, route as image part, or drop the attachment\n  } else throw e;\n}","preventionTips":["Whitelist PDF as the only file media type sent to Perplexity","Send images as image parts, never as file parts","Convert Office/CSV documents to PDF server-side before attaching","Validate attachment media types at upload time in your app"],"tags":["perplexity","file-parts","unsupported-functionality","media-type","pdf"],"backgroundTag":"unsupported-file-part","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}