# Create destination

> Registers a bucket Mynth can deliver finished media to. The secret is write-only: it is stored encrypted and never returned by any endpoint. `name` is the slug you reference from a task's `destination` field, and it cannot be changed afterwards.

A destination is storage of yours that Mynth writes finished images into, so
`url` on the result points at your own domain. Name it on a generation request
with its `name`, not its id.

The secret is write-only: it is stored in a vault and no endpoint returns it.
`name` cannot be changed later. [Destinations](https://mynth.io/docs/concepts/destinations.md#path-and-url-templates)
covers the path and URL templates, which is where most of the configuration
is.

`POST /destinations`

**Auth:** API key or OAuth token

## Request body

### bunny

- `name` (required, string) — Destination slug. Immutable after creation. Matches /^[a-z0-9-]+$/. ≥ 1 characters, ≤ 64 characters, matches `^[a-z0-9-]+$`.
- `config` (required, object)
  - `path_template` (required, string) — ≤ 2048 characters.
  - `url_template` (string) — URL template used to create an image URL. It must include a `{path}` which is a resolved path to file from `path_template`. Example: path_template -> "/images/{id}" On upload `path` becomes `/images/img_si1EywtFZMvDArkcVSSsN759VFNbHtE_.webp` url_template: "https://my-cdn.my-domain.com/{path}" The `url` in the response will be: "https://my-cdn.my-domain.com/images/img_si1EywtFZMvDArkcVSSsN759VFNbHtE_.webp" Note: The double `//` are automatically removed and replaced with single slash. format: includes, matches `\{path\}`.
- `provider` (required, object)
  - `id` (required, "bunny")
  - `storage_zone` (required, string)
  - `region` (string) — One of: `"de"`, `"uk"`, `"ny"`, `"la"`, `"sg"`, `"se"`, `"br"`, `"jh"`, `"syd"`.
- `secret` (required, object)
  - `password` (required, string)

### r2

- `name` (required, string) — Destination slug. Immutable after creation. Matches /^[a-z0-9-]+$/. ≥ 1 characters, ≤ 64 characters, matches `^[a-z0-9-]+$`.
- `config` (required, object)
  - `path_template` (required, string) — ≤ 2048 characters.
  - `url_template` (string) — URL template used to create an image URL. It must include a `{path}` which is a resolved path to file from `path_template`. Example: path_template -> "/images/{id}" On upload `path` becomes `/images/img_si1EywtFZMvDArkcVSSsN759VFNbHtE_.webp` url_template: "https://my-cdn.my-domain.com/{path}" The `url` in the response will be: "https://my-cdn.my-domain.com/images/img_si1EywtFZMvDArkcVSSsN759VFNbHtE_.webp" Note: The double `//` are automatically removed and replaced with single slash. format: includes, matches `\{path\}`.
- `provider` (required, object)
  - `id` (required, "r2")
  - `account_id` (required, string)
  - `bucket` (required, string)
  - `jurisdiction` (string) — One of: `"default"`, `"eu"`, `"fedramp"`.
- `secret` (required, object)
  - `access_key_id` (required, string)
  - `secret_access_key` (required, string)

### s3

- `name` (required, string) — Destination slug. Immutable after creation. Matches /^[a-z0-9-]+$/. ≥ 1 characters, ≤ 64 characters, matches `^[a-z0-9-]+$`.
- `config` (required, object)
  - `path_template` (required, string) — ≤ 2048 characters.
  - `url_template` (string) — URL template used to create an image URL. It must include a `{path}` which is a resolved path to file from `path_template`. Example: path_template -> "/images/{id}" On upload `path` becomes `/images/img_si1EywtFZMvDArkcVSSsN759VFNbHtE_.webp` url_template: "https://my-cdn.my-domain.com/{path}" The `url` in the response will be: "https://my-cdn.my-domain.com/images/img_si1EywtFZMvDArkcVSSsN759VFNbHtE_.webp" Note: The double `//` are automatically removed and replaced with single slash. format: includes, matches `\{path\}`.
- `provider` (required, object)
  - `id` (required, "s3")
  - `bucket` (required, string)
  - `region` (required, string)
  - `endpoint` (string)
  - `force_path_style` (boolean)
- `secret` (required, object)
  - `access_key_id` (required, string)
  - `secret_access_key` (required, string)

## Response

### 201 — Destination created

- `data` (required, object)
  - `id` (required, string)
  - `name` (required, string)
  - `provider` (required, json)
  - `config` (required, json)
  - `created_at` (required, string) — format: date-time.
  - `updated_at` (required, string) — format: date-time.

```json
{
  "data": {
    "id": "string",
    "name": "string",
    "provider": {},
    "config": {},
    "created_at": "string",
    "updated_at": "string"
  }
}
```

### 400 — The request was rejected before anything was queued. `error.message` says what to change. A field that failed the schema, or one the endpoint does not take, is also listed in `error.issues`.

- `error` (required, object)
  - `code` (required, string) — `validation_error` for a body that failed validation, `invalid_json` for one that is not JSON. One of: `"validation_error"`, `"invalid_json"`.
  - `message` (required, string) — Every problem, in one sentence each, led by the field it is about.
  - `issues` (object[]) — One entry per field that failed the schema, and one per field the endpoint does not take.
    - `path` (required, (string | integer)[]) — Where the problem is, e.g. `["inputs", 0, "source"]`. Empty for the body as a whole.
    - `message` (required, string)

```json
{
  "error": {
    "code": "validation_error",
    "message": "count: Too big: expected number to be <=20. colour: Unknown field.",
    "issues": [
      {
        "path": [
          "count"
        ],
        "message": "Too big: expected number to be <=20"
      },
      {
        "path": [
          "colour"
        ],
        "message": "Unknown field."
      }
    ]
  }
}
```

## Request samples

### cURL

```bash
curl -X POST https://api.mynth.io/destinations \
  -H "Authorization: Bearer $MYNTH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "string",
    "config": {
      "path_template": "string"
    },
    "provider": {
      "id": "bunny",
      "storage_zone": "string"
    },
    "secret": {
      "password": "string"
    }
  }'
```

### JavaScript

```ts
const response = await fetch("https://api.mynth.io/destinations", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MYNTH_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "name": "string",
    "config": {
      "path_template": "string"
    },
    "provider": {
      "id": "bunny",
      "storage_zone": "string"
    },
    "secret": {
      "password": "string"
    }
  }),
});

const { data } = await response.json();
```

The full schema for this endpoint is in the [OpenAPI document](https://api.mynth.io/openapi.json).
