SDKsTypeScript SDK

TypeScript SDK

@mnemo-ai/client-ts is a typed HTTP client with no runtime dependencies beyond fetch. It needs a running Mnemosyne server and an API key. The CLI and the MCP server are built on it.

pnpm add @mnemo-ai/client-ts
# or
npm i @mnemo-ai/client-ts

Construct

import { MnemosyneClient } from "@mnemo-ai/client-ts";
 
const memory = new MnemosyneClient({
  url: "http://localhost:3939",
  apiKey: process.env.MNEMO_KEY!,
});

url and apiKey are required, and the constructor throws without them. The API key decides the workspace.

OptionDefaultWhat it does
urlrequiredBase URL of the server
apiKeyrequiredSent as Authorization: Bearer
fetchglobal fetchCustom fetch implementation
timeout30000Per-request timeout in milliseconds
retry{ attempts: 3, initialDelayMs: 200 }Retry policy. Also takes shouldRetry(error, attempt)
userAgentnoneSuffix added to the User-Agent header
workspaceIdnoneDefault X-Workspace-Id. Only meaningful with a uk_live_* token
localenoneSent as Accept-Language, so the server localizes error messages

Core methods

// Remember
const fact = await memory.remember({
  statement: "Acme prefers communication in Spanish.",
  tags: ["client:acme"],
});
 
// Recall
const { hits } = await memory.recall({
  query: "what language should we use with Acme?",
  topK: 5,
});
for (const hit of hits) {
  console.log(hit.score.toFixed(2), hit.content);
}
 
// Pin and unpin
await memory.pinFact(fact.id);
await memory.unpinFact(fact.id);
 
// Forget: a soft delete, the fact is closed and not erased
await memory.forgetFact(fact.id);
 
// Timeline
const { events } = await memory.timeline({
  limit: 20,
  since: "2026-06-01T00:00:00Z",
});

remember posts to POST /remember. Besides statement it accepts subject, kind, subtype, confidence, tags, sensitivity, topicKey, sessionId, scope, scopeRef, metadata and vector. createFact({ content, attribution, tags }) is a shorter form that posts to the same route.

A pin does not change how a fact ranks in recall.

A hit that a federation sync brought from another server also carries federation: { peer, trustScore } on the wire. The RecallHit type does not declare that field yet.

eraseSubject({ userId, confirm }) or eraseSubject({ actorId, confirm }) posts to POST /admin/erasure, the GDPR crypto-erasure, and needs the memory:hard_delete scope. See Security & compliance.

issueScopedKey({ type, scopes, expiresIn }), rotateScopedKey(id) and revokeScopedKey(id) manage the scoped-scheme keys that MNEMO_SCOPED_AUTH=1 verifies, and need the admin:keys scope. An admin key also returns mfaSecret and otpauthUri, once. See Security & isolation.

Recall options

const snapshot = await memory.recall({
  query: "firmware release cadence",
  topK: 3,
  mode: "hybrid",
  kinds: ["fact", "decision"],
});
FieldValuesNotes
topK1 to 100, default 10Maximum number of hits
modelexical, semantic, hybrid, autoDefault auto
kindsarray of kind namesOmit for the default set. task, event and reasoning are only returned when listed
scopeglobal, conversation, personalOmit to search every scope
scopeRefstringFilters to memories written with that reference
hydebooleanOne LLM call writes a hypothetical answer to search with. Default false. Typed in the client from 3.6.3
asOfISO 8601 instant, not in the futureRanks what memory held at that instant, including facts superseded since
includeGraphbooleanEach hit also carries relations and hyperedges. Default false. Typed in the client from 3.6.3
minSimilarity0 to 1Cosine floor, ignored in lexical mode
vectornumber arrayA query embedding you computed yourself; the server skips its own
sessionIdstringLinks the recall to a session
projectionfull, compactcompact returns the first 300 characters of each hit
debugbooleanAdds a stage trace to debug in the response

Sessions

const session = await memory.createSession({
  agentId: "support-bot",
  label: "ticket 4812",
});
 
await memory.appendTurn(session.id, {
  role: "user",
  content: "The robot stops at aisle 4.",
});
await memory.appendTurn(session.id, {
  role: "assistant",
  content: "Firmware 2.8 fixes that.",
});
 
const result = await memory.collapseSession(session.id);
console.log(result.status);

role must be user, assistant or system. Collapsing a session needs an LLM provider configured on the server.

Pagination

There are no iterators. List methods return one page and a nextCursor:

let cursor: string | null = null;
do {
  const page = await memory.listFacts({
    limit: 100,
    ...(cursor ? { cursor } : {}),
  });
  for (const fact of page.items) {
    console.log(fact.id, fact.statement);
  }
  cursor = page.nextCursor;
} while (cursor);

Errors

Four classes are exported. MnemosyneError is the base of the other three.

ClassWhenFields
MnemosyneAPIErrorThe server answered with a non-2xxstatus, code, requestId, body, details, retryable, retryAfterSeconds
MnemosyneNetworkErrorDNS, TLS or connection failurecause, retryable
MnemosyneTimeoutErrorThe request exceeded timeouttimeoutMs
import {
  MnemosyneAPIError,
  MnemosyneNetworkError,
  MnemosyneTimeoutError,
} from "@mnemo-ai/client-ts";
 
try {
  await memory.recall({ query: "firmware release cadence" });
} catch (err) {
  if (err instanceof MnemosyneTimeoutError) {
    console.error(`timed out after ${err.timeoutMs} ms`);
  } else if (err instanceof MnemosyneNetworkError) {
    console.error("could not reach the server");
  } else if (err instanceof MnemosyneAPIError) {
    console.error(err.status, err.code, err.requestId);
  } else {
    throw err;
  }
}

A contradiction with an existing fact is not an error. remember returns it in the conflict field of its response.

Retries and idempotency

By default the client makes up to three attempts, with exponential backoff and jitter starting at 200 ms. It retries network failures, 429 and 5xx, and waits for Retry-After when the server sends it. Timeouts are not retried.

Only reads are replayed automatically: GET requests and recall. A write is replayed only when it carries an idempotency key, which is the third argument of the write methods and travels as the Idempotency-Key header:

const key = crypto.randomUUID();
 
await memory.remember(
  { statement: "Larkspur Robotics ships firmware every two weeks." },
  undefined,
  key
);

Generate the key once and reuse it if you retry the call yourself.

Several workspaces

A workspace key always works on its own workspace. With a user token (uk_live_*) whose user belongs to several workspaces, forWorkspace returns a new client that sends X-Workspace-Id:

const other = memory.forWorkspace("7c1f0b52-3e0a-4a51-9d0e-2f6a8f1f4b10");
await other.recall({ query: "firmware release cadence" });

A workspace key that asks for another workspace gets a 403.

The package requires Node 20 or later and ships ESM and CommonJS builds. It only uses fetch, so it also runs on Bun, Deno, Cloudflare Workers and browsers. @mnemo-ai/core is an internal package, not on npm: it runs inside the server.