{"record":{"id":"970ad14868cb7641","repo":"vercel/ai","slug":"file-part-data-type-part-data-type","errorCode":null,"errorMessage":"file part data type ${part.data.type}","messagePattern":"file part data type (.+?)","errorType":"exception","errorClass":"UnsupportedFunctionalityError","httpStatus":null,"severity":"error","filePath":"packages/mistral/src/convert-to-mistral-chat-messages.ts","lineNumber":25,"sourceCode":"  MistralAssistantMessageContent,\n  MistralPrompt,\n} from './mistral-chat-prompt';\nimport {\n  convertToBase64,\n  getTopLevelMediaType,\n  resolveFullMediaType,\n} from '@ai-sdk/provider-utils';\n\nfunction formatFileUrl({ part }: { part: LanguageModelV4FilePart }): string {\n  if (part.data.type === 'url') {\n    return part.data.url.toString();\n  }\n\n  if (part.data.type === 'data') {\n    return `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`;\n  }\n\n  throw new UnsupportedFunctionalityError({\n    functionality: `file part data type ${part.data.type}`,\n  });\n}\n\nexport function convertToMistralChatMessages(\n  prompt: LanguageModelV4Prompt,\n): MistralPrompt {\n  const messages: MistralPrompt = [];\n\n  for (let i = 0; i < prompt.length; i++) {\n    const { role, content } = prompt[i];\n    const isLastMessage = i === prompt.length - 1;\n\n    switch (role) {\n      case 'system': {\n        messages.push({ role: 'system', content });\n        break;\n      }","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/mistral/src/convert-to-mistral-chat-messages.ts#L7-L43","documentation":"Mistral's chat API has no representation for this file part's data type, so formatFileUrl throws UnsupportedFunctionalityError listing the unsupported type. Only 'url' and 'data' (base64) file parts can be converted to Mistral message format.","triggerScenarios":"Passing a file part whose data.type is neither 'url' nor 'data' (e.g. 'reference' or 'text') into a message sent to a Mistral chat model via streamText/generateText.","commonSituations":"Building prompts with provider-specific file references (from another provider's output) and sending them to Mistral; generic prompt-building code that attaches file parts of every kind.","solutions":["Send file parts with url or binary data instead of the unsupported data type.","Download referenced files and resend them as url or base64 data parts.","Filter out unsupported file parts before constructing the prompt.","Use a provider that supports the part type for that request."],"exampleFix":"// before: provider reference\n{ type: 'file', data: { type: 'reference', ... } }\n// after: send binary data\n{ type: 'file', mediaType: 'application/pdf', data: { type: 'data', data: pdfBytes } }","handlingStrategy":"validation","validationCode":"function isMistralCompatibleFilePart(part: { type: string; data: { type: string } }): boolean {\n  return part.type !== 'file' || ['url', 'data'].includes(part.data.type);\n}\n// filter before building the prompt:\nconst safeContent = content.filter(isMistralCompatibleFilePart);","typeGuard":"function isConvertibleFileData(data: unknown): data is { type: 'url'; url: string } | { type: 'data'; data: Uint8Array } {\n  return (\n    typeof data === 'object' && data !== null &&\n    ('url' in (data as any) || 'data' in (data as any)) &&\n    ['url', 'data'].includes((data as { type: string }).type)\n  );\n}","tryCatchPattern":"try {\n  await generateText({ model: mistral(modelId), prompt });\n} catch (error) {\n  if (UnsupportedFunctionalityError.isInstance(error)) {\n    console.warn('Unsupported part for Mistral:', error.functionality);\n  } else {\n    throw error;\n  }\n}","preventionTips":["Check provider capability docs before reusing prompts across providers.","Filter/convert file parts per provider in a central prompt builder.","Write unit tests converting every part type you use against each provider."],"tags":["mistral","unsupported-functionality","file-part","prompt-conversion"],"backgroundTag":"unsupported-provider-functionality","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}