LLM JavaScript API

Everything the LLM extension adds to pb_hooks and page code, generated from the TypeScript declarations it ships (your app's types.d.ts has the same, so your editor knows them). For how to use it, see its docs; for Go, the Go API.

$llm

Cloud models, as $llm. $llm.for(e) is the same API with every call counted for whom the request is for (its user, else its guest), so the limits in Settings → LLM can cap each user and each guest: pass a route's e or a page's ctx. A call a limit refuses throws with code "limit" (429), naming the limit and when it resets.

$llm.text

$llm.text.completeAsync()

$llm.text.completeAsync(opts: LlmTextInput): Promise<LlmTextAnswer>

Answers a prompt or a conversation: model is "provider/model". With schema, the answer's data is JSON in that shape.

Parameter Type
opts LlmTextInput

Returns Promise<LlmTextAnswer>.

$llm.text.streamAsync()

$llm.text.streamAsync(opts: LlmTextInput, onText?: (text: string) => boolean | void, onReasoning?: (text: string) => boolean | void): Promise<LlmTextAnswer>

Like completeAsync, calling onText with each piece of the answer as it's written (false stops it).

Parameter Type
opts LlmTextInput
onText (text: string) => boolean | void (optional)
onReasoning (text: string) => boolean | void (optional)

Returns Promise<LlmTextAnswer>.

$llm.text.count()

$llm.text.count(textOrMessages: string | LlmMessage[] | { text?: string; system?: string; messages?: LlmMessage[] }): number

About how many tokens a text or a conversation is (four characters each); local, not a provider call.

Parameter Type
textOrMessages string | LlmMessage[] | { text?: string; system?: string; messages?: LlmMessage[] }

Returns number.

$llm.text.modelsAsync()

$llm.text.modelsAsync(opts?: LlmModelsOpts): Promise<LlmModels>

This kind's models across the providers in Settings → LLM (or one: { provider }), as provider/model.

Parameter Type
opts LlmModelsOpts (optional)

Returns Promise<LlmModels>.

$llm.image

$llm.image.generateAsync()

$llm.image.generateAsync(opts: { model: string; prompt: string; references?: LlmFile[]; n?: number; size?: string; aspectRatio?: string; options?: Record<string, any>; signal?: AbortSignal }): Promise<{ files: LlmFile[]; model: string; usage: LlmUsage }>

Makes pictures from a prompt: n of them, at a size or aspect ratio the provider supports. references are pictures it draws from: one to change, or one whose style and characters a new scene keeps. Only models with the feature "reference images" take them (Vultr, OpenRouter).

Parameter Type
opts { model: string; prompt: string; references?: LlmFile[]; n?: number; size?: string; aspectRatio?: string; options?: Record<string, any>; signal?: AbortSignal }

Returns Promise<{ files: LlmFile[]; model: string; usage: LlmUsage }>.

$llm.image.modelsAsync()

$llm.image.modelsAsync(opts?: LlmModelsOpts): Promise<LlmModels>

This kind's models across the providers in Settings → LLM (or one: { provider }), as provider/model.

Parameter Type
opts LlmModelsOpts (optional)

Returns Promise<LlmModels>.

$llm.speech

$llm.speech.speakAsync()

$llm.speech.speakAsync(opts: { model: string; text: string; voice?: string; format?: string; speed?: number; instructions?: string; reference?: { audio: LlmFile; text?: string }; options?: Record<string, any>; signal?: AbortSignal }): Promise<{ file: LlmFile; model: string; usage: LlmUsage }>

reference clones a voice: the text is read in the voice of that clip (leave voice and instructions out). Providers that don't clone refuse it.

Parameter Type
opts { model: string; text: string; voice?: string; format?: string; speed?: number; instructions?: string; reference?: { audio: LlmFile; text?: string }; options?: Record<string, any>; signal?: AbortSignal }

Returns Promise<{ file: LlmFile; model: string; usage: LlmUsage }>.

$llm.speech.voicesAsync()

$llm.speech.voicesAsync(model: string): Promise<{ id: string; name?: string; language?: string; gender?: string; mode?: "builtin" | "design" | "clone"; description?: string }[]>

A model clones when one of its voices has mode "clone".

Parameter Type
model string

Returns Promise<{ id: string; name?: string; language?: string; gender?: string; mode?: "builtin" | "design" | "clone"; description?: string }[]>.

$llm.speech.modelsAsync()

$llm.speech.modelsAsync(opts?: LlmModelsOpts): Promise<LlmModels>

This kind's models across the providers in Settings → LLM (or one: { provider }), as provider/model.

Parameter Type
opts LlmModelsOpts (optional)

Returns Promise<LlmModels>.

$llm.transcribe

$llm.transcribe.transcribeAsync()

$llm.transcribe.transcribeAsync(opts: { model: string; audio: LlmFile; language?: string; prompt?: string; options?: Record<string, any>; signal?: AbortSignal }): Promise<{ text: string; language?: string; model: string; usage: LlmUsage }>

Writes down what's said in a recording.

Parameter Type
opts { model: string; audio: LlmFile; language?: string; prompt?: string; options?: Record<string, any>; signal?: AbortSignal }

Returns Promise<{ text: string; language?: string; model: string; usage: LlmUsage }>.

$llm.transcribe.modelsAsync()

$llm.transcribe.modelsAsync(opts?: LlmModelsOpts): Promise<LlmModels>

This kind's models across the providers in Settings → LLM (or one: { provider }), as provider/model.

Parameter Type
opts LlmModelsOpts (optional)

Returns Promise<LlmModels>.

$llm.align

Forced alignment: when each line and word of a known text is said in its audio (captions, karaoke).

$llm.align.alignAsync()

$llm.align.alignAsync(opts: { model: string; audio: LlmFile; text: string; mode?: "speech" | "lyrics"; language?: string; options?: Record<string, any>; signal?: AbortSignal }): Promise<{ duration: number lines: { index: number; text: string; start: number; end: number; score: number; certain: boolean; tag?: string }[] words: { line: number; text: string; start: number; end: number; score: number }[] unaligned?: { line: number; text: string; reason: string }[] model: string usage: LlmUsage }>

When each line and word of text is said in audio.

Parameter Type
opts { model: string; audio: LlmFile; text: string; mode?: "speech" | "lyrics"; language?: string; options?: Record<string, any>; signal?: AbortSignal }

Returns Promise<{ duration: number lines: { index: number; text: string; start: number; end: number; score: number; certain: boolean; tag?: string }[] words: { line: number; text: string; start: number; end: number; score: number }[] unaligned?: { line: number; text: string; reason: string }[] model: string usage: LlmUsage }>.

$llm.align.modelsAsync()

$llm.align.modelsAsync(opts?: LlmModelsOpts): Promise<LlmModels>

This kind's models across the providers in Settings → LLM (or one: { provider }), as provider/model.

Parameter Type
opts LlmModelsOpts (optional)

Returns Promise<LlmModels>.

$llm.music

Music is a job: createAsync with wait ("5m") resolves once it's done, files included; without, follow it with getAsync.

$llm.music.createAsync()

$llm.music.createAsync(opts: { model: string; prompt: string; lyrics?: string; seconds?: number; wait?: string; options?: Record<string, any>; signal?: AbortSignal }): Promise<LlmJob>

Starts a piece of music; with wait ("5m") it resolves once it's done, files included.

Parameter Type
opts { model: string; prompt: string; lyrics?: string; seconds?: number; wait?: string; options?: Record<string, any>; signal?: AbortSignal }

Returns Promise<LlmJob>.

$llm.music.getAsync()

$llm.music.getAsync(id: string): Promise<LlmJob>

A job by id: its status, and its files once it's done.

Parameter Type
id string

Returns Promise<LlmJob>.

$llm.music.contentAsync()

$llm.music.contentAsync(id: string, index?: number): Promise<LlmFile>

A finished job's file (index for jobs with several), downloaded.

Parameter Type
id string
index number (optional)

Returns Promise<LlmFile>.

$llm.music.modelsAsync()

$llm.music.modelsAsync(opts?: LlmModelsOpts): Promise<LlmModels>

This kind's models across the providers in Settings → LLM (or one: { provider }), as provider/model.

Parameter Type
opts LlmModelsOpts (optional)

Returns Promise<LlmModels>.

$llm.video

$llm.video.createAsync()

$llm.video.createAsync(opts: { model: string; prompt: string; image?: LlmFile; seconds?: number; size?: string; aspectRatio?: string; wait?: string; options?: Record<string, any>; signal?: AbortSignal }): Promise<LlmJob>

Starts a video, optionally from a picture; with wait it resolves once it's done.

Parameter Type
opts { model: string; prompt: string; image?: LlmFile; seconds?: number; size?: string; aspectRatio?: string; wait?: string; options?: Record<string, any>; signal?: AbortSignal }

Returns Promise<LlmJob>.

$llm.video.getAsync()

$llm.video.getAsync(id: string): Promise<LlmJob>

A job by id: its status, and its files once it's done.

Parameter Type
id string

Returns Promise<LlmJob>.

$llm.video.contentAsync()

$llm.video.contentAsync(id: string, index?: number): Promise<LlmFile>

A finished job's file (index for jobs with several), downloaded.

Parameter Type
id string
index number (optional)

Returns Promise<LlmFile>.

$llm.video.modelsAsync()

$llm.video.modelsAsync(opts?: LlmModelsOpts): Promise<LlmModels>

This kind's models across the providers in Settings → LLM (or one: { provider }), as provider/model.

Parameter Type
opts LlmModelsOpts (optional)

Returns Promise<LlmModels>.

$llm.embed

$llm.embed.embedAsync()

$llm.embed.embedAsync(opts: { model: string; input: string[]; dimensions?: number; options?: Record<string, any>; signal?: AbortSignal }): Promise<{ vectors: number[][]; model: string; usage: LlmUsage }>

Turns each text into a vector, for search and similarity.

Parameter Type
opts { model: string; input: string[]; dimensions?: number; options?: Record<string, any>; signal?: AbortSignal }

Returns Promise<{ vectors: number[][]; model: string; usage: LlmUsage }>.

$llm.embed.modelsAsync()

$llm.embed.modelsAsync(opts?: LlmModelsOpts): Promise<LlmModels>

This kind's models across the providers in Settings → LLM (or one: { provider }), as provider/model.

Parameter Type
opts LlmModelsOpts (optional)

Returns Promise<LlmModels>.

$llm.file()

$llm.file(f: LlmFile): any

A generated file (with its bytes) as a PocketBase file: record.set("pictures+", $llm.file(r.files[0])).

Parameter Type
f LlmFile

Returns any.

$llm.fileAsync()

$llm.fileAsync(f: LlmFile): Promise<any>

The same, downloading a file the provider gave only a URL for.

Parameter Type
f LlmFile

Returns Promise<any>.

$llm.fromRecord()

$llm.fromRecord(record: core.Record, field: string): LlmFile

A record's stored file (the first in a file field) as an LlmFile with its bytes, to send to a model: speakAsync({ reference: { audio: $llm.fromRecord(rec, "clip"), text } }).

Parameter Type
record core.Record
field string

Returns LlmFile.

$llm.chat

Stored conversations (llm.chat/v1, the llm-chat extension). Only sendAsync reaches a provider.

$llm.chat.new()

$llm.chat.new(opts?: { title?: string; meta?: Record<string, any> }): string

Starts a chat and returns its id.

Parameter Type
opts { title?: string; meta?: Record<string, any> } (optional)

Returns string.

$llm.chat.open()

$llm.chat.open(id: string, opts?: LlmChatOptions): LlmChat

A stored chat by id, with the options every send uses.

Parameter Type
id string
opts LlmChatOptions (optional)

Returns LlmChat.

$llm.chat.list()

$llm.chat.list(opts?: { meta?: Record<string, any>; limit?: number; offset?: number }): LlmChatInfo[]

Chats, most recently updated first; meta keeps those whose meta has each key with that value.

Parameter Type
opts { meta?: Record<string, any>; limit?: number; offset?: number } (optional)

Returns LlmChatInfo[].

$llm.chat.forget()

$llm.chat.forget(opts: { meta: Record<string, any> }): number

Deletes every chat whose meta matches; returns how many.

Parameter Type
opts { meta: Record<string, any> }

Returns number.

$llm.search

Buckets of the app's content, searched by meaning (llm.search/v1, the llm-search extension). Only searchAsync reaches a provider (it embeds the query); everything else is local (a URL or collection is read in the background).

$llm.search.buckets()

$llm.search.buckets(): SearchBucket[]

Every bucket, by name.

Returns SearchBucket[].

$llm.search.bucket()

$llm.search.bucket(name: string): SearchBucket
Parameter Type
name string

Returns SearchBucket.

$llm.search.ensure()

$llm.search.ensure(o: string | { name: string; title?: string; description?: string; owner?: string }): SearchBucket

Makes the bucket if it's missing (call it at startup for the bucket your app needs) and returns it.

Parameter Type
o string | { name: string; title?: string; description?: string; owner?: string }

Returns SearchBucket.

$llm.search.update()

$llm.search.update(o: { name: string; title?: string; description?: string; maxDocuments?: number; maxBytes?: number }): SearchBucket
Parameter Type
o { name: string; title?: string; description?: string; maxDocuments?: number; maxBytes?: number }

Returns SearchBucket.

$llm.search.deleteBucket()

$llm.search.deleteBucket(name: string): number

Deletes a bucket and everything in it.

Parameter Type
name string

Returns number.

$llm.search.sources()

$llm.search.sources(bucket: string): SearchSource[]

A bucket's sources: files, text, folders, zips, pages, repositories, collections.

Parameter Type
bucket string

Returns SearchSource[].

$llm.search.add()

$llm.search.add(o: { bucket: string; name: string; text: string; kind?: "file" | "text"; replace?: string }): SearchSource

Adds a file or text as its own source (replacing the source of that name, or the one named by replace).

Parameter Type
o { bucket: string; name: string; text: string; kind?: "file" | "text"; replace?: string }

Returns SearchSource.

$llm.search.addURL()

$llm.search.addURL(o: { bucket: string; url: string; kind?: "page" | "git"; every?: "hour" | "day" | "week"; commits?: number; exclude?: string[] }): SearchSource

Adds a web page or a Git repository (kind decided from the URL), read now and every hour, day or week.

Parameter Type
o { bucket: string; url: string; kind?: "page" | "git"; every?: "hour" | "day" | "week"; commits?: number; exclude?: string[] }

Returns SearchSource.

$llm.search.follow()

$llm.search.follow(o: { bucket: string; collection: string; fields: string[]; filter?: string }): SearchSource

Adds a collection: a document per record the filter keeps, kept in sync as records are saved and deleted.

Parameter Type
o { bucket: string; collection: string; fields: string[]; filter?: string }

Returns SearchSource.

$llm.search.addFolder()

$llm.search.addFolder(o: { bucket: string; path: string; include?: string[]; exclude?: string[]; url?: string }): SearchSource

Adds a folder of the app's own files on the server (path relative to the app's folder: "pb_pages/docs"), read now and again every few minutes. url ("/docs/{path}") links each result to the page its file is published at, with the section's anchor.

