{"record":{"id":"40f887ca59580227","repo":"vercel/ai","slug":"file-parts-with-provider-references-40f887","errorCode":null,"errorMessage":"file parts with provider references","messagePattern":"file parts with provider references","errorType":"exception","errorClass":"UnsupportedFunctionalityError","httpStatus":null,"severity":"error","filePath":"packages/perplexity/src/convert-to-perplexity-messages.ts","lineNumber":49,"sourceCode":"            (part.type === 'file' &&\n              getTopLevelMediaType(part.mediaType) === 'image') ||\n            (part.type === 'file' &&\n              getTopLevelMediaType(part.mediaType) === 'application'),\n        );\n\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') {","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/perplexity/src/convert-to-perplexity-messages.ts#L31-L67","documentation":"Perplexity's message format cannot express file parts whose data is a provider reference (a pointer to a previously uploaded/generated file). convertToPerplexityMessages throws UnsupportedFunctionalityError for part.data.type === 'reference' because there is no Perplexity representation to map it to.","triggerScenarios":"Sending a prompt whose messages contain a file part created with a provider-generated reference (e.g. data from a prior generateImage/file upload returned as { type: 'reference', ... }) to a perplexity.chat(...) model.","commonSituations":"Chaining outputs between providers (OpenAI file ids or previously generated assets passed to Perplexity); reusing a shared message history that includes provider-specific file references.","solutions":["Inline the actual file bytes as a data part (base64 data URL) instead of a reference","Provide the file as a URL part that Perplexity can fetch","Strip or convert reference file parts before calling Perplexity"],"exampleFix":"// before\n{ type: 'file', data: { type: 'reference', fileId } }\n// after\n{ type: 'file', data: new URL('https://example.com/doc.pdf'), mediaType: 'application/pdf' }","handlingStrategy":"validation","validationCode":"for (const msg of messages) {\n  for (const part of msg.content) {\n    if (part.type === 'file' && part.data?.type === 'reference') {\n      throw new Error('Perplexity cannot consume file parts with provider references; inline data or use a URL');\n    }\n  }\n}","typeGuard":"function isReferencedFilePart(part: { type: string; data?: { type?: string } }): boolean {\n  return part.type === 'file' && part.data?.type === 'reference';\n}","tryCatchPattern":"try {\n  await generateText({ model: perplexity('sonar-pro'), messages });\n} catch (e) {\n  if (UnsupportedFunctionalityError.isInstance(e) && e.message.includes('provider references')) {\n    // rebuild messages with inlined data/URL file parts\n  } else throw e;\n}","preventionTips":["Resolve provider file references to concrete data/URLs before dispatching to Perplexity","Sanitize shared message histories per target provider","Avoid persisting provider-specific file references in provider-agnostic histories"],"tags":["perplexity","file-parts","unsupported-functionality","provider-reference"],"backgroundTag":"unsupported-file-part","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}