# Installation

> Install @mynthio/sdk, set MYNTH_API_KEY, and import from the right entry point.

**pnpm**

```bash
pnpm add @mynthio/sdk
```

**npm**

```bash
npm install @mynthio/sdk
```

**bun**

```bash
bun add @mynthio/sdk
```

**yarn**

```bash
yarn add @mynthio/sdk
```

The package is ESM only. Import the default client:

```ts
import Mynth from "@mynthio/sdk";

const mynth = new Mynth();
```

## API key

Create a `mak_` key with `npx @mynthio/cli api-key create my-app` or in the
[dashboard](https://mynth.io/dashboard/keys), and put it where the server process reads
environment variables:

```bash
MYNTH_API_KEY=mak_...
```

`new Mynth()` does not check the key. The first read of `mynth.image` or
`mynth.video` throws a plain `Error` when there is no `MYNTH_API_KEY` and no
`apiKey` option. `mynth.models.list()` needs no key.
[Authentication](https://mynth.io/docs/authentication.md) covers scopes and spending limits.

## Entry points

The package has four entry points. Import only these.

| Import                        | Exports                                                                              |
| ----------------------------- | ------------------------------------------------------------------------------------ |
| `@mynthio/sdk`                | `Mynth`, `verifyWebhook`, result types, error classes, and the `MynthSDKTypes` types |
| `@mynthio/sdk/next`           | `mynthWebhookHandler` for a Next.js route handler                                    |
| `@mynthio/sdk/tanstack-start` | `mynthWebhookHandler` for a TanStack Start route                                     |
| `@mynthio/sdk/convex`         | `mynthWebhookAction` for a Convex HTTP action                                        |

There is no `@mynthio/sdk/webhooks` entry point. `verifyWebhook()` in the
main entry point verifies a delivery in any other framework and returns the
typed event. `convex` is an optional peer dependency, needed only for
`@mynthio/sdk/convex`. The webhook helpers and `verifyWebhook()` read
`MYNTH_WEBHOOK_SECRET` unless you pass a secret.
[Webhooks](https://mynth.io/docs/concepts/webhooks.md#receive-events) shows each one mounted.

## Optional environment

| Variable               | Used for                                                                    |
| ---------------------- | --------------------------------------------------------------------------- |
| `MYNTH_API_KEY`        | The API key, unless you pass `apiKey`                                       |
| `MYNTH_DESTINATION`    | Default destination for image generation, background removal, and upscaling |
| `MYNTH_WEBHOOK_SECRET` | The `whsec_` secret the webhook helpers verify against                      |

## Next steps

- [Client](https://mynth.io/docs/sdks/typescript/client.md): the constructor options.
- [Generating media](https://mynth.io/docs/sdks/typescript/generating-media.md): the first real call.
