# Make sure .env.local existscat .env.local# Restart your development server after adding env varsnpm run dev
Verify the key format:
// Should start with 'sk_satori_'if (!process.env.SATORI_API_KEY?.startsWith('sk_satori_')) { console.error('Invalid API key format');}
Check if the key is revoked:
Log into your dashboard
Go to API Keys
Verify the key status is “Active”
Memories not being saved
Symptoms:
LLM doesn’t call add_item tool
No memories appear in database
Solutions:
Verify tools are passed to streamText:
const tools = memoryTools(config);const result = await streamText({ model: openai('gpt-4o'), messages, tools, // ← Make sure this is included});
Check system prompt instructs LLM to save:
system: `You are a helpful assistant with memory.When the user shares important information, use the add_item tool to save it.Important information includes:- Personal preferences- Personal details- Goals and intentions`
If this doesn’t work, check your API logs for errors.
Context not appearing in responses
Symptoms:
LLM doesn’t reference saved memories
Responses don’t seem personalized
Solutions:
Verify context is fetched:
const context = await getContext(config, userMessage);console.log('Memory context:', context);// Should output something like:// "- User prefers TypeScript// - User loves hiking"
Check context is in system prompt:
system: `You are a helpful assistant.What you know about this user:${memoryContext} // ← Make sure this is includedUse this information to personalize responses.`
Verify memories exist:
const client = new MemoryClient(config);const all = await client.getAllMemories();console.log('Total memories:', all.length);
Check search threshold:
// Lower threshold for broader matchesconst context = await getContext(config, userMessage, { threshold: 0.6, // Default is 0.7});
Rate limit exceeded
Symptoms:
Too Many Requests error
429 status code
Solutions:
Implement exponential backoff:
async function retryWithBackoff(fn: () => Promise<any>, maxRetries = 3) { for (let i = 0; i < maxRetries; i++) { try { return await fn(); } catch (error) { if (error.message.includes('rate limit') && i < maxRetries - 1) { const delay = Math.pow(2, i) * 1000; await new Promise(resolve => setTimeout(resolve, delay)); } else { throw error; } } }}// Usageawait retryWithBackoff(() => client.addMemory('content'));
// ❌ Don't do this in client components'use client';const client = new MemoryClient({ apiKey: '...' }); // API key exposed!// ✅ Do this instead - use API routesexport async function POST(req: Request) { // Server-side only const client = new MemoryClient({ apiKey: process.env.SATORI_API_KEY!, });}
// Make sure you have the correct UUIDconsole.log('Deleting memory:', memoryId);await client.deleteMemory(memoryId);
Check memory belongs to user:
// Memory IDs are scoped per userconst memories = await client.getAllMemories();const exists = memories.some(m => m.id === memoryId);if (!exists) { console.error('Memory not found for this user');}
Handle errors gracefully:
try { await client.deleteMemory(memoryId);} catch (error) { if (error.message.includes('Not Found')) { console.log('Memory already deleted or does not exist'); } else { throw error; }}
Duplicate memories
Symptoms:
Same information saved multiple times
Too many similar memories
Solutions:
Check before saving:
// Search for similar memories firstconst existing = await client.searchMemories(content, { threshold: 0.9, // High threshold for near-duplicates limit: 1,});if (existing.length === 0) { await client.addMemory(content);} else { console.log('Similar memory already exists');}
Update system prompt:
system: `Before saving a memory, consider if similar information already exists.Only save truly new or updated information.`
Periodic cleanup:
// Find and merge duplicate memoriesconst memories = await client.getAllMemories();for (let i = 0; i < memories.length; i++) { for (let j = i + 1; j < memories.length; j++) { const similarity = await calculateSimilarity( memories[i].content, memories[j].content ); if (similarity > 0.95) { // Keep the newer one, delete the older await client.deleteMemory(memories[i].id); break; } }}