TypeScript / Node
There is no official TypeScript SDK yet. All integration is via the REST API using the built-in fetch (Node 18+) or axios.
Installation
Section titled “Installation”No additional packages are required if you are on Node 18 or later — fetch is available globally. For older Node versions, or if you prefer a more ergonomic API, install axios:
npm install axiosQuick start
Section titled “Quick start”Define the Memory type and two helper functions:
const BASE = "http://localhost:4545";const HEADERS = { "Content-Type": "application/json", Authorization: "Bearer YOUR_TOKEN", // omit if auth is disabled};
interface Memory { id: string; content: string; memory_type: "short_term" | "long_term"; metadata: { created_at: string; importance: number; tags: string[]; // ...see the Data model reference for the full metadata shape };}
async function storeMemory(content: string, memory_type = "short_term"): Promise<Memory> { const res = await fetch(`${BASE}/api/v1/memories`, { method: "POST", headers: HEADERS, body: JSON.stringify({ content, memory_type }), }); if (!res.ok) throw new Error(`Remem error: ${res.status}`); return res.json();}
interface SearchResult { memory: Memory; score: number;}
async function searchMemories(query: string, limit = 10): Promise<SearchResult[]> { const res = await fetch(`${BASE}/api/v1/memories/search`, { method: "POST", headers: HEADERS, body: JSON.stringify({ query, search_type: "hybrid", limit }), }); if (!res.ok) throw new Error(`Remem error: ${res.status}`); const data = await res.json(); return data.results; // { results: [{ memory, score }], total }}
// Usageawait storeMemory("User prefers dark mode", "long_term");const results = await searchMemories("dark mode preferences");Vercel AI SDK integration pattern
Section titled “Vercel AI SDK integration pattern”Use Remem as a tool inside a Vercel AI SDK streamText or generateText call to give the model persistent context retrieval:
import { generateText, tool } from "ai";import { openai } from "@ai-sdk/openai";import { z } from "zod";
const BASE = "http://localhost:4545";const AUTH = { Authorization: "Bearer YOUR_TOKEN" };
const recallTool = tool({ description: "Search Remem for memories relevant to a query. Call this before answering questions that might benefit from past context.", parameters: z.object({ query: z.string().describe("Search query"), limit: z.number().optional().default(5), }), execute: async ({ query, limit }) => { const res = await fetch(`${BASE}/api/v1/memories/search`, { method: "POST", headers: { ...AUTH, "Content-Type": "application/json" }, body: JSON.stringify({ query, search_type: "hybrid", limit }), }); if (!res.ok) throw new Error(`Remem search failed: ${res.status}`); const data = await res.json(); return data.results as SearchResult[]; },});
const { text } = await generateText({ model: openai("gpt-4o"), tools: { recall: recallTool }, maxSteps: 3, prompt: "What are this user's UI preferences?",});The model will call recall autonomously when it decides past context is useful.
LangChain.js integration pattern
Section titled “LangChain.js integration pattern”Extend BaseMemory to back a LangChain.js chain with Remem:
import { BaseMemory, InputValues, OutputValues } from "langchain/memory";
interface MemoryVariables { history: string[];}
export class RememMemory extends BaseMemory { private base: string; private headers: Record<string, string>; private searchLimit: number;
constructor(options: { base?: string; token?: string; searchLimit?: number } = {}) { super(); this.base = options.base ?? "http://localhost:4545"; this.searchLimit = options.searchLimit ?? 5; this.headers = { "Content-Type": "application/json", ...(options.token ? { Authorization: `Bearer ${options.token}` } : {}), }; }
get memoryKeys(): string[] { return ["history"]; }
async loadMemoryVariables(values: InputValues): Promise<MemoryVariables> { const query = String(values["input"] ?? ""); if (!query) return { history: [] };
const res = await fetch(`${this.base}/api/v1/memories/search`, { method: "POST", headers: this.headers, body: JSON.stringify({ query, search_type: "hybrid", limit: this.searchLimit }), }); if (!res.ok) throw new RememError(res.status, await res.text()); const data = await res.json(); const results: SearchResult[] = data.results; return { history: results.map((r) => r.memory.content) }; }
async saveContext(inputs: InputValues, outputs: OutputValues): Promise<void> { const pairs: Array<[string, string]> = [ ["human", String(inputs["input"] ?? "")], ["ai", String(outputs["output"] ?? "")], ]; for (const [role, content] of pairs) { if (!content) continue; const res = await fetch(`${this.base}/api/v1/memories`, { method: "POST", headers: this.headers, body: JSON.stringify({ content: `${role}: ${content}`, memory_type: "long_term" }), }); if (!res.ok) throw new RememError(res.status, await res.text()); } }
async clear(): Promise<void> { // Implement bulk delete here if needed }}Error handling
Section titled “Error handling”Define a typed error class so callers can distinguish Remem API failures from network errors:
export class RememError extends Error { constructor( public readonly status: number, public readonly body: string, ) { super(`Remem API error ${status}: ${body}`); this.name = "RememError"; }
get isAuthError(): boolean { return this.status === 401 || this.status === 403; }
get isValidationError(): boolean { return this.status === 422; }
get isServerError(): boolean { return this.status >= 500; }}
async function safeStore(content: string, memory_type = "short_term"): Promise<Memory | null> { try { const res = await fetch(`${BASE}/api/v1/memories`, { method: "POST", headers: HEADERS, body: JSON.stringify({ content, memory_type }), signal: AbortSignal.timeout(10_000), }); if (!res.ok) throw new RememError(res.status, await res.text()); return res.json(); } catch (err) { if (err instanceof RememError) { if (err.isAuthError) console.error("Check your API token."); else if (err.isValidationError) console.error("Invalid request:", err.body); else console.error("Server error:", err.message); } else if (err instanceof DOMException && err.name === "TimeoutError") { console.error("Request timed out."); } else { console.error("Network error:", err); } return null; }}Next steps
Section titled “Next steps”- Memories API reference — full endpoint documentation including filters and bulk operations
- MCP Overview — use the MCP interface instead of REST for agent frameworks that support it
