Skip to main content

Function: file()

file(data, mimeType, options?): UnifiedMessageInput

Defined in: packages/core/src/multimodal.ts:218

Create a file input for documents, PDFs, and other file types.

Accepts binary data (Blob, Uint8Array, ArrayBuffer, base64 string) or an HTTPS URL. When an HTTPS URL is provided, the AI provider fetches the file server-side — the bytes never transit through your application. Works across all providers via the AI SDK. HTTP (non-TLS) URLs are rejected for security.

Parameters​

data​

string | ArrayBuffer | Uint8Array<ArrayBufferLike> | Blob

mimeType​

string

options?​

cacheControl?​

boolean

Returns​

UnifiedMessageInput

Examples​

PDF from blob storage URL (provider fetches directly)

bot.process(combine(
text('Summarize this contract'),
file('https://storage.example.com/contract.pdf', 'application/pdf', { cacheControl: true })
));

PDF from binary data

const pdfBlob = await fetch('report.pdf').then(r => r.blob());
bot.process(combine(text('Summarize this'), file(pdfBlob, 'application/pdf')));

With caching (second call within 5min is ~90% cheaper on Anthropic)

bot.process(file(pdfBuffer, 'application/pdf', { cacheControl: true }));