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)By default the generated SDK uses the client exported from client.gen.ts.
Pass a client override when you need a different PocketBase instance:
import PocketBase from "pocketbase"import { getArticle } from "./generated/sdk.gen"
const pb = new PocketBase("https://my-pb.example.com")
await getArticle("RECORD_ID", undefined, { client: pb })Watch mode
Section titled “Watch mode”To auto-regenerate when your schema changes:
bunx pbkit generate --watchThis polls the API every 10 seconds. Press Ctrl+C to stop.