Authentication

Every request carries an API key and a subject.

Living Brain requires two headers on every request.

HeaderPurpose
x-api-keyAuthenticates the caller. Scoped to an organization; carries the role of the member it was issued to.
x-subject-idIdentifies the end user you’re acting on behalf of. Brains are owned by subjects.

The split matters: one API key serves your whole application, while x-subject-id keeps each of your users’ brains isolated from one another. Pass through a stable identifier from your own auth system — a user id, not an email.

Configuring the SDKs

Both clients read from the environment when you don’t pass values explicitly, so production code usually needs no arguments at all.

1import { LivingBrainClient } from "@livingbrain/sdk";
2
3// Explicit
4const client = new LivingBrainClient({
5 apiKey: process.env.LIVING_BRAIN_API_KEY!,
6 subjectId: "user_123",
7});
8
9// Or rely on LIVING_BRAIN_API_KEY / LIVING_BRAIN_SUBJECT_ID
10const fromEnv = new LivingBrainClient({ subjectId: "user_123" });

A key is a bearer credential for your entire organization. Keep it server-side — never ship it to a browser or mobile client. If you need browser access, proxy through your backend.

Per-user clients

Because the subject is a client-level header, the usual pattern is one client per request, constructed with whichever user you’re serving:

1function clientFor(userId: string) {
2 return new LivingBrainClient({
3 apiKey: process.env.LIVING_BRAIN_API_KEY!,
4 subjectId: userId,
5 });
6}

Roles and permissions

An API key inherits the role of the member it was issued to. The organization creator is the owner.

CapabilityOwnerAdminDeveloperViewer
Manage organization (rename / delete)
Invite / change roles / remove members
Request API keys
Reveal / rotate / revoke own key
Revoke any key in the org
View org (members, keys, brains)

Failure modes

ResponseMeaning
401 Missing API keyNo x-api-key header was sent.
401 Invalid API keyThe key was rejected — revoked, mistyped, or from another environment.
404The brain exists but isn’t owned by this x-subject-id.

See Errors for the full error envelope.