TypeScript SDK
@molecule/sdk — the typed client for the Company Brain API. Retrieve, answer, stream, and feedback from any repo, with zero runtime dependencies.
@molecule/sdk is the typed TypeScript client for the Company Brain API
(molecule.v1). It wraps every Boundary 1 endpoint — retrieval, grounded
answers (whole or streamed), policy resolution, website ingestion, and answer
feedback — behind one small class.
It has zero runtime dependencies and runs in the browser and in Node ≥18
(global fetch + ReadableStream), so a product team can drop it into a Next.js
app, a Cloudflare worker, or a Node service without a bundler dance.
Internal package
This is an internal SaaSLabs package, published to GitHub Packages — not
the public npm registry. See Install from GitHub for the
.npmrc + token setup.
Install
pnpm add @molecule/sdk # requires the .npmrc from "Install from GitHub"First call
import { Molecule } from "@molecule/sdk";
// The API key IS the principal: it resolves to a (tenant, product) and the
// surfaces it may act on. The caller never supplies scope.
const molecule = new Molecule({
apiKey: process.env.MOLECULE_KEY!,
baseUrl: "https://brain.example.com",
});
const res = await molecule.answer("what are your pricing plans?", {
surface: "site_chatbot",
});
console.log(res.answer); // grounded, cited text
console.log(res.citations); // Citation[]
console.log(res.decisionId); // replayable policy-decision idWhat's on the client
Prop
Type
Constructor options
Prop
Type
Errors & cancellation
Any non-2xx response throws a MoleculeError carrying the HTTP status and
the parsed body:
import { MoleculeError } from "@molecule/sdk";
try {
await molecule.answer("…", { surface: "site_chatbot" });
} catch (e) {
if (e instanceof MoleculeError) {
// 401 auth · 403 policy · 400 validation · 5xx server
console.error(e.status, e.message, e.body);
}
}Every method accepts an AbortSignal ({ signal } in the options object, or a
second argument on feedback/ingest/health) so you can cancel in-flight
requests — essential for a chat UI where the user sends a new message before the
last answer finishes.
Contract source of truth
The SDK's wire types mirror @molecule/core (molecule.v1), which the gateway
validates against. That package is the source of truth; the SDK vendors the
types so it stays dependency-free for external repos.
Core concepts
Classification, ACL tokens, the public/private bifurcation, and snapshot-pinned reads — the model behind every response.
Install from GitHub
Consume @molecule/sdk in another repo straight from GitHub — via GitHub Packages (recommended) or a git dependency — with the scope and token setup that actually works for a monorepo.