Brain Docs

Reference

TypeScript SDKInstallationHTTP clientWire client
ErrorsRetriesPagination
Brain/Docs
✦ ASKBrain on GitHubDashboard
TypeScript SDKHTTP client

HTTP client

BrainHttpClient — construction, Bearer auth, base URL, timeouts, the camelCase-to-snake_case seam, and the full verb map.

PURPOSE

BrainHttpClient talks JSON to the Brain HTTP edge — brain-edge self-hosted, or the Arc cloud gateway. It covers 57 of the edge's routes across one flat client. This page documents construction and the conventions that apply to every verb on it.

Construction

Bearer API keystable
new BrainHttpClient(opts: BrainHttpClientOptions)
ParameterTypeRequired
apiKeystringrequired

Sent as Authorization: Bearer <apiKey>. Missing or empty throws a BrainHttpError with status: 0 and code: "config" before any request is attempted (apiKey is required), and so does a key carrying an ASCII control character: apiKey must not contain control characters. Every C0 character and DEL is refused, except HTAB, which RFC 7230 permits in a field value. The usual way one gets in is a key read from an env file with a trailing newline. The same rule, with the same message, applies in the Python and Rust clients (which spell the field api_key).

baseUrlstringoptional

The edge. Defaults to http://127.0.0.1:8080 — the self-host default. A scheme that is not http or https is rejected at construction.

timeoutMsnumberoptional

Per-request timeout. Defaults to 30_000. A timeout surfaces as a BrainHttpError with status: 0.

retryPartial<HttpRetryPolicy>optional

Merged over DEFAULT_HTTP_RETRY. See Retries.

fetchtypeof fetchoptional

Override the fetch implementation. Useful for instrumentation, for a proxy agent, or for tests.

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
  timeoutMs: 15_000,
});

There is no close()

The HTTP client holds no connection. Construct one per process and keep it; there is nothing to release.

Two entries, one client

The package root exports both tiers; @brain-db/sdk/http exports this one alone. The class is the same object either way, so on Node the choice only changes how much you pull in.

Off Node it is the difference between loading and not. The wire tier imports node:net and node:crypto, and because they are static imports in the root entry, taking BrainHttpClient from the root takes those with it — a Cloudflare Workers, Deno, Bun or Next.js Edge build fails on a module your own code never mentions:

Failed to load external module node:crypto:
TypeError: Native module not found: node:crypto

Nothing in the ./http subpath's import closure references a Node builtin, at runtime or in a type position, so it needs only fetch. Prefer it everywhere and the question never arises.

The subpath is 0.4.1 and later

Earlier releases published a single "." export, and there was no way to take the HTTP client on its own. On one of those, the root import is your only option and the runtime has to be Node.

Conventions

Naming

You write camelCase; the edge speaks snake_case. The SDK converts at the seam, in both directions, for bodies and query strings — includeTombstoned goes out as include_tombstoned. This matters more than it sounds: a query parameter sent under the wrong name is not an error, it silently takes the field's default, so a filter appears to be applied and is not.

64-bit numbers

Session ids, LSNs and nanosecond timestamps are bigint. The SDK serialises them losslessly rather than routing them through stock JSON.stringify, which would round anything past 2^53.

Query values

Every query field is a string, number, bigint or boolean. Passing an object or an array throws a TypeError at the call site rather than stringifying to [object Object] and letting the edge answer 400 — or worse, apply a default. undefined is dropped, so an omitted option means "let the edge decide".

Ids in paths

Path ids are percent-encoded. An id is caller data, not a path fragment.

The verb map

Each verb has its own reference page. The full map, with both tiers, is on the SDK index.

AreaVerbs
Memoryencode, encodeVector, recall, forget
StorememoryList, memoryInspect, graphFetch, link, unlink
SpacescreateSpace, listSpaces, deleteSpace, createSession, listSessions, deleteSession
EntitieslistEntities, getEntity, createEntity, resolveEntity, updateEntity, renameEntity, mergeEntities, unmergeEntity, tombstoneEntity
StatementslistStatements, getStatement, createStatement, supersedeStatement, tombstoneStatement, retractStatement, statementHistory
RelationscreateRelation, getRelation, listRelations, traverseRelations, supersedeRelation, tombstoneRelation
SchemagetSchema, uploadSchema, validateSchema, replaceSchema, dropSchema, listSchemas, listExtractors
Reasoningplan, reason, materializeProcedural, queryExplain, queryTrace
Streamssubscribe
CredentialsputLlmCredential, getLlmCredential, deleteLlmCredential, testLlmCredential, verifyLlmCredential
Introspectionwhoami, capabilities

What the HTTP tier cannot do

OptionTypeDefault / Env
Transactionswire only

No txnBegin. Each HTTP verb is its own unit. See Transactions.

act_aswire only

The space comes from the credential. Addressing another space per request needs the wire client. See Wire client.

Frame-level streamingwire only

No …Frames variants. The HTTP tier concatenates; only subscribe streams, over SSE.

ping and cancelStreamwire only

There is no connection to keep alive and no stream id to cancel.

See also
Wire clientErrorsRetries

Was this page helpful?

Installation

Install @brain-db/sdk, its one dependency, the runtime floor, and how to import each tier.

Wire client

BrainClient over the BRN0 protocol — connect, ClientConfig, the two auth methods, act_as, multiplexing, the connection pool, and the id helpers.

On this page

ConstructionTwo entries, one clientConventionsNaming64-bit numbersQuery valuesIds in pathsThe verb mapWhat the HTTP tier cannot do
Suggest an editOpen in Playground