Skip to main content

C# SDK

Complete reference for the official Trix .NET SDK.

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 Trix

Requirements

  • .NET 10.0 or later

Initialization

Basic Setup

Basic.cs
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:

FromEnvironment.cs
// Uses TRIX_API_KEY and optionally TRIX_BASE_URL
using var client = TrixClient.FromEnvironment();

Full Configuration

FullConfig.cs
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:

OptionTypeDefaultDescription
ApiKeystringRequiredYour Trix API key (starts with gdb_)
BaseUrlstring"https://api.trixdb.com"Base URL for API requests
TimeoutTimeSpan30 secondsRequest timeout
MaxRetriesint3Maximum retry attempts for failed requests
JwtTokenstring?nullJWT token for user-scoped authentication
LoggerFactoryILoggerFactory?nullLogger factory for request logging

Resources

The Trix client provides access to resource managers:

Resources.cs
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 synthesis

Quick Example

Here's a quick example to get you started:

QuickStart.cs
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}

Next Steps