Typescript SDK Quickstart
Get started with Memori in under 3 minutes using TypeScript. No database setup required — just your Memori API key and your favorite LLM provider.
In this example, we'll use Memori with OpenAI. Check out our Integration guides for other LLM providers.
Prerequisites
- Node.js 18 or higher
- An OpenAI API key
- A Memori API key from app.memorilabs.ai
Step 1: Install Libraries
Install Memori and the OpenAI SDK:
npm install @memorilabs/memori openai
Step 2: Set Environment Variables
Set your API keys as environment variables:
export MEMORI_API_KEY="your-memori-api-key"
export OPENAI_API_KEY="your-openai-api-key"
Step 3: Run Your First Memori Application
Create a new file quickstart.ts and add the following code:
Setup & Configuration
Import libraries and initialize Memori with your API key and OpenAI client.
- Memori reads your
MEMORI_API_KEYfrom the environment automatically llm.register()wraps your LLM client for automatic memory captureattribution()links memories to a specific user and process
import OpenAI from 'openai';
import { Memori } from '@memorilabs/memori';
const client = new OpenAI();
const mem = new Memori().llm.register(client);
mem.attribution('user_123', 'test-ai-agent');
First Conversation
Tell the LLM a fact about yourself. Memori automatically captures the conversation and processes it through Advanced Augmentation.
const response = await client.chat.completions.create({
model: 'gpt-4o-mini',
messages: [
{ role: 'user', content: 'My favorite color is blue.' }
],
});
console.log(response.choices[0].message.content + '\n');
Memory Recall
Create a completely new client and Memori instance — no prior context carried over. Memori automatically injects relevant facts via semantic search, so the second response should correctly recall your favorite color. This verifies recall from stored memories, not prior in-memory message history.
const client2 = new OpenAI();
const mem2 = new Memori().llm.register(client2);
mem2.attribution('user_123', 'test-ai-agent');
const response2 = await client2.chat.completions.create({
model: 'gpt-4o-mini',
messages: [
{ role: 'user', content: "What's my favorite color?" }
],
});
console.log(response2.choices[0].message.content + '\n');
Step 4: Run the Application
Execute your TypeScript file:
npx tsx quickstart.ts
You should see the AI respond to both questions, with the second response correctly recalling that your favorite color is blue!
Step 5: Check the Dashboard
Visit app.memorilabs.ai to see your memory usage and try the Graph Explorer to interact with your memories visually.