LLM
Version 0.1.0 · Owners: @benallfree
LLM gives your app cloud models to call, one kind at a time: text, pictures, speech, transcription, music, video and
embeddings. You add providers in Settings → LLM, each with your own key, and every call names its model as
provider/model:
const r: LlmTextAnswer = await $llm.text.completeAsync({ model: "vultr/glm-5.3", prompt: "Summarize: " + body, reasoning: "off" })
const pic = await $llm.image.generateAsync({ model: "or/black-forest-labs/flux.2-klein-4b", prompt: "a lighthouse at dusk, watercolor" })
record.set("cover", $llm.file(pic.files[0]))
r, err := textv1.Contract.Must(app).Complete(ctx, extkit.Internal, textv1.CompleteInput{
Model: "vultr/glm-5.3", Prompt: "Summarize: " + body, Reasoning: "off"})
vultr is the name you gave a provider; what follows the first slash is that provider's own id for the model. Any
call can name any model of any provider, so one app can use two picture providers, or a cheap text model for labels and
a large one for writing.
Providers come in four types:
| Type | What it reaches |
|---|---|
vultr |
Vultr Serverless Inference: every kind, music, video and alignment included. |
cloudflare |
Workers AI on your Cloudflare account: text, pictures, speech, transcription and embeddings. |
openrouter |
OpenRouter: hundreds of models behind one key; text, pictures, speech, transcription, video and embeddings. |
openai |
Any API shaped like OpenAI's: OpenAI itself, Groq, Together, or Ollama and llama-server on localhost. Add as many as you like. |
The answers come from your provider accounts, on your keys; PocketOne adds no limits or charges.
Install · Configure · Use · Integrations · Example
Install
LLM is built into pocketone and on in every app and every instance of a host (a standard member). It does nothing
until you add a provider. In your own Go build:
extkit.Setup(app, []extkit.Extension{llm.New()}, nil, nil)
The module is pocketone.dev/ext/llm.
Configure
Settings → LLM (superusers) lists your providers. Press New provider, pick its type, give it a name (the part
before the slash in a model) and enter its key: an endpoint for openai providers (with its version path, like
https://api.groq.com/openai/v1), the account ID for Cloudflare (with a token that has Workers AI permission). Vultr,
Cloudflare and OpenRouter providers can't be saved without a key; an openai one can (a local Ollama has none). Each
provider's Test checks its key, typed or saved, without spending anything, and its check mark turns green when it
passes. Saving applies at once.
Keys stay on the server: the screen never shows a saved key again, and a key is never sent to an endpoint other than the
one it was entered for (change a provider's endpoint and you enter its key again). The settings are in the app's
key-value store, under the private name _llm/settings (only Go code reaches it; the kv/v1 API
and $kv don't).
Under the providers, Limits cap what the app spends: the whole app, each signed-in user, each guest or all guests
together, at most so many US dollars, output tokens, input tokens or calls a UTC day or month, optionally for one kind
or model. Every call passes them before it reaches a provider, and a used-up limit refuses it with code limit (429).
Page code says whom a call is for with $llm.for(ctx) (a page's ctx or a route's e): its signed-in user, or else a
guest told apart by a signed cookie. Guest calls are refused until there's a limit for all guests together. Every call
is recorded in the _llm_calls collection, and the screen shows today's and this month's spend from it
(Limits, Users and guests). $llm.ledger reads it: what's left of
each limit, what someone spent, totals by model or person (Spend and the ledger). The screen's
limits are the built-in handler on $llm.onCall; your own handlers there add plan tiers, credits or anything else
(Custom limits).
There's no pocketone.yaml configuration besides the switch: llm: {enabled: false} turns it off on a single app (on a
host, an instance's extensions.llm), and with it $llm and the llm.* contracts.
pocketone.yaml reference
llm:
Cloud models for $llm (the llm.* contracts); providers and keys are set in Settings → LLM.
| Key | Type | Default | Description |
|---|---|---|---|
enabled |
bool | false turns the extension off on this app ($llm and the llm.* contracts are gone). |
Use
In page code it's $llm.<kind>. Every call that reaches a provider is async, and its name says so: await it in an async
handler (await $llm.text.completeAsync({...})). It runs off the app's JS VM, so the app keeps serving other requests
while a model works; there are no blocking versions to reach for. Each call names its model:
| Call | What it does |
|---|---|
$llm.search.searchAsync({ query, buckets?, limit?, viewer? }) and the rest of $llm.search |
Hybrid search over knowledge bases (buckets) of your content, through the LLM Search extension (Search and RAG). |
$llm.text.completeAsync({ model, system?, prompt | messages, schema?, maxTokens?, temperature?, stop?, reasoning?, enrich?, options? }) |
Answers: { text, data, reasoning, stopReason, model, usage, passages }. With schema, data is the parsed JSON. With enrich (RAG: buckets to search, ["help"]), the best passages from them are sent after the prompt and listed in passages (LLM Search). |
$llm.text.streamAsync(opts, onText, onReasoning?) |
The same, calling onText with each piece as it's written (false stops it). |
$llm.text.count(text | messages) |
About how many tokens (four characters each). Local, so not async. |
$llm.image.generateAsync({ model, prompt, references?, n?, size?, aspectRatio? }) |
Pictures: { files, model, usage }. references are pictures to draw from, on models with the feature reference images. |
$llm.speech.speakAsync({ model, text, voice?, format?, speed?, instructions?, reference? }), voicesAsync(model) |
Audio: { file, model, usage }. reference: { audio, text? } reads in the voice of that clip (voice cloning). |
$llm.transcribe.transcribeAsync({ model, audio, language?, prompt? }) |
Text from audio: { text, language, model, usage }. |
$llm.align.alignAsync({ model, audio, text, mode?, language? }) |
When each line and word of text is said in audio: { duration, lines, words, unaligned, model, usage }, in seconds. For captions timed to a voice. |
$llm.music.createAsync({ model, prompt, lyrics?, seconds?, wait? }), getAsync(id), contentAsync(id, index) |
Music, as a job (below). |
$llm.video.createAsync({ model, prompt, image?, seconds?, size?, aspectRatio?, wait? }), getAsync(id), contentAsync(id, index) |
Video, as a job. |
$llm.embed.embedAsync({ model, input, dimensions? }) |
One vector per text: { vectors, model, usage }. |
$llm.<kind>.modelsAsync({ provider? }) |
The models your providers offer of that kind, with their prices, size, features and languages where known (below). |
$llm.file(file), $llm.fileAsync(file) |
A generated file as a PocketBase file, for record.set("field", ...); fileAsync also downloads one the provider gave only a URL for. |
$llm.fromRecord(record, field) |
The other way: a record's stored file as a file with its bytes, to send to a model (a voice clip, audio to transcribe). |
$llm.chat.* |
Stored conversations, from the LLM Chat extension. |
reasoning is how much a reasoning model thinks before answering: "off", "low", "medium", "high", or left
out for the model's own default. Many models think by default, and the thinking counts toward maxTokens: for short
jobs (labels, titles, JSON) say "off", or the answer can come back empty with stopReason: "length".
options passes a provider's own fields through unchanged (seed, steps, OpenRouter's provider routing...), for
what the common fields don't cover.
Files come back as { name, type, data, url }: data is the bytes (base64 in JSON), url the provider's own copy
when it keeps one (it may expire). Audio to transcribe is sent the same way.
Jobs: music and video take a while. createAsync starts one and returns { id, status }; follow it with getAsync(id) until
status is done, then fetch each of its outputs with contentAsync(id, index). Or pass wait: "5m": createAsync then
resolves once the job is done, its files included. The id names the provider
(vultr:music_02a2…), so get finds it again after a restart; the provider keeps the job, not your app.
Cost: every result's usage.costMicroUSD is what the call cost, in millionths of a US dollar (1000000 is $1), a
whole number on every answer of every kind: what the provider charged when it says (OpenRouter on every call, Vultr for
media), else worked out from the model's listed prices and what the call used (tokens, cached tokens, pictures,
seconds, characters), with usage.costEstimated true, else 0 (free, or no prices it can count).
Models and prices: each model in a models answer carries what its provider says about it: contextTokens,
size ("27B", "30B (3B active)"), features (tools, structured output, vision, audio input, voice cloning,
voice design, built-in voices, lyrics), languages, and prices. A price is a rate on one meter, in US dollars
per unit, and every provider's are given in the same units: 1M input tokens, 1M output tokens,
1M cached input tokens, second (of audio or video made, or read), megapixel, image, 1K characters (read
aloud), request. Its source is listed (the provider's own list) or measured: what this app's calls to the model
were actually billed, from the ledger, over calls calls (text in 1M tokens, in and out together, since a bill
doesn't split them; pictures per request). Costs worked out from listed prices never count toward a measured one.
No prices means the price isn't known. Extras a call may not use (web search, cache writes, images sent in) aren't
listed, and a model with a price in a unit that can't be put in these (per inference step) lists none rather than
look cheaper than it is.
Settings → LLM lists every model of each kind across your providers under Models, searchable and cheapest first.
Other dashboard screens use the same pieces through window.pocketone.llm: select({ kind, value, onchange }) is a
searchable dropdown of a kind's models with their prices. Give it the work the model is
for, job: () => ({ "1M input tokens": 0.006, "1M output tokens": 0.002 }) (how much of each price unit the work uses)
and per: "a story", and each model also shows what that work costs on it ("≈ $0.0012 a story", "≥" when it lists only
one side of the tokens), cheapest first. browser({ kinds?, kind? }) is the whole list, and models(kind),
prices(model), priceText(model), rank(model) and costFor(model, job) the data underneath.
Errors have a code: not_configured (no providers yet), unknown_model (no model named, or no provider by that
name), not_supported (that provider type doesn't do this kind), provider (the provider's own error, its message
kept, with the provider's name in front), timeout (the provider didn't answer in time; the request was cancelled).
Text calls always stream from the provider, so a stalled answer fails after a few seconds of silence (10 s on Vultr and
OpenRouter), and every call has an overall limit by kind. To give up sooner, call through
$llm.withContext(ctx) with a TimeoutContext or a CancelContext: when the context ends, the call stops, the
promise rejects with its cause and the provider's request is cancelled (Time limits).
Over HTTP each kind is a contract at /api/_c/llm.<kind>/v1/ (llm.text/v1/complete, llm.image/v1/generate...),
for superusers and for API tokens with the llm scope (llm:read for models, voices, get and content); see
llm.text/v1 and the others in the catalogue.
What each provider type covers:
| Text | Pictures | Speech | Transcription | Music | Video | Embeddings | |
|---|---|---|---|---|---|---|---|
vultr |
yes | yes (and references) | yes, with voices and cloning | yes | yes (job) | yes (job) | yes |
cloudflare |
yes | yes | yes | yes | yes | ||
openrouter |
yes | yes (and references) | yes, with voices and cloning | yes | yes (job) | yes | |
openai |
yes | yes | yes | yes | yes |
An openai provider's model list names only ids, so each model's kind is guessed from its name (whisper is
transcription, tts is speech, embed is embeddings, and so on; anything else is text).
Commands and APIs
Generated from the pocketone binary and the contracts this extension provides.
llm.align/v1
| Operation | CLI | REST | MCP |
|---|---|---|---|
| align | pocketone remote llm align --model <value> --audio <json> --text <value> --mode <value> --language <value> --options <json> |
POST /api/_c/llm.align/v1/align |
llm_align_align |
| models | pocketone remote llm align models --provider <value> |
GET /api/_c/llm.align/v1/models |
llm_align_models |
llm.embed/v1
| Operation | CLI | REST | MCP |
|---|---|---|---|
| embed | pocketone remote llm embed --model <value> --input <a,b> --dimensions <n> --options <json> |
POST /api/_c/llm.embed/v1/embed |
llm_embed_embed |
| models | pocketone remote llm embed models --provider <value> |
GET /api/_c/llm.embed/v1/models |
llm_embed_models |
llm.image/v1
| Operation | CLI | REST | MCP |
|---|---|---|---|
| generate | pocketone remote llm image generate --model <value> --prompt <value> --n <n> --size <value> --aspectratio <value> --references <json> --options <json> |
POST /api/_c/llm.image/v1/generate |
llm_image_generate |
| models | pocketone remote llm image models --provider <value> |
GET /api/_c/llm.image/v1/models |
llm_image_models |
llm.ledger/v1
| Operation | CLI | REST | MCP |
|---|---|---|---|
| remaining | pocketone remote llm ledger remaining --subject <value> |
GET /api/_c/llm.ledger/v1/remaining |
llm_ledger_remaining |
| spent | pocketone remote llm ledger spent --subject <value> --window <value> --since <value> --until <value> --kind <value> --model <value> |
GET /api/_c/llm.ledger/v1/spent |
llm_ledger_spent |
| summary | pocketone remote llm ledger summary --by <value> --window <value> --since <value> --until <value> --subject <value> --kind <value> --model <value> --limit <n> |
GET /api/_c/llm.ledger/v1/summary |
llm_ledger_summary |
| calls | pocketone remote llm ledger calls --window <value> --since <value> --until <value> --subject <value> --kind <value> --model <value> --status <value> --limit <n> --offset <n> |
GET /api/_c/llm.ledger/v1/calls |
llm_ledger_calls |
llm.music/v1
| Operation | CLI | REST | MCP |
|---|---|---|---|
| create | pocketone remote llm music create --model <value> --prompt <value> --lyrics <value> --seconds <n> --wait <value> --options <json> |
POST /api/_c/llm.music/v1/create |
llm_music_create |
| get | pocketone remote llm music get --id <value> |
POST /api/_c/llm.music/v1/get |
llm_music_get |
| content | pocketone remote llm music content --id <value> --index <n> |
POST /api/_c/llm.music/v1/content |
llm_music_content |
| models | pocketone remote llm music models --provider <value> |
GET /api/_c/llm.music/v1/models |
llm_music_models |
llm.speech/v1
| Operation | CLI | REST | MCP |
|---|---|---|---|
| speak | pocketone remote llm speech speak --model <value> --text <value> --voice <value> --format <value> --speed <n> --instructions <value> --reference <json> --options <json> |
POST /api/_c/llm.speech/v1/speak |
llm_speech_speak |
| voices | pocketone remote llm speech voices --model <value> |
POST /api/_c/llm.speech/v1/voices |
llm_speech_voices |
| models | pocketone remote llm speech models --provider <value> |
GET /api/_c/llm.speech/v1/models |
llm_speech_models |
llm.text/v1
| Operation | CLI | REST | MCP |
|---|---|---|---|
| complete | pocketone remote llm text complete --model <value> --system <value> --prompt <value> --messages <json> --schema <json> --maxtokens <n> --temperature <json> --stop <a,b> --reasoning <value> --options <json> --enrich <json> |
POST /api/_c/llm.text/v1/complete |
llm_text_complete |
| stream | pocketone remote llm text stream --model <value> --system <value> --prompt <value> --messages <json> --schema <json> --maxtokens <n> --temperature <json> --stop <a,b> --reasoning <value> --options <json> --enrich <json> |
POST /api/_c/llm.text/v1/stream |
llm_text_stream |
| count | pocketone remote llm text count --model <value> --text <value> --system <value> --messages <json> |
POST /api/_c/llm.text/v1/count |
llm_text_count |
| models | pocketone remote llm text models --provider <value> |
GET /api/_c/llm.text/v1/models |
llm_text_models |
llm.transcribe/v1
| Operation | CLI | REST | MCP |
|---|---|---|---|
| transcribe | pocketone remote llm transcribe --model <value> --audio <json> --language <value> --prompt <value> --options <json> |
POST /api/_c/llm.transcribe/v1/transcribe |
llm_transcribe_transcribe |
| models | pocketone remote llm transcribe models --provider <value> |
GET /api/_c/llm.transcribe/v1/models |
llm_transcribe_models |
llm.video/v1
| Operation | CLI | REST | MCP |
|---|---|---|---|
| create | pocketone remote llm video create --model <value> --prompt <value> --image <json> --seconds <n> --size <value> --aspectratio <value> --wait <value> --options <json> |
POST /api/_c/llm.video/v1/create |
llm_video_create |
| get | pocketone remote llm video get --id <value> |
POST /api/_c/llm.video/v1/get |
llm_video_get |
| content | pocketone remote llm video content --id <value> --index <n> |
POST /api/_c/llm.video/v1/content |
llm_video_content |
| models | pocketone remote llm video models --provider <value> |
GET /api/_c/llm.video/v1/models |
llm_video_models |
JavaScript API
What it adds to pb_hooks and page code: LLM JavaScript API.
Integrations
| With | What happens |
|---|---|
| LLM Chat | Stored conversations on top of llm.text/v1: $llm.chat.new(), $llm.chat.open(id).sendAsync(text). |
| Settings | Settings → LLM is its settings/v1 section. |
| API Tokens | A token with the llm scope can call the contracts over HTTP, and MCP clients get them as tools. |
| Multisite | Each instance has its own Settings → LLM, providers and keys. |
Example
The example is a PocketBase app with LLM that, once you've added a provider named vultr in Settings → LLM, answers
one question at start-up and logs it.
// Command example is a PocketBase app with the llm extension. Add a provider named "vultr" in Settings → LLM (or
// change the model below), run `go run . serve`, and watch the log for "llm: answer".
package main
import (
"context"
"log"
"ganigeorgiev.com/pocketbase/pocketbase"
"ganigeorgiev.com/pocketbase/pocketbase/core"
textv1 "pocketone.dev/ext/contracts/llm/text/v1"
"pocketone.dev/ext/devusers"
"pocketone.dev/ext/extkit"
"pocketone.dev/ext/llm"
)
func main() {
app := pocketbase.New()
devusers.Register(app)
if _, err := extkit.Setup(app, []extkit.Extension{llm.New()}, nil, nil); err != nil {
log.Fatal(err)
}
app.OnServe().BindFunc(func(e *core.ServeEvent) error {
go func() {
res, err := textv1.Contract.Must(app).Complete(context.Background(), extkit.Internal, textv1.CompleteInput{
Model: "vultr/glm-5.3", Prompt: "In one sentence: what is PocketBase?", MaxTokens: 200, Reasoning: "off"})
app.Logger().Info("llm: answer", "text", res.Text, "model", res.Model, "error", err)
}()
return e.Next()
})
if err := app.Start(); err != nil {
log.Fatal(err)
}
}
The ask starter kit (pocketone pages create mydocs --starter ask) is a whole PocketOne app
(no Go) on $llm: it answers questions from a folder of Markdown docs kept in an LLM Search bucket, citing its pages.
License
MIT
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.