Quick setup examples

Node.js Quickstart

Call the Unison brain from Node.js using the built-in fetch API — no extra dependencies required.

Node 18+ ships with fetch globally, so no extra HTTP library is needed. For a typed, higher-level client consider the official SDK instead: TypeScript SDK.

Prerequisites

export UNISON_TOKEN=usk_live_...

Node 18 or later (for native fetch).

Recall — fetch prompt-ready context

const BASE = "https://brain.unisonlabs.ai";
const headers = {
  Authorization: `Bearer ${process.env.UNISON_TOKEN}`,
};

const params = new URLSearchParams({ q: "payment service architecture", k: "5", mode: "auto" });
const res = await fetch(`${BASE}/v1/brain/context?${params}`, { headers });
const data = await res.json();

const memory = data.weakEvidence ? "" : data.contextMd;
// Prepend `memory` to your system prompt before calling the LLM

Persist — save a conversation to the brain

const res = await fetch(`${BASE}/v1/brain/remember`, {
  method: "POST",
  headers: { ...headers, "Content-Type": "application/json" },
  body: JSON.stringify({
    dump: {
      turns: [
        { role: "user",      content: "What queue library should we use?" },
        { role: "assistant", content: "Switched to pgmq — simpler ops than Redis." },
      ],
    },
    sourceRef: "session-1",
  }),
});

const { jobId } = await res.json();
console.log("jobId:", jobId);

remember runs the save-or-skip curation pipeline (dedupe, curated notes, entity facts) as a background job. The returned jobId tracks it — poll GET /v1/brain/jobs/{jobId} for status. New memories surface in recall queries within seconds.

To write a document directly instead (no curation, explicit path/tags), POST a { type: "document", content, ... } item to /v1/brain/ingest — see Ingest.

On this page