Parameter Type
o { bucket: string; path: string; include?: string[]; exclude?: string[]; url?: string }

Returns SearchSource.

$llm.search.refresh()

$llm.search.refresh(bucket: string, source: string): SearchSource

Reads a source again now.

Parameter Type
bucket string
source string

Returns SearchSource.

$llm.search.remove()

$llm.search.remove(bucket: string, sources: string | string[]): number

Takes sources out of a bucket, with their documents.

Parameter Type
bucket string
sources string | string[]

Returns number.

$llm.search.documents()

$llm.search.documents(bucket: string | { bucket: string; source?: string; prefix?: string }): SearchDocument[]
Parameter Type
bucket string | { bucket: string; source?: string; prefix?: string }

Returns SearchDocument[].

$llm.search.sample()

$llm.search.sample(o: string | { buckets?: string | string[]; bucket?: string; count?: number; prefix?: string }): SearchResult[]

Chunks picked at random from the buckets named (every bucket when none): material to draw from, not matches. Local and free (nothing is embedded). count defaults to 5, at most 50; prefix keeps documents whose name starts with it.

Parameter Type
o string | { buckets?: string | string[]; bucket?: string; count?: number; prefix?: string }

Returns SearchResult[].

$llm.search.status()

$llm.search.status(): { model: string; chunks: number; embedded: number; note?: string }

