TypeScript SDK
The hand-written TypeScript client for Brain — two clients over one verb vocabulary, and every operation's reference page.
Two clients, one vocabulary
BrainHttpClientHTTP / JSONTalks JSON to the Brain HTTP edge — brain-edge self-hosted, or the Arc
cloud gateway. Covers every data route the edge exposes.
BrainClientWire / BRN0 over TCPTalks the binary protocol directly to a Brain shard: everything the HTTP
client does, plus transactions, act_as, frame-level streaming, ping
and stream cancellation — multiplexed over one socket.
The client is flat. There are no namespaced resource objects and no separate query verb: the write verb is encode and the read verb is recall.
Install
npm install @brain-db/sdkSee Installation for runtime and versioning notes.
Quickstart
import { BrainHttpClient } from "@brain-db/sdk/http";
const brain = new BrainHttpClient({
apiKey: process.env.BRAIN_API_KEY!,
baseUrl: process.env.BRAIN_BASE_URL, // unset → http://127.0.0.1:8080
});
await brain.encode({ text: "I prefer dark mode and live in Berlin." });
const answer = await brain.recall({ query: "where does the user live?" });
console.log(answer.answerKind, answer.memories[0]?.text);recall never fabricates: the hit list is empty when Brain has nothing to
say.
Every operation
| Area | What it covers | Operations |
|---|---|---|
| Memory | The three verbs, plus the store-level operations and memory edges. | encode, recall, forget, encodeVector, memoryList, memoryInspect, graphFetch, link, unlink |
| Spaces and sessions | Provision and erase the caller's space, and the sessions inside it. | createSpace, listSpaces, deleteSpace, createSession, listSessions, deleteSession |
| Entities | The typed graph's identity layer — resolution, merging, lifecycle. | createEntity, getEntity, resolveEntity, listEntities, updateEntity, renameEntity, mergeEntities, unmergeEntity, tombstoneEntity |
| Statements | Typed claims, their supersession chains, and three ways to retire one. | createStatement, getStatement, listStatements, supersedeStatement, tombstoneStatement, retractStatement, statementHistory |
| Relations | Typed, directed, time-bounded edges between entities, and traversal. | createRelation, getRelation, listRelations, traverseRelations, supersedeRelation, tombstoneRelation |
| Schema | Declare the typed graph, and the extractors bound to it. | getSchema, validateSchema, uploadSchema, replaceSchema, dropSchema, listSchemas, listExtractors |
| Reasoning | Planning, inference, the procedural block, and query introspection. | plan, reason, materializeProcedural, queryExplain, queryTrace |
| Streams | The live change feed, and stream cancellation. | subscribe, cancelStream |
| Transactions | Group wire writes into one atomic unit. | txnBegin, txnCommit, txnAbort |
| Credentials | Register and verify the LLM provider key extraction runs on. | putLlmCredential, getLlmCredential, testLlmCredential, verifyLlmCredential, deleteLlmCredential |
| Introspection | Who you are, what the server can do, and whether it is alive. | whoami, capabilities, ping |
Reading the reference
Each operation has one page covering both tiers. Where the two differ — a field name, an extra filter, a frame-level form — the page says so rather than splitting into two near-identical pages.
| Page | What it covers |
|---|---|
| Installation | Install, imports, runtime, versioning |
| HTTP client | Construction, auth, conventions |
| Wire client | Connect, config, act_as, multiplexing, pooling |
| Errors | Both taxonomies, the categories and the code families |
| Retries | What retries automatically, and what does not |
| Pagination | Cursors and frames |
Was this page helpful?