> ## Documentation Index
> Fetch the complete documentation index at: https://docs.larynth.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript SDK

> A typed client for the Larynth API, with a webhook signature verifier.

The TypeScript SDK is generated from the same OpenAPI spec as the [API reference](https://docs.larynth.com/api-reference/introduction.md), so every endpoint has a typed function with typed request and response objects. It needs Node 24 or later.

## Install

```bash theme={null}
npm install @larynth/sdk
```

> [!NOTE]
>
> The SDK is at version 0.1, a beta: it may change between 0.x releases. The source is public at [github.com/Larynth-Labs/larynth-node](https://github.com/Larynth-Labs/larynth-node). Report problems there.

## Configure

Create an API key in the dashboard and keep it in an environment variable. Call `configure` once at startup.

```ts theme={null}
import { configure } from "@larynth/sdk";

configure({
  apiKey: process.env.LARYNTH_API_KEY!,
  baseUrl: "https://api-us.larynth.com",
});
```

Each endpoint is a function named after its operation, such as `listAssistants`, `createCall` or `getCallAnalysis`. The names match the `operationId` shown on every endpoint page.

Functions take one options object with `body`, `path`, `query` and `headers` as the endpoint needs. By default they return `{ data, error, response }`. Pass `throwOnError: true` to get `data` directly and throw on a failed request.

## Example: list assistants

```ts theme={null}
import { listAssistants } from "@larynth/sdk";

const { data } = await listAssistants({
  query: { status: "active", limit: 20 },
  throwOnError: true,
});

for (const assistant of data.data) {
  console.log(assistant.id, assistant.name, assistant.published_version);
}
```

## Example: place a call

`createCall` needs an `Idempotency-Key` so a retry cannot place the call twice. See [idempotency](https://docs.larynth.com/api-reference/idempotency.md). Use only numbers you have the right to call. Outbound calls go through the same compliance checks as a campaign.

```ts theme={null}
import { randomUUID } from "node:crypto";
import { createCall } from "@larynth/sdk";

const { data: call } = await createCall({
  headers: { "Idempotency-Key": randomUUID() },
  body: {
    assistant_id: "3f1c6e0a-5b1d-4c3e-9a57-2d0f4c8d1e11",
    from_e164: "+14155550100",
    to_e164: "+14155550123",
    purpose: "informational",
  },
  throwOnError: true,
});

console.log(call.call_id, call.status);
```

## Example: read a call summary

```ts theme={null}
import { getCallAnalysis } from "@larynth/sdk";

const { data: analysis } = await getCallAnalysis({
  path: { call_id: "call_01J9ZK3Q8M2V7X4N6P5R1T0WYB" },
  throwOnError: true,
});

console.log(analysis.summary);
console.log(analysis.data);
```

## Example: create a webhook endpoint

```ts theme={null}
import { createWebhook } from "@larynth/sdk";

const { data: endpoint } = await createWebhook({
  body: {
    url: "https://example.com/hooks/larynth",
    event_types: ["call.ended", "call.analyzed"],
  },
  throwOnError: true,
});

console.log(endpoint.id);
console.log(endpoint.secret);
```

The secret is shown once. Store it before you leave the script.

## Handle errors

Without `throwOnError`, check `error`. It is the parsed [problem response](https://docs.larynth.com/api-reference/errors.md).

```ts theme={null}
import { getCall } from "@larynth/sdk";

const { data, error, response } = await getCall({
  path: { call_id: "call_01J9ZK3Q8M2V7X4N6P5R1T0WYB" },
});

if (error) {
  console.error(response?.status, error.code, error.title);
} else {
  console.log(data.status);
}
```

## Verify webhooks

```ts theme={null}
import { verifyWebhook } from "@larynth/sdk";

verifyWebhook(process.env.LARYNTH_WEBHOOK_SECRET!, headers, rawBody);
```

`verifyWebhook` throws a `WebhookVerificationError` if the signature or timestamp is wrong. `signWebhook` builds a signature, which is useful in tests. See [verify signatures](https://docs.larynth.com/webhooks/verify-signatures.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.