The app's embedding model and how much is embedded.

Returns { model: string; chunks: number; embedded: number; note?: string }.

$llm.search.searchAsync()

$llm.search.searchAsync(o: { query: string; buckets?: string | string[]; bucket?: string; limit?: number; prefix?: string; viewer?: core.Record | null; signal?: AbortSignal })

The best matches for a query across buckets (all of them when none are named), best first. viewer (an auth record, or null for a guest) leaves out records they can't view; left out, the search sees everything.

Parameter Type
o { query: string; buckets?: string | string[]; bucket?: string; limit?: number; prefix?: string; viewer?: core.Record | null; signal?: AbortSignal }

$llm.search.Promise

$llm.search.Promise: 

$llm.ledger

The ledger: what calls used and cost. Local reads (not provider calls), so plain. On $llm.for(e), remaining and spent answer about that request's user or guest; on plain $llm, name a subject (or none: the whole app).

$llm.ledger.remaining()

$llm.ledger.remaining(opts?: { subject?: string }): LlmLimitLeft[]

For each limit in Settings → LLM that counts the subject's calls, how much is used and left: the tightest first.

Parameter Type
opts { subject?: string } (optional)

Returns LlmLimitLeft[].

$llm.ledger.spent()

$llm.ledger.spent(window?: "day" | "month" | LlmLedgerWindow & { subject?: string; kind?: string; model?: string }): LlmTotals

