TypeScript SDK
Install and use the Cerebe TypeScript SDK.
TypeScript SDK
The official TypeScript SDK for Cerebe. Works in Node.js 18+, browsers, Deno, and Bun.
Installation
npm install @cerebe/sdkQuick Start
import Cerebe from '@cerebe/sdk'
const client = new Cerebe({
apiKey: 'ck_live_...',
})
// Store a memory
await client.memory.add({
content: 'User prefers visual explanations',
sessionId: 'session_abc',
type: 'semantic',
importance: 0.8,
})
// Search memories
const results = await client.memory.search({
query: 'What does the user prefer?',
sessionId: 'session_abc',
})Resources
client.memory // Memory operations (add, search, harvest, consolidate)
client.knowledge // Knowledge graph (ingest, query, entities, visualize)
client.rag // Retrieval-Augmented Generation (embed, search, stats)
client.storage // File storage (upload, presigned URLs, extract)
client.metaLearning // PLRE state, learning pattern analysis
client.agents // Agent trace ingestion, working memory
client.sessions // Session management, cognitive state
client.graph // Graph traversal, temporal viewsRAG Quick Start
import { readFile } from 'node:fs/promises'
// Embed a document (Node.js)
await client.rag.embed({
source: 'docs/auth.md',
content: await readFile('docs/auth.md', 'utf-8'),
})
// Semantic search — returns top-k chunks ranked by similarity
const results = await client.rag.search({
query: 'how does authentication work?',
k: 3,
})
for (const r of results.data.results) {
console.log(r.source, r.score)
}See RAG docs for the full API reference.
Error Handling
import Cerebe, { AuthenticationError, RateLimitError, NotFoundError } from '@cerebe/sdk'
try {
const result = await client.memory.search({ query: '...', sessionId: 'sess_1' })
} catch (error) {
if (error instanceof AuthenticationError) {
console.log('Invalid API key')
} else if (error instanceof RateLimitError) {
console.log(`Retry after ${error.retryAfter}s`)
} else if (error instanceof NotFoundError) {
console.log('Resource not found')
}
}Agent Integration
// Ingest execution traces
await client.agents.ingestTrace({
content: 'Called search tool with query "quadratic formula"',
sessionId: 'sess_123',
metadata: { tool: 'search', latency_ms: 120 },
})
// Set working memory with TTL
await client.agents.setWorkingMemory({
content: 'Current task: algebra homework',
sessionId: 'sess_123',
ttlSeconds: 3600,
})Configuration
| Parameter | Environment Variable | Default |
|---|---|---|
apiKey | CEREBE_API_KEY | — (required) |
project | CEREBE_PROJECT | "" |
baseUrl | CEREBE_BASE_URL | https://api.cerebe.ai |
timeout | — | 30000 (ms) |
maxRetries | — | 3 |
Requirements
- Node.js 18+ / modern browser / Deno / Bun
- TypeScript 5.0+ (optional, for type checking)