Overview
The official Trix .NET SDK provides a fully-typed client for integrating memory capabilities into your .NET applications. Built with modern C# features, it provides comprehensive error handling, automatic retries with exponential backoff, async/await support, and Microsoft.Extensions.Logging integration.
If you're using Python or TypeScript, check out the Python SDK or TypeScript SDK for a more idiomatic experience in those languages.
Key Features
- Full .NET 10 support - Built with latest C# language features
- Strongly typed - Complete type definitions for all APIs
- Automatic retries - Exponential backoff with jitter for failed requests
- Async enumerable - Stream through paginated results with
await foreach - Cancellation support - Full CancellationToken support throughout
- Comprehensive exceptions - Typed exception hierarchy for precise error handling
- Logging integration - Microsoft.Extensions.Logging support
Installation
Install the SDK using your preferred method:
dotnet add package TrixRequirements
- .NET 10.0 or later
Initialization
Basic Setup
using Trix;
// Create client with API key
using var client = new TrixClient("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
using var client = TrixClient.FromEnvironment();Full Configuration
using Trix;
var options = new TrixClientOptions
{
// Required
ApiKey = "gdb_your_api_key",
// Optional settings
BaseUrl = "https://api.trixdb.com", // API endpoint
Timeout = TimeSpan.FromSeconds(30), // Request timeout
MaxRetries = 3, // Retry attempts for failed requests
// Logging (optional)
LoggerFactory = loggerFactory
};
using var client = new TrixClient(options);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 | TimeSpan | 30 seconds | Request timeout |
MaxRetries | int | 3 | Maximum retry attempts for failed requests |
JwtToken | string? | null | JWT token for user-scoped authentication |
LoggerFactory | ILoggerFactory? | null | Logger factory for request logging |
Resources
The Trix client provides access to resource managers:
client.Memories // Memory objects
client.Relationships // Connections between memories
client.Clusters // Groups of related memories
client.Spaces // Isolated knowledge spaces
client.Graph // Knowledge graph traversal
client.Search // Semantic and keyword search
client.Webhooks // Webhook management
client.Agent // Agent execution
client.Feedback // User feedback
client.Highlights // Memory highlights
client.Jobs // Background job tracking
client.Facts // Extracted facts
client.Entities // Named entities
client.Enrichments // Memory enrichment
client.Sessions // CLI session management
client.Resources // Resource management
client.SpaceConfig // Space configuration
client.HubRoles // Hub role management
client.Calendar // Calendar integration
client.Knowledge // Knowledge synthesisQuick Example
Here's a quick example to get you started:
1using Trix;
2using Trix.Models;
3
4// Initialize client
5using var client = TrixClient.FromEnvironment();
6
7// Create a memory
8var memory = await client.Memories.CreateAsync(new CreateMemoryRequest
9{
10 Content = "User prefers dark mode and compact layouts",
11 Tags = new List<string> { "preferences", "ui" }
12});
13
14Console.WriteLine($"Created memory: {memory.Id}");
15
16// Search for memories
17var results = await client.Memories.ListAsync(new ListMemoriesRequest
18{
19 Q = "user preferences",
20 Mode = SearchMode.Semantic,
21 Limit = 10
22});
23
24foreach (var m in results.Data)
25{
26 Console.WriteLine($"- {m.Content}");
27}