What the subject's calls used: "day" or "month" (UTC), or { since, until }; optionally one kind or model.

Parameter Type
window "day" | "month" | LlmLedgerWindow & { subject?: string; kind?: string; model?: string } (optional)

Returns LlmTotals.

$llm.ledger.summary()

$llm.ledger.summary(opts?: LlmLedgerWindow & { by?: "model" | "kind" | "subject" | "day"; subject?: string; kind?: string; model?: string; limit?: number }): (LlmTotals & { key: string })[]

Totals grouped by model (the default), kind, subject or day, the costliest (or, by day, latest) first.

Parameter Type
opts LlmLedgerWindow & { by?: "model" | "kind" | "subject" | "day"; subject?: string; kind?: string; model?: string; limit?: number } (optional)

Returns (LlmTotals & { key: string })[].

$llm.ledger.calls()

$llm.ledger.calls(opts?: LlmLedgerWindow & { subject?: string; kind?: string; model?: string; status?: "ok" | "refused"; limit?: number; offset?: number }): { calls: LlmLedgerCall[]; more: boolean }

The ledger's rows, newest first.

Parameter Type
opts LlmLedgerWindow & { subject?: string; kind?: string; model?: string; status?: "ok" | "refused"; limit?: number; offset?: number } (optional)

Returns { calls: LlmLedgerCall[]; more: boolean }.

