vercel/ai · error · UnsupportedFunctionalityError

'file part media type ${block.mediaType} as inline data (xAI

Error message

'file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)' functionality not supported.

What it means

For Responses API input, xAI only accepts non-image files via URL or a Files API file_id reference. Inline binary data (base64 'data') for non-image media types has no wire representation, so the converter throws UnsupportedFunctionalityError naming the media type.

Source

Thrown at packages/xai/src/responses/convert-to-xai-responses-input.ts:101

                    contentParts.push({
                      type: 'input_image',
                      image_url: imageUrl,
                      ...(filePartOptions?.imageDetail != null && {
                        detail: filePartOptions.imageDetail,
                      }),
                    });
                  } else if (block.data.type === 'url') {
                    // xAI's Responses API accepts non-image documents (PDF, text, CSV, etc.)
                    // via `{ type: 'input_file', file_url }`. See
                    // https://docs.x.ai/docs/guides/chat-with-files. Inline bytes for
                    // non-image files are not supported by xAI; callers must upload via
                    // the Files API and pass a provider reference (file_id) instead.
                    contentParts.push({
                      type: 'input_file',
                      file_url: block.data.url.toString(),
                    });
                  } else {
                    throw new UnsupportedFunctionalityError({
                      functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`,
                    });
                  }
                  break;
                }
              }
              break;
            }

            default: {
              const _exhaustiveCheck: never = block;
              inputWarnings.push({
                type: 'other',
                message:
                  'xAI Responses API does not support this content type in user messages',
              });
            }
          }

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Upload the file to xAI's Files API and reference it via providerOptions/data reference (file_id)
  2. Host the file at a URL and pass a file part with data: { type: 'url', url }
  3. Convert the content to text parts if it can be represented as text

Example fix

// before
{ type: 'file', mediaType: 'application/pdf', data: { type: 'data', data: base64Pdf } }
// after (upload first, then reference)
{ type: 'file', mediaType: 'application/pdf', data: { type: 'reference', reference: new ProviderReference({ fileId }) } }
Defensive patterns

Strategy: validation

Validate before calling

for (const m of prompt) for (const p of m.content) {
  if (p.type === 'file' && p.data.type === 'data' && !p.mediaType.startsWith('image/')) {
    throw new Error('inline non-image file data unsupported by xai responses; upload to Files API first');
  }
}

Type guard

function isInlineNonImageFile(p: any): boolean {
  return p?.type === 'file' && p?.data?.type === 'data' && !String(p?.mediaType ?? '').startsWith('image/');
}

Try / catch

try {
  await streamText({ model, prompt });
} catch (e) {
  if ((e as any).name === 'AI_UnsupportedFunctionalityError' && (e as Error).message.includes('as inline data')) {
    // upload file to xAI Files API and rebuild prompt with a reference
  }
}

Prevention

When it happens

Trigger: Passing a file part with data type 'data' (inline base64/binary) and a non-image mediaType (e.g. application/pdf, audio/*) to an xai responses model; image data parts are allowed, everything else inline is not.

Common situations: Embedding a PDF as base64 in the prompt; reusing prompts written for OpenAI/Anthropic that accept inline document data; generating files at runtime and attaching them inline.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/5c8d04a79000d9e7. Report an issue: GitHub.