kv/v1

An app's key-value store: a name and a JSON value, kept without a collection or a migration. Use it for an app's settings, a feature's state, anything that is one blob rather than many records. Each value is a row in PocketBase's own _params table, so it rides along in backups.

A wire contract (kv.go) plus Go helpers (helpers.go).

Use

From Go (an extension, a hook), call the helpers. They need no provider and work inside a transaction when given one:

var s Settings
found, err := kvv1.Get(app, "storytime/settings", &s) // found is false and s untouched when there's no value
err = kvv1.Set(app, "storytime/settings", s)          // any value json.Marshal takes
err = kvv1.Delete(app, "storytime/settings")          // no error when there was no value
entries, err := kvv1.List(app, "storytime/")          // by name prefix, sorted by name; "" lists all (private too)
e, found, err := kvv1.Lookup(app, "storytime/settings") // the raw entry, with created and updated

Declare WorksWith: extkit.IDs("kv/v1") when you do.

From page code and pb_hooks, the provider gives $kv (sync, local):

const settings = $kv.get("storytime/settings") ?? defaults // the parsed value, or null
$kv.set("storytime/settings", { title: "Story Time", minutes: 10 })
$kv.delete("storytime/settings")
$kv.list("storytime/") // [{ name, value, created, updated }]

Over HTTP (superusers, or an API token with the scope):

Operation HTTP Token scope
List GET /api/_c/kv/v1?prefix=storytime/ kv:read
Get GET /api/_c/kv/v1/get?name=storytime/settings kv:read
Set POST /api/_c/kv/v1/set with {"name": "storytime/settings", "value": {...}} kv
Delete POST /api/_c/kv/v1/delete with {"name": "storytime/settings"} kv

Get answers 404 not_found for a name with no value. The same operations are pocketone remote kv ... commands and MCP tools (kv_list, kv_get, kv_set, kv_delete).

Names are 1 to 128 characters: letters, digits and _ - . : /, starting with a letter or digit. Start yours with a prefix of your own (storytime/, myext:) so they stay apart from other apps' and extensions'. A value is any JSON up to 1 MiB.

Private names start with _ (_myext/settings): the Go helpers read and write them, but the wire API (HTTP, the CLI, MCP) and $kv refuse them (403 private) and leave them out of lists. Keep secrets there, such as API keys and signing keys, which a kv:read token must never see.

Moving an extension's own row: an extension that kept a _params row of its own before kv/v1 moves it once with kvv1.MoveParamOnce(app, "oldrow", "_myext/settings") before reading (MoveParam for a one-off): the value and its times move to the name and the old row goes away.

Storage: name storytime/settings is the _params row with id kv:storytime/settings, its value the row's value. The kv: prefix keeps every name apart from PocketBase's own params (settings) and from rows extensions keep there themselves. Write through the helpers, never the table, so the rules above hold.

Provide

The wire API and $kv: ext/kv provides kvv1.Store by default, over the helpers. Another provider implements kvv1.Store and provides it in Register (kvv1.Contract.Provide(app, s)); it must keep the storage above, since the helpers read and write it directly.

Commands and APIs

Every operation is a REST endpoint, a pocketone command and an MCP tool, all generated from the contract and behind the same token scope check and hooks. See Remote CLI, or the full CLI, Extension APIs and MCP references.

list

Returns the values whose names start with prefix (all of them when it's empty), sorted by name. Private names (starting with _) are left out.

REST GET /api/_c/kv/v1
CLI pocketone remote kv list --prefix <value>
MCP kv_list
Token scope kv:read
Input field Flag Type
prefix --prefix string

get

Returns one value. A name with no value is a not_found error; a private name is a private error.

REST GET /api/_c/kv/v1/get
CLI pocketone remote kv get --name <value>
MCP kv_get
Token scope kv:read
Input field Flag Type
name --name string

set

Stores a JSON value under a name, replacing any value it had.

REST POST /api/_c/kv/v1/set
CLI pocketone remote kv set --name <value> --value <json>
MCP kv_set
Token scope kv
Input field Flag Type
name --name string
value --value json

delete

Removes a value. Deleting a name with no value is not an error.

REST POST /api/_c/kv/v1/delete
CLI pocketone remote kv delete --name <value>
MCP kv_delete
Token scope kv
Input field Flag Type
name --name string

Extensions

Extension
kv provides (default)
api-tokens works with
billing works with
bulkmail works with
creem works with
llm works with
llm-search works with
paddle works with
stripe works with

License

MIT