Generate a fully typed SDK from your PocketBase schema, then read a record, list records, and create one.
In this tutorial you will point pbkit at a PocketBase instance, generate a typed SDK, and use it to read, list, and create records. It takes about a minute and assumes pbkit is already installed — if not, follow Install pbkit first.
By the end you will understand the three files pbkit generates and how to call them.
1. Create a config file
Section titled “1. Create a config file”Create pbkit.config.ts in your project root:
export default { input: "https://my-pb.example.com", output: "./src/generated", sdk: { baseUrl: "https://my-pb.example.com", },}You can also point to an exported JSON schema:
export default { input: "./pb_schema.json", output: "./src/generated", sdk: { baseUrl: "https://my-pb.example.com", },}2. Generate
Section titled “2. Generate”bunx pbkit generateThis creates generated files in ./src/generated:
types.gen.ts— TypeScript interfacesclient.gen.ts— PocketBase client singletonsdk.gen.ts— Typed CRUD functions
3. Use the generated SDK
Section titled “3. Use the generated SDK”import { getArticle, listArticles, createArticle } from "./generated/sdk.gen"import type { ArticlesCreate, ArticlesRecord } from "./generated/types.gen"
// Get a single recordconst article: ArticlesRecord = await getArticle("RECORD_ID")
// Expand relations with autocompleteconst withAuthor = await getArticle("RECORD_ID", { expand: "author",})
// List with paginationconst page = await listArticles({ page: 1, perPage: 20 })
// Createconst draft: ArticlesCreate = { title: "Hello", status: "draft", author: "USER_ID",}
const newArticle = await createArticle(draft)That’s it — you have a fully typed SDK with autocomplete and compile-time checks, generated entirely from your schema.
What just happened?
Section titled “What just happened?”pbkit read your schema and wrote three files into ./src/generated:
| File | What it is |
|---|---|
types.gen.ts | TypeScript interfaces for every collection (ArticlesRecord, ArticlesCreate, …) |
client.gen.ts | A PocketBase client initialized with your sdk.baseUrl |
sdk.gen.ts | The typed CRUD functions you imported (getArticle, listArticles, createArticle, …) |
By default the SDK functions talk to the client exported from client.gen.ts.
You only ever import from sdk.gen.ts and types.gen.ts — never edit these
files by hand, since they are overwritten on every run.
For why pbkit splits the output this way, see The generated files.
Keep your SDK in sync
Section titled “Keep your SDK in sync”Whenever your PocketBase schema changes, run bunx pbkit generate again. During
active development you can leave it watching:
bunx pbkit generate --watchThis polls the schema every 10 seconds and regenerates on changes. Press
Ctrl+C to stop.
Next steps
Section titled “Next steps”- Migrate from pocketbase-typegen — moving an existing project
- Configuration reference — every available option
- Add TanStack Query or Zod schemas via plugins