C# SDK
Reference for the Smritea C# SDK. Install it, create a client, and call AddAsync, SearchAsync, GetAsync and DeleteAsync.
The C# SDK is the Smritea.Sdk NuGet package. It gives you an async SmriteaClient with four calls: AddAsync, SearchAsync, GetAsync and DeleteAsync. The package targets .NET 10.
Install
dotnet add package Smritea.SdkImport the namespace:
using Smritea.Sdk;Create a client
SmriteaClient takes your API key and your app ID. You must pass both, and a null value throws ArgumentNullException. The client implements IDisposable. Create the keys in the dashboard; see Create an app and API key.
| Constructor parameter | Type | Default | Description |
|---|---|---|---|
apiKey | string | none | The API key, in the form smrt_<prefix>_<secret>. |
appId | string | none | The app ID, in the form app_.... |
baseUrl | string? | https://api-us.smritea.ai | The host for your region. See Regions. |
maxRetries | int | 2 | Retries after a rate limit. 0 turns retries off. |
traceId | string? | null | A trace ID to send with each call. A bad value throws ArgumentException. |
httpClient | HttpClient? | a new client | Your own HTTP client. Set timeouts here. |
The client has no timeout parameter. Set a timeout on the HttpClient you pass in. Dispose does not dispose a client you supplied.
Methods
Every method takes a CancellationToken ct = default as its last argument.
| Method | Returns | Description |
|---|---|---|
AddAsync(content, opts) | Task<MemoryCreationResult> | Extracts and stores memories from the text. |
SearchAsync(query, opts) | Task<IReadOnlyList<SearchResult>> | Finds memories that match the query. |
GetAsync(memoryId) | Task<Memory> | Returns one memory by ID. |
DeleteAsync(memoryId) | Task | Deletes one memory by ID. |
The opts argument is optional. The GetAllAsync method exists but throws NotImplementedException. Use SearchAsync to find memories.
The names Memory, MemoryCreationResult and SearchResult are the SDK's own short names for generated types. Only the SDK assembly can use these short names. Your code can name the public generated types in Smritea.Internal.Autogen.Model: MemoryResponse, CreateMemoryResponse and SearchMemoryResponse. Declare results with var. To name one, add an alias such as using SearchResult = Smritea.Internal.Autogen.Model.SearchMemoryResponse;.
Add options
Build options with the fluent methods on new AddOptions().
| Method | Description |
|---|---|
WithScope(scope) | Who and what the memory belongs to. |
WithMetadata(dictionary) | Values must be strings, integers or floats. |
WithEventOccurredAt(string) | An RFC 3339 string, such as 2026-11-05T10:00:00Z. Smritea uses it to resolve words like "yesterday" and to date the memory. |
WithRelativeStanding(RelativeStanding) | The importance and decay settings for the memory. |
Build a RelativeStanding with new RelativeStanding(). Chain WithImportance(float), WithDecayFactor(float) and WithDecayFunction(string). The importance ranges from 0 to 1. The decay factor is 0 or higher. The decay function takes exponential, gaussian or linear. Decay affects quick_search, context_aware_search and deep_search with temporal or rrf_temporal; importance affects deep_search with rrf or rrf_temporal.
Search options
Build options with the fluent methods on new SearchOptions().
| Method | Description |
|---|---|
WithScope(scope) | Limits results to this scope. |
WithSpeakerActorId(id) | Who is asking. It never filters results. |
WithLimit(n) | Most results to return. Omit it to use the app default. |
WithMethod(m) | quick_search, deep_search or context_aware_search. |
WithRerankerType(r) | Applies to deep_search only. See Search methods and rerankers. |
WithGraphDepth(n) | A value from 1 to 5. |
WithValidAt(t) | An RFC 3339 time. Returns memories valid at that moment. |
WithFromTime(t), WithToTime(t) | An RFC 3339 range. Use either one alone for an open range. |
WithMetadataFilter(dictionary) | See Filter by metadata. |
You cannot combine WithValidAt with WithFromTime or WithToTime.
Memory scope
Build a scope with new MemoryScope() and its With methods. Every field is optional. See Memory scope for the rules.
| Method | Description |
|---|---|
WithActorId(id) | The actor's ID, up to 64 characters. Set it with WithActorType. |
WithActorType(type) | user, agent or system. |
WithActorName(name) | A display name, up to 255 characters. Used by AddAsync only. |
WithConversationId(id) | A conversation ID, up to 64 characters. |
WithSourceType(type) | conversation, document or api. Defaults to api. |
WithParticipantIds(list) | A list of one or more IDs. Search only. |
Results
SearchAsync returns a list of results. Each one has a Score and a Memory.
| Property | Description |
|---|---|
Score | The relevance score. |
Memory.Content | The memory text. |
Memory.Id | The memory ID. |
Memory.Metadata | The metadata you stored. |
Memory.Scope | The scope fields of the memory. |
AddAsync returns a MemoryCreationResult.
| Property | Description |
|---|---|
Memories | The memories the call stored. Empty when ExplicitSkip is true. |
FactsExtracted | How many facts the text held. |
SkippedCount | How many facts the call skipped. |
UpdatedCount | How many existing memories the call updated. |
ExplicitSkip | True when nothing was worth storing. |
Exceptions
Every error derives from SmriteaException. The SDK picks the class from the HTTP status.
| Exception | HTTP status | When |
|---|---|---|
SmriteaBadRequestException | 400 | A parameter is invalid. |
SmriteaUnauthorizedException | 401 | The API key is missing or wrong. |
SmriteaPaymentRequiredException | 402 | Your plan quota has run out. |
SmriteaForbiddenException | 403 | The key cannot do this. |
SmriteaNotFoundException | 404 | The memory does not exist. |
SmriteaConflictException | 409 | The request conflicts with current state. |
SmriteaUnprocessableException | 422 | The request is well formed but not allowed. |
SmriteaTooManyRequestsException | 429 | You hit a rate limit. |
SmriteaException | other | Any other failure, including 5xx. |
Each exception has HTTPStatus, Code, Retryable, Body and RequestId. SmriteaTooManyRequestsException also has RetryAfter, in seconds.
The SDK retries a 429 up to maxRetries times. It never retries a 402. For every code, see Errors and codes.
Example
This program stores a memory, searches for it and handles the failures.
using Smritea.Sdk;
var client = new SmriteaClient(
apiKey: Environment.GetEnvironmentVariable("SMRITEA_API_KEY")!,
appId: Environment.GetEnvironmentVariable("SMRITEA_APP_ID")!);
var alice = new MemoryScope()
.WithActorId("alice")
.WithActorType("user");
try
{
await client.AddAsync("Alice is vegetarian and loves hiking",
new AddOptions().WithScope(alice));
var results = await client.SearchAsync("What does Alice eat?",
new SearchOptions().WithScope(alice));
foreach (var r in results)
Console.WriteLine($"{r.Score:F2} {r.Memory.Content}");
}
catch (SmriteaPaymentRequiredException)
{
Console.WriteLine("Plan quota used up (402)");
}
catch (SmriteaTooManyRequestsException ex)
{
Console.WriteLine($"Rate limited. Retry in {ex.RetryAfter}s");
}
catch (SmriteaException ex)
{
Console.WriteLine($"{ex.HTTPStatus} {ex.Code} {ex.RequestId}");
}Don't see your language? Request it on GitHub. Search existing requests first and add a 👍 if yours is there. That helps the Smritea team rank requests.
Last updated on



