Skip to content

TypeScript SDK

@typemo-org/sdk is a typed client for both Typemo APIs. Search, suggestions and events go to the search API; everything else goes to the management API. One object covers both, and its types come from the same OpenAPI document as the API reference.

Terminal window
npm i @typemo-org/sdk
import { Typemo } from '@typemo-org/sdk';
const typemo = new Typemo({ apiKey: process.env.TYPEMO_API_KEY });

It runs on Node 18 or later and in browsers. In a browser, use a Read only key and set searchUrl to your region’s address: see Regions.

OptionWhat it doesDefault
apiKeyThe key, sent as X-API-Key.None
baseUrlThe management API.https://api.typemo.com/v1
searchUrlThe search API: search, suggestions and events. In a browser, your region’s address plus /v1.https://search.typemo.com/v1
fetchA fetch of your own, such as SvelteKit’s event.fetch.The global fetch
credentialsPassed to fetch. include sends cookies.None
interface Product {
title: string;
price: number;
brand: string;
}
const results = await typemo.search<Product>('products', {
q: 'sneakers',
filter: {
AND: [
{ field: 'brand', op: 'eq', value: 'Stride' },
{ field: 'price', op: 'lte', value: 100 }
]
},
sort: 'price:asc',
perPage: 20
});
results.found; // total matches
results.hits[0]?.title; // your document fields, typed, plus id and _score
results.facets.category; // [['Footwear', 3]]
results.fallback?.hits; // on a miss: popular items to show instead

The type parameter types the hits’ fields. Every parameter is optional and matches the Search API one to one. A search goes out as GET, so a repeat is answered from the one-minute cache; a search with a vector goes out as POST.

Collection ids and project ids are the first argument. Lists take { page, perPage } and return { data, page, perPage, total }.

MethodWhat it does
search(collectionId, params)Searches a collection.
suggestions(collectionId, { q, limit, locale })Popular searches, optionally those that match q.
events.track(collectionId, event)Records a search, click, add-to-cart or purchase. See Analytics events.
collections.list · get · create · update · deleteManages collections.
collections.sync(collectionId)Re-reads the collection’s source now: a feed, a store or a crawl.
documents.list(collectionId, query)Lists documents. Takes q, filter, sort and grouped besides paging.
documents.get · deleteReads or deletes one document by id.
documents.upsert(collectionId, { documents })Creates or updates documents by id. Takes any number and sends them 1,000 per request; the counts add up.
documents.deleteMany(collectionId, ids)Deletes up to 1,000 documents. Ids that don’t exist count in notFound.
documents.truncate(collectionId)Deletes every document.
curations.list · get · create · update · deleteManages custom results.
boostRules.list · get · create · update · deleteManages boost rules.
synonyms.list · get · upsert · deleteManages synonyms. upsert creates or replaces the set with that id.
synonyms.batch(collectionId, input)Creates or replaces up to 500 synonym sets in one request.
stopwords.get · updateReads or replaces the collection’s stopword list.
knowledge.list · create · update · deleteManages the AI assistant’s knowledge snippets, per project.
analytics.topQueries · zeroResults · topClickedReads search analytics, per project. from and to are required.
rawThe underlying openapi-fetch client, typed for every route.

Writes need a Write & Read key, so keep that key on your server. Document limits are the same as on every import path: see Formats and limits.

The SDK has no method to replace every document at once. Send that snapshot with PUT /v1/collections/{id}/documents, described in Push over the API.

Every method throws a TypemoError on a response that isn’t 2xx.

PropertyWhat it holds
statusThe HTTP status.
codeThe error code, such as BAD_REQUEST or RATE_LIMITED.
messageWhat went wrong.
paramThe input the API refused, when it names one.
bodyThe parsed response. A refused push carries its per-document report here.
retryAfterOn a 429, the seconds to wait.
rateLimit{ limit, remaining, reset } from the response headers, each only when the API sent it.
import { TypemoError } from '@typemo-org/sdk';
try {
await typemo.search('products', { q: 'sneakers', sort: 'colour:asc' });
} catch (err) {
if (!(err instanceof TypemoError)) throw err;
console.log(err.status, err.code, err.param); // 400 'BAD_REQUEST' 'sort'
}

Next: Search API for every search parameter, or Push over the API to keep your catalog current.