# Client

> The Mynth constructor options, where the key, base URL, and default destination come from, and the image, video, and models clients.

`new Mynth()` with no arguments reads `MYNTH_API_KEY` and sends requests to
`https://api.mynth.io`. Pass options only when a default is wrong:

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

const mynth = new Mynth({
  apiKey: process.env.MYNTH_API_KEY,
  baseUrl: "https://api.mynth.io",
  destination: "product-photos",
});
```

| Option        | Default                | What it does                                                          |
| ------------- | ---------------------- | --------------------------------------------------------------------- |
| `apiKey`      | `MYNTH_API_KEY`        | The bearer key. Missing, it throws on first use of `image` or `video` |
| `baseUrl`     | `https://api.mynth.io` | A proxy or test host. A trailing slash is removed                     |
| `destination` | `MYNTH_DESTINATION`    | Default destination name for image generation and background removal  |

An option wins over its environment variable, and a `destination` on a
request wins over both. Video has no destinations, so `mynth.video` ignores
the option.

## The three clients

| Property       | Holds                                                                  |
| -------------- | ---------------------------------------------------------------------- |
| `mynth.image`  | Image generation, rating, alt text, review, background removal, upload |
| `mynth.video`  | Video generation, estimates, upload                                    |
| `mynth.models` | `list()`: the public catalog, `GET /models`, no key needed             |

`image` and `video` are created the first time you read them, and that is when
a missing key throws:

```text
Mynth API key is required. Either pass it as an option or set the MYNTH_API_KEY environment variable.
```

The throw is a plain `Error`, not a `MynthAPIError`.

`models.list()` returns image and video entries together. Filter on `type`.
[The model field](https://mynth.io/docs/models.md#reading-a-catalog-entry) describes each entry.

`MynthImage` and `MynthVideo` are also exported for code that needs only one
side. `MynthVideo` takes `apiKey` and `baseUrl`. Types live on
`MynthSDKTypes`:

```ts
import type { MynthSDKTypes } from "@mynthio/sdk";
```

## Next steps

- [Generating media](https://mynth.io/docs/sdks/typescript/generating-media.md): `image.generate()` and `video.generate()`.
- [Tasks and polling](https://mynth.io/docs/sdks/typescript/tasks.md): keep the wait out of a request handler.
