Commands
Section titled “Commands”pbkit generate
Section titled “pbkit generate”Generate types and SDK from your pbkit.config.ts.
bunx pbkit generateOptions
Section titled “Options”| Flag | Short | Description |
|---|---|---|
--config <path> | -c | Path to a config file (defaults to auto-detection) |
--watch | -w | Watch mode — regenerates every 10 seconds |
--help | -h | Show help message |
pbkit schema
Section titled “pbkit schema”Manage PocketBase collection definitions directly against the admin API
(/api/collections). Schema-only — record CRUD is intentionally out of scope.
pbkit schema list # list all collections (name + type)pbkit schema get <collection> # dump one collection as JSONpbkit schema pull [--out pb-schema.json]# download the full snapshot the generator readspbkit 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>"Subcommands
Section titled “Subcommands”| Command | Description |
|---|---|
list | List 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 |
Options
Section titled “Options”| Flag | Description |
|---|---|
--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-missing | For 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.
Authentication
Section titled “Authentication”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.
| Variable | Purpose |
|---|---|
POCKETBASE_URL | PocketBase base URL |
POCKETBASE_ADMIN_EMAIL | Superuser email (used with the password) |
POCKETBASE_ADMIN_PASSWORD | Superuser password |
POCKETBASE_ADMIN_TOKEN | Pre-issued admin token (alternative to email/password) |
pbkit logs
Section titled “pbkit logs”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.
pbkit logs # last 50 logs, oldest firstpbkit logs -n 200 --level warn # last 200 warnings and errorspbkit logs --since 1h --errors # failing requests and error logs from the last hourpbkit logs --slow 1000 -v # requests that took 1s or more, with detailspbkit logs --filter 'data.status>=500'pbkit logs -f # keep printing new logs as they arrivepbkit logs --json | jq . # raw records, one JSON object per linepbkit logs get <id> # one log as pretty JSONpbkit logs stats [--since 24h] # hourly log countspbkit logs top [--since 24h] # per-endpoint calls, errors and latencyEach 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.
Options
Section titled “Options”| Flag | Short | Description |
|---|---|---|
--limit <n> | -n | How 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 | |
--errors | Only failing requests (status 400 and up) and error-level logs | |
--filter <expr> | Any PocketBase filter (e.g. data.status>=400) | |
--include-self | Also show the CLI’s own /api/logs requests (hidden by default) | |
--verbose | -v | Print a second, indented line under request logs with auth, IP, referer, userAgent and details (empty fields are left out) |
--json | Print raw records, one JSON object per line | |
--follow | -f | Poll every 2 seconds and print new logs as they arrive |
--config <path> | -c | Config 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.
pbkit logs top
Section titled “pbkit logs top”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.
| Flag | Short | Description |
|---|---|---|
--since <dur> | Time window (default 1h) | |
--sort <key> | latency (p95, the default), errors or calls | |
--limit <n> | -n | Rows to show (default 20) |
--max <n> | Stop after fetching this many logs (default 20000) | |
--slow, --errors, --level, --filter, --include-self | Same as for pbkit logs | |
--json | Print the summary as JSON |
Percentiles use the nearest-rank method, so each value is a real request time from the window.
Finding slow or failing endpoints
Section titled “Finding slow or failing endpoints”Start with the overview, then look at the individual requests:
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 themUse 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.
topdownloads 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--maxlogs (default 20000) and warns you that the result is partial. Narrow--sinceor raise--maxif that happens.
Config auto-detection
Section titled “Config auto-detection”pbkit searches for a config file in the current working directory in this order:
pbkit.config.tspbkit.config.jspbkit.config.mjs
Watch mode
Section titled “Watch mode”bunx pbkit generate --watchIn 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.
Custom config path
Section titled “Custom config path”bunx pbkit generate --config ./configs/pbkit.config.tsExit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
0 | Success |
1 | Error (config not found, API error, invalid config) |
Example output
Section titled “Example output”$ bunx pbkit generate src/generated/types.gen.ts src/generated/client.gen.ts src/generated/sdk.gen.tsGenerated 3 file(s) in 120ms