$llm.for()

$llm.for(e: core.RequestEvent | { req: { event: core.RequestEvent } }): LlmAPI

The same API with every call counted for the request's signed-in user, else its guest: pass a page's ctx or a route's e.

Parameter Type
e core.RequestEvent | { req: { event: core.RequestEvent } }

Returns LlmAPI.

$llm.onCall()

$llm.onCall(handler: (e: LlmCallEvent) => void | Promise<void>): void

Runs before every call that reaches a provider, every kind: change e.model, e.subject or e.input, then e.next(); or throw e.refuse("...") to refuse it. Runs before the limits in Settings → LLM, which count what it settled on.

Parameter Type
handler (e: LlmCallEvent) => void | Promise<void>

$llm.onCallDone()

$llm.onCallDone(handler: (e: LlmCallDoneEvent) => void | Promise<void>): void

Runs after every call that reached a provider, with what it used and cost. It can't refuse; the call happened.

Parameter Type
handler (e: LlmCallDoneEvent) => void | Promise<void>

Types

LlmFile

A generated or sent file: data is base64. $llm.file(f) makes it a PocketBase file for record.set.

type LlmFile = { name?: string; type?: string; data?: string; url?: string }

LlmUsage

type LlmUsage = { inputTokens?: number; outputTokens?: number; cachedTokens?: number; reasoningTokens?: number; seconds?: number; /** what the call cost, in millionths of a US dollar (1000000 = $1); 0 when free or not known */ costMicroUSD: number; costEstimated?: boolean }

