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 — write memory to the brain

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

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

The returned jobId tracks async indexing. New memories surface in recall queries within seconds.

On this page