HTTP client
BrainHttpClient — construction, Bearer auth, base URL, timeouts, the camelCase-to-snake_case seam, and the full verb map.
Construction
new BrainHttpClient(opts: BrainHttpClientOptions)apiKeystringrequiredSent 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).
baseUrlstringoptionalThe 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.
timeoutMsnumberoptionalPer-request timeout. Defaults to 30_000. A timeout surfaces as a
BrainHttpError with status: 0.
retryPartial<HttpRetryPolicy>optionalMerged over DEFAULT_HTTP_RETRY. See Retries.
fetchtypeof fetchoptionalOverride 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:cryptoNothing 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.
| Area | Verbs |
|---|---|
| Memory | encode, encodeVector, recall, forget |
| Store | memoryList, memoryInspect, graphFetch, link, unlink |
| Spaces | createSpace, listSpaces, deleteSpace, createSession, listSessions, deleteSession |
| Entities | listEntities, getEntity, createEntity, resolveEntity, updateEntity, renameEntity, mergeEntities, unmergeEntity, tombstoneEntity |
| Statements | listStatements, getStatement, createStatement, supersedeStatement, tombstoneStatement, retractStatement, statementHistory |
| Relations | createRelation, getRelation, listRelations, traverseRelations, supersedeRelation, tombstoneRelation |
| Schema | getSchema, uploadSchema, validateSchema, replaceSchema, dropSchema, listSchemas, listExtractors |
| Reasoning | plan, reason, materializeProcedural, queryExplain, queryTrace |
| Streams | subscribe |
| Credentials | putLlmCredential, getLlmCredential, deleteLlmCredential, testLlmCredential, verifyLlmCredential |
| Introspection | whoami, capabilities |
What the HTTP tier cannot do
Transactionswire onlyNo txnBegin. Each HTTP verb is its own unit. See
Transactions.
act_aswire onlyThe space comes from the credential. Addressing another space per request needs the wire client. See Wire client.
Frame-level streamingwire onlyNo …Frames variants. The HTTP tier concatenates; only subscribe
streams, over SSE.
ping and cancelStreamwire onlyThere is no connection to keep alive and no stream id to cancel.
Was this page helpful?