LlmModels

Member Type
models { id: string; provider: string; type: string; name?: string; kinds: string[]; inputs?: string[]; reasoning?: boolean; contextTokens?: number; /** USD per unit ("1M input tokens", "1M output tokens", "1M cached input tokens", "1M tokens", "second", "megapixel", * "image", "1K characters", "request"): listed by the provider, or measured from this app's billed calls (calls: how * many). None: the price isn't known. */ prices?: { unit: string; usd: number; source?: "listed" | "measured"; calls?: number }[]; description?: string; /** parameters, as its maker names them: "1.7B", "30B (3B active)" */ size?: string; /** "tools", "structured output", "vision", "audio input", "voice cloning", "voice design", "built-in voices", "lyrics" */ features?: string[]; /** ISO 639-1 codes */ languages?: string[] }[]

LlmJob

type LlmJob = { id: string; status: "queued" | "running" | "done" | "failed"; progress?: number; files?: LlmFile[]; outputs?: number; error?: string; model: string; usage: LlmUsage }

LlmMessage

type LlmMessage = { role: "system" | "user" | "assistant"; content: string }

LlmTextInput

Member Type
model string "provider/model", e.g. "vultr/glm-5.3".
enrich? LlmEnrich
system? string
prompt? string
messages? LlmMessage[]
schema? object | string A JSON schema the answer must match; the parsed answer is then in data.
maxTokens? number
temperature? number
stop? string[]
reasoning? "" | "off" | "low" | "medium" | "high" How much a reasoning model thinks first: "" (its default), "off", "low", "medium", "high".
options? Record<string, any> The provider's own fields, passed through.
signal? AbortSignal Cancels the call, provider request included: the promise rejects with signal.reason.

LlmPassage

A passage enrich added to the prompt, from a search bucket.

type LlmPassage = { bucket: string; document: string; heading?: string; text: string; score: number }

LlmEnrich

Adds the best passages from the app's search buckets after the prompt: the buckets, or { buckets, limit?, query? }.

type LlmEnrich = string[] | { buckets: string[]; limit?: number; query?: string; /** who the answer is for (ctx.auth, or null for a guest): passages from records they can't view are left out */ viewer?: core.Record | null }

LlmTextAnswer

type LlmTextAnswer = { text: string; data?: any; reasoning?: string; stopReason?: string; model: string; usage: LlmUsage; /** what enrich added to the prompt, best first */ passages?: LlmPassage[] }

LlmModelsOpts

type LlmModelsOpts = { provider?: string; signal?: AbortSignal }

LlmLedgerWindow

type LlmLedgerWindow = { window?: "day" | "month"; since?: string; until?: string }

LlmTotals

type LlmTotals = { calls: number; refused: number; input: number; cached: number; output: number; seconds: number; costMicroUSD: number }

LlmLimitLeft

Member Type
limit string The limit in words: "each guest, $0.10 a day".
scope "app" | "user" | "guest" | "guests"
window "day" | "month"
metric "cost" | "input" | "output" | "calls"
kind? string
model? string
amount number In the metric's unit: US dollars for cost, else tokens or calls.
used number
left number
resets string When the window ends (RFC 3339, UTC).

LlmLedgerCall

Member Type
id string; created: string; kind: string; model: string; subject: string; via: string
input number; cached: number; output: number; seconds: number; costMicroUSD: number; estimated: boolean
refused? string Why a limit refused the call.
job? string

