Install the official TypeScript SDK and start reading and writing data from your frontend or server.
The @urbackend/sdk package is the official TypeScript SDK for urBackend. It wraps the REST API with typed methods for auth, database, and storage — no manual fetch calls required.
import urBackend from '@urbackend/sdk';const client = urBackend({ apiKey: process.env.URBACKEND_API_KEY });// Log in an existing userconst { accessToken } = await client.auth.login({ email: 'alice@example.com', password: 'secret123'});// Insert a document with RLS support (passing the user token)const product = await client.db.insert('products', { name: 'Chair', price: 99 }, accessToken);// Fetch documents with filtering and sortingconst products = await client.db.getAll('products', { filter: { price_gt: 50 }, sort: 'price:asc'});// ⚠️ Server-side only — requires a secret key (sk_live_...).// Do not use this initialization in browser/client code.const serverClient = urBackend({ apiKey: process.env.URBACKEND_SECRET_KEY });await serverClient.mail.send({ to: 'user@example.com', subject: 'Order Confirmed', text: 'Your chair is on the way!'});
Use pk_live_... (publishable key) in frontend/browser code. It allows read operations by default, and write operations only if RLS is enabled.Use sk_live_... (secret key) in server-side code only. It allows full CRUD access. Never expose it in client-side bundles or public repositories.
The SDK logs a console warning if it detects you are using a Secret Key (sk_live_...) in a browser context.