# TypeScript SDK

> Typed client for the Ladehase API, live updates via server-sent events and webhook verification.

The SDK `@ladehase/sdk` is a lean, fully typed client. It is generated from the OpenAPI description and therefore always matches the API.

## Installation

```bash
npm install @ladehase/sdk
```

## Create a client

```ts
import { ladehase } from "@ladehase/sdk";

const lh = ladehase({ apiKey: process.env.LADEHASE_KEY! });

const { data, error } = await lh.GET("/v1/devices");
if (error) throw new Error(error.title);
for (const device of data.data) console.log(device.id, device.name);
```

Paths, parameters and responses are typed. Your editor suggests endpoints and fields.

## Start and stop charging

```ts
const { data: session } = await lh.POST("/v1/sessions", {
  body: { device_id: "dev_…" },
  headers: { "idempotency-key": crypto.randomUUID() },
});

await lh.POST("/v1/sessions/{id}/stop", { params: { path: { id: session!.id } } });
```

## Preview a tariff

```ts
const { data: preview } = await lh.POST("/v1/tariffs/preview", {
  body: { rules: { energyPrice: 4500, serviceFee: 50 }, energy_wh: [20000] },
});
```

## Verify webhooks

```ts
import { verifyWebhook } from "@ladehase/sdk";

const ok = await verifyWebhook(rawBody, signatureHeader, process.env.LADEHASE_WEBHOOK_SECRET!);
```

The function uses Web Crypto and runs in Node.js, Deno, Bun and edge runtimes. Details under [Webhooks](/en/docs/webhooks).

## Other languages

For other languages, generate a client from the OpenAPI description at [www.ladehase.com/openapi.json](/openapi.json), for example with openapi-generator, or use the REST API directly with any HTTP client.
