Installation
Install @brain-db/sdk, its one dependency, the runtime floor, and how to import each tier.
Install
npm install @brain-db/sdkRuntimeNode >= 18requiredThe package declares engines.node: ">=18". It is ESM-only
("type": "module"); there is no CommonJS build.
DependenciescborgrequiredExactly one — cborg, for the CBOR payload codec. The HTTP tier uses the
platform fetch; the wire tier uses node:net and node:crypto.
TypeScript>= 5.4optionalTypes ship with the package. The wire tier uses bigint literals, so your
target must be ES2020 or later.
Imports
Two entries. The root carries both tiers; @brain-db/sdk/http carries the
HTTP tier alone, and is the one to reach for by default.
// HTTP tier — loads on any runtime with `fetch`
import { BrainHttpClient, BrainHttpError, DEFAULT_HTTP_RETRY } from "@brain-db/sdk/http";
// Wire tier
import {
BrainClient,
Pool,
EncodeBuilder,
RecallBuilder,
ForgetBuilder,
WaitMode,
ForgetMode,
MemoryKindWire,
newId,
deriveSpaceId,
withRetry,
DEFAULT_RETRY_POLICY,
} from "@brain-db/sdk";
// Errors and classification
import {
BrainError,
ServerError,
BrainHttpError,
isRetryable,
isActAsDenied,
isLlmCredentialMissing,
isLlmCredentialUnavailable,
} from "@brain-db/sdk";The HTTP tier's contract types are also re-exported from the root under an
http namespace, so they do not collide with the wire types of the same name
— PlanStep and Capabilities exist on both tiers with different shapes:
import { http } from "@brain-db/sdk";
function render(step: http.PlanStep) { /* ... */ }From the subpath there is no collision to avoid, so the same types are top-level:
import type { PlanStep } from "@brain-db/sdk/http";Which entry to import
The wire tier imports node:net and node:crypto. They are static imports
in the root entry, so taking BrainHttpClient from the root takes them with
it — which is fine on Node and fatal on Cloudflare Workers, Deno, Bun or a
Next.js Edge route, where the build fails on a module your own code never
mentions.
Nothing reachable from @brain-db/sdk/http references a Node builtin, at
runtime or in a type position. Both entries export the same
BrainHttpClient, so preferring the subpath costs nothing and the question
never comes up. Available in 0.4.1 and later; before that the package
published a single "." export and the root was the only entry.
Versioning
The package is pre-1.0. Minor versions may change shapes; pin an exact version in production.
All three SDKs target Brain wire protocol version 1 — the version byte
in the BRN0 header, advertised as supported_versions = [1] in HELLO. A
server that negotiates any other version is rejected with VersionMismatch
rather than best-effort decoded.
The exported SDK_VERSION constant is the version the package publishes, and
is safe to branch on or attach to a bug report:
import { SDK_VERSION } from "@brain-db/sdk";It used to lie, and some installs still have the old one
Until 0.4.1 the constant was a hand-typed literal that nothing checked. It
read "0.1.0" through the 0.2.0, 0.3.1 and 0.4.0 releases, so anything
reading it — a compatibility check, a telemetry tag, the version in a bug
report — got a number that had not existed for a year. A release now
rewrites it alongside package.json, and the SDK's own test/version fails
if the two disagree. If you are pinned below 0.4.1, keep reading the version
from your lockfile. The Python SDK had the identical drift and closed it the
same way; Rust takes the number from CARGO_PKG_VERSION, where it cannot
drift at all.
Verify the install
import { BrainHttpClient } from "@brain-db/sdk/http";
const brain = new BrainHttpClient({ apiKey: process.env.BRAIN_API_KEY! });
console.log(await brain.whoami());
console.log(await brain.capabilities());whoami is the cheapest round trip that proves the key, the base URL and the
network path all work at once.
Was this page helpful?