Overview
The official Trix TypeScript SDK provides a fully-typed client for integrating
memory capabilities into your Node.js and browser applications. Built with
zero dependencies, it uses native fetch and provides comprehensive
error handling, automatic retries, and async iteration.
This SDK works in both Node.js 18+ and modern browsers. For older environments,
you may need to polyfill fetch.
Key Features
- Full TypeScript support - Complete type definitions for all APIs
- Zero dependencies - Uses native fetch, works in Node.js 18+ and browsers
- Automatic retries - Exponential backoff with jitter for failed requests
- Async iteration - Stream through paginated results with
for await - Interceptors - Hook into request/response lifecycle
- Comprehensive errors - Typed error classes for precise error handling
Installation
Install the SDK using your preferred package manager:
npm install @trixdb/clientRequirements
- Node.js 18+ (for native fetch support)
- TypeScript 4.7+ (optional, for type checking)
Initialization
Basic Setup
import { Trix } from '@trixdb/client';
const trix = new Trix({
apiKey: 'gdb_your_api_key'
});From Environment Variables
The SDK can automatically read configuration from environment variables:
// Uses TRIX_API_KEY and optionally TRIX_BASE_URL
const trix = Trix.fromEnv();
// With additional options
const trix = Trix.fromEnv({
timeout: 60000,
maxRetries: 5
});Full Configuration
import { Trix } from '@trixdb/client';
const trix = new Trix({
// Required
apiKey: 'gdb_your_api_key',
// Optional settings
baseUrl: 'https://api.trixdb.com', // API endpoint
timeout: 30000, // Request timeout in ms
maxRetries: 3, // Retry attempts for failed requests
// Development options
allowInsecure: false, // Allow HTTP (local dev only)
// Custom fetch implementation
fetch: customFetch,
// Interceptors for request/response handling
requestInterceptors: [],
responseInterceptors: [],
errorInterceptors: []
});Configuration Options
Complete list of configuration options:
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | Required | Your Trix API key (starts with gdb_) |
baseUrl | string | 'https://api.trixdb.com' | Base URL for API requests |
timeout | number | 30000 | Request timeout in milliseconds |
maxRetries | number | 3 | Maximum retry attempts for failed requests |
allowInsecure | boolean | false | Allow HTTP connections (development only) |
fetch | Function | Native fetch | Custom fetch implementation |
Resources
The Trix client provides access to 32 resource managers:
trix.memories // Memory objects
trix.knowledge // Knowledge summaries and synthesis
trix.relationships // Connections between memories
trix.clusters // Groups of related memories
trix.spaces // Isolated knowledge spaces
trix.graph // Knowledge graph traversal
trix.search // Semantic search and embeddings
trix.webhooks // Event webhooks
trix.agent // Agent sessions and operations
trix.feedback // User feedback management
trix.highlights // Text highlights within memories
trix.facts // Extracted facts
trix.entities // Named entities
trix.enrichments // Memory enrichment operations
trix.invites // Team invitations
trix.sessions // Session management
trix.resources // External resources
trix.tasks // Task tracking
trix.habits // Habit tracking
trix.personas // AI personas
trix.bots // Bot management
trix.skills // Bot skills
trix.goals // Goal tracking
trix.workflows // Workflow automation
trix.notes // Structured notes
trix.templates // Note and workflow templates
trix.crews // Crew management
trix.hubs // Hub management
trix.files // File management
trix.presets // Agent presets
trix.calendar // Calendar integration
trix.spaceConfig // Space configurationQuick Example
Here's a quick example to get you started with creating and searching memories:
import { Trix } from '@trixdb/client';
// Initialize client
const trix = Trix.fromEnv();
// Create a memory
const memory = await trix.memories.create({
content: 'TypeScript provides static type checking at compile time',
tags: ['typescript', 'programming']
});
console.log('Created:', memory.id);
// Search memories
const results = await trix.memories.list({
q: 'type checking',
mode: 'semantic',
limit: 5
});
for (const mem of results.data) {
console.log(mem.content);
}SDK Reference
The TypeScript SDK documentation is organized into the following sections:
Next Steps
- Memories API - Learn how to create and search memories
- Graph & Relationships - Build knowledge graphs
- Advanced Topics - Error handling and best practices