{"record":{"id":"1ee64efb30f32886","repo":"vercel/ai","slug":"text-file-parts-1ee64e","errorCode":null,"errorMessage":"text file parts","messagePattern":"text file parts","errorType":"exception","errorClass":"UnsupportedFunctionalityError","httpStatus":null,"severity":"error","filePath":"packages/perplexity/src/convert-to-perplexity-messages.ts","lineNumber":54,"sourceCode":"\n        const messageContent = content\n          .map((part, index) => {\n            switch (part.type) {\n              case 'text': {\n                return {\n                  type: 'text',\n                  text: part.text,\n                };\n              }\n              case 'file': {\n                switch (part.data.type) {\n                  case 'reference': {\n                    throw new UnsupportedFunctionalityError({\n                      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","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/perplexity/src/convert-to-perplexity-messages.ts#L36-L72","documentation":"Perplexity only accepts binary/remote file content (e.g. PDFs by URL or data), not files whose payload is textual content carried inline. convertToPerplexityMessages throws UnsupportedFunctionalityError for file parts with data.type === 'text' since there is no corresponding Perplexity message field.","triggerScenarios":"Constructing a file part with data as plain text/string content ({ type: 'text', ... }) in a message sent to a Perplexity chat model.","commonSituations":"Passing extracted text of a document as a 'file' part instead of as a text part; generic document pipelines that build file parts with inline text payloads regardless of provider.","solutions":["Send the content as a normal text part instead of a file part","Upload/host the document and pass it as a URL file part (PDF)","Convert the text into a base64 data part with the proper media type if the content is a supported binary format"],"exampleFix":"// before\n{ type: 'file', data: { type: 'text', value: 'document text...' }, mediaType: 'application/pdf' }\n// after\n{ type: 'text', text: 'document text...' }","handlingStrategy":"validation","validationCode":"for (const part of msg.content) {\n  if (part.type === 'file' && part.data?.type === 'text') {\n    throw new Error('Send textual content as a text part, not a file part (Perplexity)');\n  }\n}","typeGuard":"function isTextFilePart(part: { type: string; data?: { type?: string } }): boolean {\n  return part.type === 'file' && part.data?.type === 'text';\n}","tryCatchPattern":"try {\n  await generateText({ model: perplexity('sonar-pro'), messages });\n} catch (e) {\n  if (UnsupportedFunctionalityError.isInstance(e) && e.message.includes('text file parts')) {\n    // convert those parts to plain text parts and retry\n  } else throw e;\n}","preventionTips":["Use text parts for textual content; reserve file parts for binary documents","Review document-ingestion pipelines that wrap extracted text in file parts","Add a preprocessing step that normalizes file parts before provider dispatch"],"tags":["perplexity","file-parts","unsupported-functionality","text-content"],"backgroundTag":"unsupported-file-part","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}