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

# TypeScript SDK

> The official TypeScript SDK — generated types, request signing and webhook verification included.

[`@tetlith/ts-sdk`](https://github.com/Tetlith/ts-sdk) wraps the REST API
in a typed client: request and response shapes come straight from the
same OpenAPI spec that generates [the API reference](https://docs.tetlith.com/api-reference),
and the signed-request auth described in [Authentication](https://docs.tetlith.com/authentication.md)
is handled for you.

```sh npm theme={null}
npm install @tetlith/ts-sdk
```

```sh pnpm theme={null}
pnpm add @tetlith/ts-sdk
```

```sh yarn theme={null}
yarn add @tetlith/ts-sdk
```

## Quickstart

```ts theme={null}
import { Tetlith } from "@tetlith/ts-sdk";

const tetlith = new Tetlith({ auth: { apiKey: process.env.TETLITH_API_KEY! } });

const entity = await tetlith.entities.create({ externalId: "cus_4821", assets: ["USDC_ETH"] });
```

## Resources

A named method per endpoint, grouped the way [the API reference](https://docs.tetlith.com/api-reference)
groups them: `entities`, `accounts`, `transactions`, `activity`,
`compliance`, `policies`, `treasury`, `reconciliation`.

```ts theme={null}
await tetlith.entities.openAccounts(entity.id, { assets: ["USDC_ETH"] });
await tetlith.accounts.getBalance(accountId);
await tetlith.transactions.list({ status: "completed", limit: 20 });
```

`tetlith.api` is still there underneath — the same typed `openapi-fetch`
client, usable directly (`tetlith.api.POST("/v1/entities", { body })`) as
an escape hatch for an endpoint the resources haven't caught up to yet.

## Auth

> [card] Bearer
>
> `{ apiKey }`. Simple, and enough for anything read-only.

> [card] Signed
>
> `{ keyId, signingPrivateKey }`. Binds each request to its method, path,
> body, a timestamp and a nonce with an Ed25519 signature, so a captured
> request can't be replayed or altered. Required for anything that moves
> money.

```ts theme={null}
const tetlith = new Tetlith({
	auth: { keyId: "kp_live_...", signingPrivateKey: process.env.TETLITH_SIGNING_KEY! },
});
```

## Errors

Every non-2xx response throws a `TetlithError` carrying the API's own
`code` and `status`, rather than a response you have to check manually.

```ts theme={null}
import { Tetlith, TetlithError } from "@tetlith/ts-sdk";

try {
	await tetlith.entities.get(entityId);
} catch (err) {
	if (err instanceof TetlithError) {
		console.error(err.code, err.message);
	}
}
```

## Webhooks

`constructWebhookEvent` verifies the signature and timestamp before
handing back the parsed payload — see [Webhooks](https://docs.tetlith.com/webhooks/overview.md) for
the event types it carries.

```ts theme={null}
import { constructWebhookEvent } from "@tetlith/ts-sdk";

const event = constructWebhookEvent(
	rawBody, // the exact bytes your server received, not a re-serialised object
	{
		"x-keypair-timestamp": req.headers["x-keypair-timestamp"],
		"x-keypair-signature": req.headers["x-keypair-signature"],
	},
	process.env.TETLITH_WEBHOOK_SECRET!,
);
```

> [card] [Source and issues](https://github.com/Tetlith/ts-sdk)
>
> The SDK is open source — read the code, file an issue, or open a PR.


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