# Overview

> @mynthio/sdk is the TypeScript client for Mynth. It creates tasks, waits for them, uploads local files, and ships webhook helpers for Next.js, TanStack Start, and Convex.

`@mynthio/sdk` is the TypeScript client for Mynth. Construct one client, pass
a model id and a prompt, and read the file URLs from the result.

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

const mynth = new Mynth(); // reads MYNTH_API_KEY

const task = await mynth.image.generate({
  model: "black-forest-labs/flux.2-pro",
  prompt: "A lighthouse at dusk, film grain",
});

console.log(task.urls[0]);
```

`generate()` creates a task and polls it until it settles. Use
`generateAsync()` when the caller cannot wait, and finish on a webhook.

## What the SDK covers

| Surface                                           | Methods                                                                                          |
| ------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| `mynth.image`                                     | `generate`, `rate`, `alt`, `review`, `removeBackground`, each with an `Async` twin, and `upload` |
| `mynth.video`                                     | `generate`, `generateAsync`, `estimate`, `upload`                                                |
| `mynth.models`                                    | `list`, which needs no API key                                                                   |
| `@mynthio/sdk/next`, `/tanstack-start`, `/convex` | Webhook helpers that verify the signature                                                        |

The SDK does not wrap account management: keys, webhooks, destinations, and
balance. Use the REST API or the CLI for those.

## Rules

- Keep the `mak_` key on the server. A browser polls one task with the `pat_`
  token from the create response. See [tasks and polling](https://mynth.io/docs/sdks/typescript/tasks.md#poll-from-the-browser).
- Pass a model id. Omitting `model` makes the API use `auto`, which is
  experimental. See [the model field](https://mynth.io/docs/models.md#auto-is-experimental).
- `urls` and `getImages()` skip failed images. Compare with the `count` you
  sent when a partial result matters.

## In this section

| Page                                                       | Covers                                                         |
| ---------------------------------------------------------- | -------------------------------------------------------------- |
| [Installation](https://mynth.io/docs/sdks/typescript/installation.md)         | The package, the key, and the entry points                     |
| [Client](https://mynth.io/docs/sdks/typescript/client.md)                     | `apiKey`, `baseUrl`, and the default destination               |
| [Generating media](https://mynth.io/docs/sdks/typescript/generating-media.md) | Image, video, and tool calls, and what the result classes hold |
| [Tasks and polling](https://mynth.io/docs/sdks/typescript/tasks.md)           | `generateAsync()`, poll intervals, and the browser token       |
| [Errors](https://mynth.io/docs/sdks/typescript/errors.md)                     | `MynthAPIError` and the errors a wait throws                   |

## Next steps

- [Installation](https://mynth.io/docs/sdks/typescript/installation.md): add the package and set the key.
- [Generate images](https://mynth.io/docs/guides/generate-images.md): every field `image.generate()` sends.
- [Webhooks](https://mynth.io/docs/concepts/webhooks.md): the helpers, mounted per framework.
