A TypeScript Express REST API that demonstrates how to add persistent memory to an AI assistant using Mem0 and Groq.
Most AI APIs are stateless — every request starts from zero. This project shows how to fix that by integrating Mem0 as a memory layer, so your AI assistant remembers users across conversations.
- Express.js — REST API framework
- TypeScript — type safety
- Mem0 — persistent memory layer
- Groq — LLM inference (llama-3.3-70b-versatile)
| Method | Endpoint | Description |
|---|---|---|
| POST | /chat/:userId |
Send a message and get a memory-aware response |
| GET | /chat/:userId/memories |
Retrieve all stored memories for a user |
| DELETE | /chat/:userId/memories |
Clear all memories for a user |
| POST | /chat/:userId/no-memory |
Send a message with no memory context (for comparison) |
- Node.js 18+
- Mem0 API key — mem0.ai/platform
- Groq API key — console.groq.com
git clone https://github.com/yourusername/mem0-express-api.git
cd mem0-express-api
npm installCreate a .env file in the root:
GROQ_API_KEY=your_groq_key_here
MEM0_API_KEY=your_mem0_key_here
PORT=3000npm run devSend a message:
curl -X POST http://localhost:3000/chat/user123 \
-H "Content-Type: application/json" \
-d '{"message": "My name is Ayomide and I am building an API platform called APIblok"}'Check stored memories:
curl http://localhost:3000/chat/user123/memoriesCompare with no memory:
curl -X POST http://localhost:3000/chat/user123/no-memory \
-H "Content-Type: application/json" \
-d '{"message": "What do you know about me?"}'Clear memories:
curl -X DELETE http://localhost:3000/chat/user123/memories- User sends a message to
/chat/:userId - Mem0 searches for relevant memories for that user
- Memories are injected into the system prompt
- Groq generates a context-aware response
- The exchange is stored in Mem0 for future requests
Read the full tutorial: [link to article]
MIT