TypeScript SDK
Reference for the Smritea TypeScript SDK. Install it, create a client, and call add, search, get and delete.
The TypeScript SDK is the smritea-sdk package. It gives you an async SmriteaClient with four calls: add, search, get and delete. It ships both ESM and CommonJS builds.
Install
npm install smritea-sdkImport the client from smritea-sdk:
import { SmriteaClient } from 'smritea-sdk';Create a client
SmriteaClient takes one config object. You must set apiKey and appId. Create them in the dashboard; see Create an app and API key.
| Option | 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 | number | 2 | Retries after a rate limit. 0 turns retries off. |
traceId | string | none | A trace ID to send with each call. A bad value throws TypeError. |
fetch | typeof fetch | global fetch | Your own fetch function. Set timeouts here. |
The client has no timeout option. Pass a fetch that sets one.
Methods
The table lists the client methods and what each one returns.
| Method | Returns | Description |
|---|---|---|
add(content, options?) | Promise<MemoryCreationResult> | Extracts and stores memories from the text. |
search(query, options?) | Promise<SearchResult[]> | Finds memories that match the query. |
get(memoryId) | Promise<Memory> | Returns one memory by ID. |
delete(memoryId) | Promise<void> | Deletes one memory by ID. |
The getAll method exists but throws an error. Use search to find memories.
Add options
The table lists the options that add accepts.
| Option | Type | Description |
|---|---|---|
scope | MemoryScope | Who and what the memory belongs to. |
metadata | Record<string, ...> | Values must be strings, integers or floats. |
eventOccurredAt | 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. |
relativeStanding | object | The importance and decay settings for the memory. |
Pass relativeStanding as an object literal, such as { importance: 0.9, decayFactor: 0.5, decayFunction: 'exponential' }. The package does not export a type for it, so pass the literal inline or add as const. importance ranges from 0 to 1. decayFactor is 0 or higher. decayFunction 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
The table lists the options that search accepts.
| Option | Type | Description |
|---|---|---|
scope | MemoryScope | Limits results to this scope. |
speakerActorId | string | Who is asking. It never filters results. |
limit | number | Most results to return. Omit it to use the app default. |
method | string | quick_search, deep_search or context_aware_search. |
rerankerType | string | Applies to deep_search only. See Search methods and rerankers. |
graphDepth | number | A value from 1 to 5. |
validAt | string | An RFC 3339 time. Returns memories valid at that moment. |
fromTime, toTime | string | An RFC 3339 range. Use either one alone for an open range. |
metadataFilter | object | See Filter by metadata. |
You cannot combine validAt with fromTime or toTime. Put actor and conversation fields inside scope. The client ignores them anywhere else.
Memory scope
MemoryScope decides who a memory belongs to. Every field is optional. See Memory scope for the rules.
| Field | Description |
|---|---|
actorId | The actor's ID, up to 64 characters. Set it with actorType. |
actorType | user, agent or system. |
actorName | A display name, up to 255 characters. Used by add only. |
conversationId | A conversation ID, up to 64 characters. |
sourceType | conversation, document or api. Defaults to api. |
participantIds | An array of one or more IDs. Search only. |
Results
search returns an array of SearchResult. Each one has a score and a memory. The memory field is optional in the type, so read it with ?..
| Field | 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. |
add returns a MemoryCreationResult.
| Field | 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 SmriteaError. The SDK picks the class from the HTTP status.
| Exception | HTTP status | When |
|---|---|---|
SmriteaBadRequestError | 400 | A parameter is invalid. |
SmriteaUnauthorizedError | 401 | The API key is missing or wrong. |
SmriteaPaymentRequiredError | 402 | Your plan quota has run out. |
SmriteaForbiddenError | 403 | The key cannot do this. |
SmriteaNotFoundError | 404 | The memory does not exist. |
SmriteaConflictError | 409 | The request conflicts with current state. |
SmriteaUnprocessableError | 422 | The request is well formed but not allowed. |
SmriteaTooManyRequestsError | 429 | You hit a rate limit. |
SmriteaError | other | Any other failure, including 5xx. |
Each exception has httpStatus, code, retryable, body and requestId. SmriteaTooManyRequestsError 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 script stores a memory, searches for it and handles the failures.
import {
SmriteaClient,
SmriteaError,
SmriteaPaymentRequiredError,
SmriteaTooManyRequestsError,
} from 'smritea-sdk';
const client = new SmriteaClient({
apiKey: process.env.SMRITEA_API_KEY!,
appId: process.env.SMRITEA_APP_ID!,
});
const scope = { actorId: 'alice', actorType: 'user' as const };
try {
await client.add('Alice is vegetarian and loves hiking', { scope });
const results = await client.search('What does Alice eat?', { scope });
for (const r of results) {
console.log(r.score, r.memory?.content);
}
} catch (e) {
if (e instanceof SmriteaPaymentRequiredError) {
console.log('Plan quota used up (402)');
} else if (e instanceof SmriteaTooManyRequestsError) {
console.log(`Rate limited. Retry in ${e.retryAfter}s`);
} else if (e instanceof SmriteaError) {
console.log(e.httpStatus, e.code, e.requestId);
} else {
throw e;
}
}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



