vercel/ai · error · UnsupportedFunctionalityError
'text file parts' functionality not supported.
Error message
'text file parts' functionality not supported.
What it means
convertToXaiChatMessages maps AI SDK file parts to xAI's chat format. xAI's chat API supports image file parts but not text file parts, so a file part with a text media type throws UnsupportedFunctionalityError with the message 'text file parts' functionality not supported.
Source
Thrown at packages/xai/src/convert-to-xai-chat-messages.ts:61
userContent.push({ type: 'text', text: part.text });
break;
}
case 'file': {
switch (part.data.type) {
case 'reference': {
userContent.push({
type: 'file',
file: {
file_id: resolveProviderReference({
reference: part.data.reference,
provider: 'xai',
}),
},
});
break;
}
case 'text': {
throw new UnsupportedFunctionalityError({
functionality: 'text file parts',
});
}
case 'url':
case 'data': {
if (getTopLevelMediaType(part.mediaType) === 'image') {
const filePartOptions = await parseProviderOptions({
provider: 'xai',
providerOptions: part.providerOptions,
schema: xaiFilePartProviderOptions,
});
userContent.push({
type: 'image_url',
image_url: {
url:
part.data.type === 'url'
? part.data.url.toString()View on GitHub (pinned to 69428b1f8b)
Solutions
- Convert the text file content to a TextPart (inline the text into the prompt) before sending.
- If sending a document, use a provider that supports text file parts, or extract text yourself.
- Filter out text file parts with a warning before the call.
Example fix
// before
messages: [{ role: 'user', content: [{ type: 'file', data: txtBuffer, mediaType: 'text/plain' }] }]
// after
messages: [{ role: 'user', content: [{ type: 'text', text: txtBuffer.toString('utf-8') }] }] Defensive patterns
Strategy: validation
Validate before calling
function assertNoTextFileParts(messages: ModelMessage[]) {
for (const m of messages) {
for (const p of Array.isArray(m.content) ? m.content : []) {
if (p.type === 'file' && p.mediaType.startsWith('text/')) {
throw new Error(`Convert text file part (${p.mediaType}) to a text part before sending to xAI`);
}
}
}
} Type guard
const isImageFilePart = (p: unknown): p is FilePart & { mediaType: `image/${string}` } =>
typeof p === 'object' && p !== null && (p as any).type === 'file' &&
String((p as any).mediaType).startsWith('image/'); Try / catch
try {
await generateText({ model: xai('grok-4'), messages });
} catch (e) {
if (UnsupportedFunctionalityError.isInstance(e) && e.functionality === 'text file parts') {
messages = messages.map(convertTextFilePartsToText);
return generateText({ model: xai('grok-4'), messages });
}
throw e;
} Prevention
- Map uploaded text/.txt/.csv files to TextParts before calling xAI models.
- Write a provider-agnostic preprocessing step for message content per provider.
- Add a unit test asserting message content passed to xai contains no text file parts.
When it happens
Trigger: Passing a message containing a FilePart whose mediaType is a text type (e.g. text/plain) to a model from @ai-sdk/xai via generateText/streamText.
Common situations: Sending extracted PDF text or .txt/.csv attachments as file parts; generic file-upload UI forwarding all attachments to the model; code written for another provider (e.g. Anthropic, which supports text file parts) reused with xAI.
Related errors
- 'file part media type ${part.mediaType}' functionality not s
- 'text file parts' functionality not supported.
- 'file part media type ${block.mediaType} as inline data (xAI
- AI_UnsupportedFunctionalityError
- file parts with provider references
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/6d555a090b193178.
Report an issue: GitHub.