TanStack

fileSourceFromHandle

ts
function fileSourceFromHandle<TProvider>(handle): ContentPartFileSource<TProvider>;

Defined in: packages/ai/src/activities/files/index.ts:104

Build a { type: 'file' } content source from an uploaded FileHandle, for use in a chat message (image/audio/document part source).

The source's value is the handle's wire form: the handle URL when the provider exposes one (Gemini, fal, Grok), otherwise the opaque id (OpenAI, Anthropic). provider records the issuer, so an adapter for a different provider rejects the source rather than sending a handle it cannot resolve.

Type Parameters

TProvider

TProvider extends string

Parameters

handle

FileHandle<TProvider>

Returns

ContentPartFileSource<TProvider>

Example

ts
const handle = await uploadFile({ adapter: openaiFiles(), input })
messages.push({ role: 'user', content: [
  { type: 'image', source: fileSourceFromHandle(handle) },
] })