Skip to content

TypeScript SDK — overview

@cratebase/client is Cratebase’s first-party TypeScript SDK — typed end to end, with the vector/LLM/queue/presence value-adds built in rather than bolted on. It’s the recommended client for new projects; the official pocketbase npm package still works unmodified against Cratebase (see PocketBase SDK interop) if you’re already using it.

Terminal window
bun add @cratebase/client
import { createClient } from "@cratebase/client";
const cb = createClient("http://localhost:8090");
const { record } = await cb.auth.signIn.password({
identity: "user@example.com",
password: "hunter2",
});
const posts = await cb.collection("posts").list({ filter: "published = true" });

Generate a Schema interface with @cratebase/schema-codegen and pass it as createClient’s type parameter for a typed cb.collection("posts"):

import { createClient } from "@cratebase/client";
import type { Schema } from "./cratebase-types";
const cb = createClient<Schema>("http://localhost:8090");
const post = await cb.collection("posts").one("abc123"); // typed as PostsRecord & RecordModel

createClient(url, options) returns a CratebaseClient with:

  • collection(name) — typed CRUD + realtime for one collection (see Records).
  • auth — the default auth namespace, bound to options.authCollection (default "users"); auth.as(collection) for another collection (see Authentication).
  • files — file URLs and protected-file tokens (see Files).
  • batch() — multi-write transactions (see Batch & admin).
  • admin — superuser-only management endpoints (see Batch & admin).
  • vector, llm, mcp, queue, presence — Cratebase-only value-add surface, built into this SDK (also available as @cratebase/extras for projects staying on the official pocketbase SDK).
  • send(path, options) — raw escape hatch for anything not wrapped.

CreateClientOptions:

interface CreateClientOptions {
authCollection?: string; // default "users"
authStore?: AuthStore; // default LocalAuthStore in a browser, MemoryAuthStore elsewhere
cookie?: string; // SSR: attach a raw Cookie header value
credentials?: RequestCredentials; // default "same-origin"
headers?: Record<string, string>;
fetch?: typeof fetch;
lang?: string;
}

Errors are CratebaseError (.status, .message, .response, .isAbort), never PocketBase’s ClientResponseError.