Observed since 20 Oct, 22:12 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
JavaScript/TypeScript SDK for 0Latency agent memory API
A lightweight JavaScript/TypeScript client for the 0Latency agent memory API.
npm install @0latency/sdk
import { Memory } from '@0latency/sdk';
// Initialize the client
const memory = new Memory({ apiKey: 'your-api-key' });
// Add a memory
await memory.add('User prefers dark mode');
// Recall relevant memories
const results = await memory.recall('What are the user preferences?');
console.log(results);
const memory = new Memory({
apiKey: 'your-api-key', // Required
baseUrl?: 'https://custom.api', // Optional, defaults to api.0latency.ai
timeout?: 30000 // Optional, defaults to 30000ms
});
add(content, options?)Store a new memory.
await memory.add('User loves coffee', {
agentId: 'assistant-1',
metadata: { category: 'preferences', confidence: 0.95 }
});
Parameters:
content (string): The text content to rememberoptions (optional):
agentId (string): Agent identifier for scopingmetadata (object): Key-value metadata to attachReturns: API confirmation payload
recall(query, options?)Retrieve relevant memories using semantic search.
const results = await memory.recall('What does the user like?', {
agentId: 'assistant-1',
limit: 5
});
Parameters:
query (string): Natural-language search queryoptions (optional):
agentId (string): Agent identifier for scopinglimit (number): Maximum results (default: 10)Returns: Matching memories from the API
extract(conversation, options?)Start async memory extraction from a conversation.
const result = await memory.extract([
{ role: 'user', content: 'I love hiking in the mountains' },
{ role: 'assistant', content: 'That sounds wonderful!' }
], { agentId: 'assistant-1' });
console.log('Job ID:', result.job_id);
Parameters:
conversation (array): List of message objects with role and contentoptions (optional):
agentId (string): Agent identifierReturns: Object containing job_id for status polling
extractStatus(jobId)Check the status of an extraction job.
const status = await memory.extractStatus('job-123');
console.log('Status:', status);
Parameters:
jobId (string): The job identifier returned by extract()Returns: Job status payload
health()Check API health.
const health = await memory.health();
console.log('API status:', health);
Returns: Health status payload
import { Memory } from '@0latency/sdk';
const memory = new Memory({ apiKey: process.env.ZEROLATENCY_API_KEY });
async function chatWithMemory(userMessage: string) {
// Recall relevant context
const context = await memory.recall(userMessage, {
agentId: 'chatbot-1',
limit: 3
});
// Generate response using context (pseudo-code)
const response = await generateResponse(userMessage, context);
// Store the conversation for future recall
await memory.extract([
{ role: 'user', content: userMessage },
{ role: 'assistant', content: response }
], { agentId: 'chatbot-1' });
return response;
}
import { Memory } from '@0latency/sdk';
const memory = new Memory({ apiKey: process.env.ZEROLATENCY_API_KEY });
async function codingAgent(projectId: string, userRequest: string) {
// Recall project-specific knowledge
const projectKnowledge = await memory.recall(
`${userRequest} in the context of this project`,
{ agentId: `project-${projectId}`, limit: 5 }
);
// Store important facts about the project
await memory.add('User prefers functional programming style', {
agentId: `project-${projectId}`,
metadata: {
category: 'coding-style',
project: projectId,
timestamp: Date.now()
}
});
return projectKnowledge;
}
import { Memory } from '@0latency/sdk';
const memory = new Memory({ apiKey: process.env.ZEROLATENCY_API_KEY });
async function extractAndPoll(conversation: any[]) {
// Start extraction job
const { job_id } = await memory.extract(conversation, {
agentId: 'assistant-1'
});
// Poll for completion
let status;
do {
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait 1 second
status = await memory.extractStatus(job_id);
} while (status.state === 'processing');
console.log('Extraction complete:', status);
}
The SDK provides custom error classes for different failure modes:
import {
Memory,
AuthenticationError,
RateLimitError,
ZeroLatencyError
} from '@0latency/sdk';
const memory = new Memory({ apiKey: 'your-api-key' });
try {
await memory.add('Some content');
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Invalid API key');
} else if (error instanceof RateLimitError) {
console.error('Rate limit exceeded, retry later');
} else if (error instanceof ZeroLatencyError) {
console.error('API error:', error.message, error.statusCode);
} else {
console.error('Unexpected error:', error);
}
}
Full TypeScript definitions are included. Import types as needed:
import type {
MemoryConfig,
AddMemoryOptions,
RecallOptions,
ConversationMessage
} from '@0latency/sdk';
For older Node.js versions, you can polyfill fetch using node-fetch or undici.
MIT License - see LICENSE file for details.
Contributions welcome! Please open an issue or PR on GitHub.
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.1.0Registry latest | 26 Mar 2026 | 8 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 22:12 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:129e4c96a7cd1c49402f25e695a8e10a257b9513c21080ab6c212584fa4906d1