Skip to content

CLI

pbkit command-line interface reference.

Generate types and SDK from your pbkit.config.ts.

Terminal window
bunx pbkit generate
FlagShortDescription
--config <path>-cPath to a config file (defaults to auto-detection)
--watch-wWatch mode — regenerates every 10 seconds
--help-hShow help message

Manage PocketBase collection definitions directly against the admin API (/api/collections). Schema-only — record CRUD is intentionally out of scope.

Terminal window
pbkit schema list # list all collections (name + type)
pbkit schema get <collection> # dump one collection as JSON
pbkit schema pull [--out pb-schema.json]# download the full snapshot the generator reads
pbkit schema apply <file.json> # import definitions (non-destructive)
pbkit schema add-field <collection> <json>
pbkit schema add-index <collection> "<sql>"
pbkit schema set-rule <collection> [--list <rule>] [--view <rule>] [--create <rule>] [--update <rule>] [--delete <rule>]
pbkit schema create-view <name> --query "<sql>"
CommandDescription
listList every collection with its name and type
get <collection>Print one collection (fields, indexes, rules, viewQuery) as JSON
pull [--out <file>]Write the full schema snapshot (default pb-schema.json) — the same shape pbkit generate consumes
apply <file>Import collection definitions via PUT /api/collections/import
add-field <collection> <json>Append a field, preserving the existing fields array
add-index <collection> "<sql>"Append an index, merging with existing indexes
set-rule <collection> --list/--view/--create/--update/--delete <rule>Update API rules (only the provided ones)
create-view <name> --query "<sql>"Create a view collection
FlagDescription
--config <path>Config file used for fallback URL/token (auth env vars take precedence)
--out <file>Output path for pull (default pb-schema.json)
--delete-missingFor apply, remove collections absent from the file (default off)
--query <sql>View query for create-view
--list/--view/--create/--update/--delete <rule>Rules for set-rule

apply is non-destructive by default (deleteMissing: false). Partial operations (add-field, add-index, set-rule) fetch the current collection and patch it, so they never clobber unrelated fields, indexes, or rules. For set-rule, a rule value of "null" makes the rule superuser-only and "" makes it public.

Schema commands authenticate as a superuser (_superusers/auth-with-password). Credentials are read from the environment (preferred), falling back to the pbkit.config.ts API input — never inline.

VariablePurpose
POCKETBASE_URLPocketBase base URL
POCKETBASE_ADMIN_EMAILSuperuser email (used with the password)
POCKETBASE_ADMIN_PASSWORDSuperuser password
POCKETBASE_ADMIN_TOKENPre-issued admin token (alternative to email/password)

Read PocketBase’s request and app logs from the admin API (/api/logs), like tail for your server. Uses the same superuser authentication as pbkit schema.

Terminal window
pbkit logs # last 50 logs, oldest first
pbkit logs -n 200 --level warn # last 200 warnings and errors
pbkit logs --since 1h --errors # failing requests and error logs from the last hour
pbkit logs --slow 1000 -v # requests that took 1s or more, with details
pbkit logs --filter 'data.status>=500'
pbkit logs -f # keep printing new logs as they arrive
pbkit logs --json | jq . # raw records, one JSON object per line
pbkit logs get <id> # one log as pretty JSON
pbkit logs stats [--since 24h] # hourly log counts
pbkit logs top [--since 24h] # per-endpoint calls, errors and latency

Each log prints on one line: time, level, then for request logs the method, status, URL and how long the request took (12ms, 1.4s); other logs show their message. If the log has an error, it is appended at the end. In a terminal, slow requests stand out: latency is yellow above 500ms and red above 2s. Colors are turned off when output is piped or NO_COLOR is set.

FlagShortDescription
--limit <n>-nHow many recent logs to show (default 50)
--since <dur>Only logs from the last 30m, 1h, 24h, 7d, …
--level <name>Minimum level: debug, info, warn or error
--slow <ms>Only requests that took at least this many milliseconds
--errorsOnly failing requests (status 400 and up) and error-level logs
--filter <expr>Any PocketBase filter (e.g. data.status>=400)
--include-selfAlso show the CLI’s own /api/logs requests (hidden by default)
--verbose-vPrint a second, indented line under request logs with auth, IP, referer, userAgent and details (empty fields are left out)
--jsonPrint raw records, one JSON object per line
--follow-fPoll every 2 seconds and print new logs as they arrive
--config <path>-cConfig file used for fallback URL/token (auth env vars take precedence)

All the narrowing flags (--since, --level, --slow, --errors, --filter) combine with AND. stats accepts --since, --filter and --json.

PocketBase writes logs to its database in batches, so with --follow new entries can show up a few seconds after the request happened. That is normal.

Groups request logs by method and route and shows, per endpoint: number of calls, number of errors (status 400 and up), and the p50, p95 and max request time. Routes are normalized so they group well: the query string is dropped, record ids become :id, and file URLs become /api/files/<collection>/:id/:file.

FlagShortDescription
--since <dur>Time window (default 1h)
--sort <key>latency (p95, the default), errors or calls
--limit <n>-nRows to show (default 20)
--max <n>Stop after fetching this many logs (default 20000)
--slow, --errors, --level, --filter, --include-selfSame as for pbkit logs
--jsonPrint the summary as JSON

Percentiles use the nearest-rank method, so each value is a real request time from the window.

Start with the overview, then look at the individual requests:

Terminal window
pbkit logs top --since 24h # which endpoints are slow or failing?
pbkit logs --slow 1000 -v # the requests that took 1s or more, with who made them

Use pbkit logs top --sort errors to rank by failures instead of latency.

For a step-by-step walkthrough, see Find slow endpoints.

Two things to keep in mind:

  • The timing is for the whole HTTP request as PocketBase saw it, not for individual SQL queries. A slow endpoint tells you where to look, not which query is to blame.
  • top downloads the logs in the window to your machine and does the math there. It asks only for the fields it needs and pages gently, but on a busy server it stops at --max logs (default 20000) and warns you that the result is partial. Narrow --since or raise --max if that happens.

pbkit searches for a config file in the current working directory in this order:

  1. pbkit.config.ts
  2. pbkit.config.js
  3. pbkit.config.mjs
Terminal window
bunx pbkit generate --watch

In watch mode, pbkit polls the API (or re-reads the file) every 10 seconds and regenerates if the schema has changed. Press Ctrl+C to stop.

Terminal window
bunx pbkit generate --config ./configs/pbkit.config.ts
CodeMeaning
0Success
1Error (config not found, API error, invalid config)
$ bunx pbkit generate
src/generated/types.gen.ts
src/generated/client.gen.ts
src/generated/sdk.gen.ts
Generated 3 file(s) in 120ms