LlmCallEvent

A billable call on its way to a provider, as $llm.onCall handlers see it.

Member Type
kind "text" | "image" | "speech" | "transcribe" | "align" | "music" | "video" | "embed"
op string The operation: "complete", "stream", "generate", "speak", "transcribe", "align", "create" or "embed".
model string "provider/model"; change it to send the call to another model.
subject string Whom the call is for: "user:/", "guest:", "guest:ip:
", "" or your own ("team:acme"). Change it to count the call elsewhere.
user { collection: string; id: string } | null The signed-in user the call is for, or null.
guest boolean The call is for a guest.
input Record<string, any> The operation's input (prompt, maxTokens, ...); change it as you like.
guestsCapped boolean Set it when this handler caps what guests may spend, so guest calls don't need a limit on all guests together.
next() (): void Lets the call go on. A handler that neither calls it nor throws refuses the call.
refuse() (message: string): Error An error refusing the call with your message (code "limit", 429): throw e.refuse("...").

LlmCallDoneEvent

A call that reached a provider, as $llm.onCallDone handlers see it.

Member Type
kind string
op string
model string
subject string
user { collection: string; id: string } | null
guest boolean
usage LlmUsage What it used; usage.costMicroUSD is what it cost, in millionths of a dollar.
job? string A music or video job's id (its event comes once the job is done and its cost known).
next() (): void

SearchBucket

type SearchBucket = { name: string; title: string; description: string; owner: string; maxDocuments: number; maxBytes: number; sources: number; documents: number; chunks: number; bytes: number; pending: number; errors: number; created: string; updated: string }

SearchSource

type SearchSource = { bucket: string; name: string; kind: "file" | "text" | "folder" | "dir" | "zip" | "page" | "git" | "collection"; url?: string; every?: "hour" | "day" | "week"; commits?: number; exclude?: string[]; path?: string; include?: string[]; pageURL?: string; collection?: string; fields?: string[]; filter?: string; hash?: string; status: "reading" | "ready" | "error"; error?: string; documents: number; chunks: number; bytes: number; pending: number; costMicroUSD: number; refreshed?: string; next?: string; created: string }

SearchRecordRef

type SearchRecordRef = { collection: string; id: string }

SearchDocument

type SearchDocument = { bucket: string; source: string; name: string; kind: "markdown" | "code" | "text"; size: number; hash: string; status: "queued" | "embedding" | "ready" | "error"; error?: string; chunks: number; record?: SearchRecordRef; tokens: number; costMicroUSD: number; created: string; updated: string }

SearchResult

type SearchResult = { bucket: string; source: string; document: string; text: string; heading?: string; startLine: number; endLine: number; record?: SearchRecordRef; /** where the passage is published: a web page's URL, or a server folder's url pattern with the section's anchor */ url?: string; score: number }

LlmChatOptions

Member Type
model? string "provider/model": every send needs one, here or on the send.
enrich? LlmEnrich passages from search buckets, added after each question (and saved with it)
reasoning? "" | "off" | "low" | "medium" | "high"
system? string
context? string | ((question: string) => string) Sent after the question (history shows the question alone): text, or a function of the question.
window? number Messages sent before the summary takes over (default 12).
summarizeEvery? number Fold the oldest messages into the summary once this many are past the window (default 6).
maxTokens? number
temperature? number

LlmChatInfo

type LlmChatInfo = { id: string; title: string; summary: string; meta: any; messages: number; created: string; updated: string }

LlmChat

Member Type
id string
sendAsync() (text: string, opts?: LlmChatOptions & { onText?: (text: string) => boolean | void; onReasoning?: (text: string) => boolean | void; schema?: object | string; signal?: AbortSignal }): Promise<LlmTextAnswer> Asks and saves both turns. With onText, streams the answer to it as it's written.
get() (): LlmChatInfo
history() (opts?: { limit?: number; before?: string }): { id: string; role: "user" | "assistant"; content: string; created: string }[]
summary() (): string
title() (text?: string): string
meta() (obj?: Record<string, any>): any
forget() (): void