Minimal example
Use these values on a trusted local machine or server. Keep project credentials out of browser code.
typescript
const headers = {
Authorization: `Bearer ${process.env.MEMORA_API_KEY}`, // Set MEMORA_API_KEY=YOUR_PROJECT_API_KEY locally.
"Content-Type": "application/json",
};
// Single-user personal connection:
const subject_id = "YOUR_SUBJECT_ID";
// Multi-user app: use each authenticated user’s stable ID instead.
await fetch(`${process.env.MEMORA_API_URL}/v1/integrations/messages`, {
method: "POST", headers,
body: JSON.stringify({ subject_id, conversation_id, idempotency_key, content: userMessage }),
});
const response = await fetch(`${process.env.MEMORA_API_URL}/v1/integrations/memories/search`, {
method: "POST", headers,
body: JSON.stringify({ subject_id, query: userMessage }),
});
const result = await response.json();
const memoryContext = result.has_relevant_memories ? result.context : "";Check that it works
- Send a message and note its response/source ID for debugging.
- Allow the asynchronous processing and indexing steps to complete.
- Search again using the same subject and namespace.
- Use returned evidence and relevant context when building the next model prompt.