Installation
fetch). Zero production dependencies.
Client
ThrindexClient is safe to share across concurrent requests — create one instance per application.
Constructor options (ClientOptions)
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | required | Your API key beginning with th_live_ |
baseUrl | string | "https://api.thrindex.com" | Override for self-hosted or test environments |
timeoutMs | number | 30_000 | Per-request timeout in milliseconds |
maxRetries | number | 3 | Maximum retry attempts on 5xx and network errors |
Methods
All methods areasync and return Promise<T>.
add()
Store a memory for asynchronous processing.
AddOptions
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
content | string | yes | — | The memory text. Max 8192 bytes (≈8 KB). |
agentId | string | yes | — | Agent identifier. Max 256 chars. Charset: [A-Za-z0-9._:-] |
userId | string | yes | — | User identifier. Same constraints as agentId. |
confidence | number | no | 1.0 server-side | Your confidence in this memory’s accuracy, 0.0–1.0. |
metadata | Record<string, unknown> | no | — | Arbitrary key-value pairs stored with the memory. |
extract | boolean | no | true | When true, the cognition worker runs LLM extraction on the content. Set to false to store verbatim with no LLM call. |
Returns
Promise<string> — the memory UUID.
search()
Retrieve the most relevant memories for a query.
SearchOptions
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
query | string | yes | — | Natural language query. Max 2048 characters. |
agentId | string | yes | — | Limits search to memories belonging to this agent. |
userId | string | yes | — | Limits search to memories belonging to this user. |
k | number | no | 10 | Number of results to return. Range: 1–100. |
taskContext | string | no | — | A sentence describing what the agent is currently doing. Improves ranking for the current task. |
level | number | no | — (all levels) | Filter to a specific memory level: 0 (raw), 1 (abstraction). |
Returns
Promise<SearchHit[]> — ordered by descending relevance score.
SearchHit
| Field | Type | Description |
|---|---|---|
id | string | Memory UUID |
content | string | The memory text |
agentId | string | Agent that owns the memory |
userId | string | User the memory belongs to |
level | number | 0 or 1 |
status | string | "active" or "deprecated" |
importance | number | Importance score 0.0–1.0 |
confidence | number | Confidence score 0.0–1.0 |
score | number | Multi-signal fusion score — use to compare results within a single response |
createdAt | string | ISO 8601 creation timestamp |
list()
List memories with cursor-based pagination.
ListOptions
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
agentId | string | no | — | Filter to a specific agent. Omit for org-wide listing. |
userId | string | no | — | Filter to a specific user. Omit for all users. |
limit | number | no | 50 | Results per page. Range: 1–200. |
cursor | string | no | — | Opaque cursor from nextCursor of a previous response. Omit for the first page. |
Returns
Promise<ListResponse> with:
results: MemoryRecord[]— current page (content excluded)nextCursor?: string— undefined when no more pages
content is excluded from list results. Call get(memoryId) to retrieve the full record including content.MemoryRecord
| Field | Type | Description |
|---|---|---|
id | string | Memory UUID |
orgId | string | Your organization identifier |
agentId | string | Agent that owns the memory |
userId | string | User the memory belongs to |
level | number | 0 or 1 |
status | string | "active" or "deprecated" |
importance | number | Importance score 0.0–1.0 |
confidence | number | Confidence score 0.0–1.0 |
source | string | Origin of the memory (e.g. "agent") |
createdAt | string | ISO 8601 creation timestamp |
updatedAt | string | ISO 8601 last updated timestamp |
get()
Fetch a single memory by ID, including its content.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
memoryId | string | yes | The memory UUID |
Returns
Promise<MemoryDetail> — all fields of MemoryRecord plus content: string. Throws NotFoundError if the memory does not exist.
delete()
Delete a memory by ID.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
memoryId | string | yes | — | The memory UUID |
options.hard | boolean | no | false | false = soft delete. true = permanent erasure from all stores. Irreversible. |
Returns
Promise<void>. Throws NotFoundError if the memory does not exist.
batchAdd()
Add multiple memories sequentially with per-item retry.
BatchAddItem
| Field | Type | Required | Description |
|---|---|---|---|
content | string | yes | The memory text |
agentId | string | no | Overrides the batch-level agentId |
userId | string | no | Overrides the batch-level userId |
confidence | number | no | Per-item confidence score |
metadata | Record<string, unknown> | no | Per-item metadata |
extract | boolean | no | Overrides the batch-level extract flag |
Returns
Promise<string[]> — memory UUIDs in the same order as the input. Throws on the first unretriable failure.
Error handling
Error classes
| Class | HTTP | Properties |
|---|---|---|
ThrindexError | any | statusCode: number | undefined, message: string |
AuthError | 401 | Extends ThrindexError |
NotFoundError | 404 | Extends ThrindexError |
RateLimitError | 429 | retryAfter: number (seconds) |
Retry behaviour
The SDK automatically retries transient failures:- 5xx errors (
500,502,503,504): up tomaxRetriestimes - 429 Rate limited: waits
Retry-Afterseconds, then retries - Network / timeout errors: retries with exponential backoff
4xx errors (except 429) are never retried. Backoff: min(500ms × 2^attempt + jitter, 30s).
LLM integrations
Drop-in wrappers for OpenAI, Anthropic, and LangChain are available as named exports from subpaths. See Integrations for full details.openai, @anthropic-ai/sdk, @langchain/core) are optional and only required when you use the corresponding integration.