---
title: "TypeScript"
description: "The @mentio-dev/sdk package, one typed function per endpoint."
canonical: https://docs.mentio.dev/sdks/typescript
markdown: https://docs.mentio.dev/sdks/typescript.mdx
---

# TypeScript

The @mentio-dev/sdk package, one typed function per endpoint.

`@mentio-dev/sdk` is the Mentio API as typed TypeScript: one function per endpoint with the same name as the reference (`searchMentions`, `createKeyword`, `getAnalyticsSummary`), request and response types included. It is generated from the same OpenAPI document that produces the [API Reference](/api), so it cannot drift from the deployed API. Node 22+, Bun, Deno and browsers; no runtime dependencies.

```bash
npm install @mentio-dev/sdk
```

## Use it

```ts
import { createMentio } from '@mentio-dev/sdk';

const mentio = createMentio({ apiKey: process.env.MENTIO_API_KEY! });

const { data, error } = await mentio.searchMentions({
  query: { platform: 'reddit', relevant: true, limit: 25 },
});
if (error) throw new Error(error.error.message);

for (const mention of data.data) {
  console.log(mention.post.platform, mention.classification?.relevance, mention.post.url);
}
```

`createMentio` binds the key and the host once. Every call resolves to `{ data, error, request, response }`: on a 2xx `data` is the typed body and `error` is `undefined`; on anything else `error` is the API's [error envelope](/errors) and `data` is `undefined`. Pass `throwOnError: true` to get `data` alone and an exception instead:

```ts
const keyword = await mentio.createKeyword({ body: { term: 'acme', kind: 'brand' }, throwOnError: true });
console.log(keyword.data.id);
```

## Every endpoint, the same way

Path ids go under `path`, filters under `query`, bodies under `body`:

```ts
await mentio.updateMention({ path: { id: 'mm_7f3a...' }, body: { status: 'done' } });
await mentio.getPerson({ path: { id: 'aut_1c2d...' } });
await mentio.createAlert({
  body: { name: 'Negative mentions', mode: 'instant', event: 'mention.negative', filter: { sentiments: ['negative'] }, channelIds: ['dest_...'] },
});
await mentio.getAnalyticsSummary({ query: { range: '7d', compare: true, timezone: 'Europe/Madrid' } });
```

Page a list by passing `nextCursor` back as `cursor` until it comes back `null`:

```ts
let cursor: string | undefined;
do {
  const { data } = await mentio.searchMentions({ query: { relevant: true, limit: 100, cursor }, throwOnError: true });
  for (const mention of data.data) handle(mention);
  cursor = data.nextCursor ?? undefined;
} while (cursor);
```

CSV exports come back as text:

```ts
const { data: csv } = await mentio.exportMentionsCsv({ query: { since: '2026-09-01T00:00:00Z' }, parseAs: 'text', throwOnError: true });
```

## Types

Every shape in the reference is exported: `Mention`, `Keyword`, `Person`, `Segment`, `Alert`, `Channel`, `Company`, `AnalyticsSummary`, `AnalyticsSeries`, `AnalyticsBreakdown`, `ShareOfVoice`, plus `<Operation>Data` and `<Operation>Response` for every call.

```ts
import type { Mention, SearchMentionsData } from '@mentio-dev/sdk';

type Filters = NonNullable<SearchMentionsData['query']>;
```

## Another host, another fetch

```ts
const mentio = createMentio({
  apiKey,
  baseUrl: 'https://api.mentio.internal',
  fetch: myFetch,
  headers: { 'x-request-source': 'billing-job' },
});
```

`mentio.client` is the underlying client: add request or response interceptors on `mentio.client.interceptors`, or send a raw request with `mentio.client.request(...)`.
