useFileUrl()
Lazy attachment URLs.
useFileUrl fetches a short-lived URL for an attachment fileId. URLs are not stored on the message — ask when you need a preview.
Assistant.useFileUrl needs Pai.Provider, not ThreadProvider. Package-root useFileUrl needs both.
function AttachmentPreview({ part }: { part: { fileId: string } }) {
const preview = Assistant.useFileUrl(part.fileId, { intent: "view" });
if (preview.status !== "ready" || !preview.url) return null;
return <img src={preview.url} alt="" />;
}Import
const { url, status } = Assistant.useFileUrl(part.fileId, { intent: "view" });Signature
function useFileUrl(
fileId: string | null | undefined,
options?: UseFileUrlOptions,
): FileUrlController;Parameters
fileId: string | null | undefined
Attachment id from a message part. null / undefined keeps the hook idle.
options?: UseFileUrlOptions
intent?: "view" | "download"
ttlSeconds?: number
enabled?: boolean
When false, skips the request.
Defaults to true.
Returns
FileUrlController
url: string | null
status: "idle" | "loading" | "ready" | "unsupported" | "not-found" | "error"
error: Error | null
retry: () => void
Force a fresh fetch.