Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

fileSourceFromHandle.md

44 lines1.1 KB

1---
2id: fileSourceFromHandle
3title: fileSourceFromHandle
4---
5​
6```ts
7function fileSourceFromHandle<TProvider>(handle): ContentPartFileSource<TProvider>;
8```
9​
10Defined in: packages/ai/src/activities/files/index.ts:104
11​
12Build a `{ type: 'file' }` content source from an uploaded
13[FileHandle](../interfaces/FileHandle.md), for use in a chat message (image/audio/document part
14`source`).
15​
16The source's `value` is the handle's wire form: the handle URL when the
17provider exposes one (Gemini, fal, Grok), otherwise the opaque id (OpenAI,
18Anthropic). `provider` records the issuer, so an adapter for a different
19provider rejects the source rather than sending a handle it cannot resolve.
20​
21## Type Parameters
22​
23### TProvider
24​
25`TProvider` *extends* `string`
26​
27## Parameters
28​
29### handle
30​
31[`FileHandle`](../interfaces/FileHandle.md)\<`TProvider`\>
32​
33## Returns
34​
35[`ContentPartFileSource`](../interfaces/ContentPartFileSource.md)\<`TProvider`\>
36​
37## Example
38​
39```ts
40const handle = await uploadFile({ adapter: openaiFiles(), input })
41messages.push({ role: 'user', content: [
42 { type: 'image', source: fileSourceFromHandle(handle) },
43] })
44```