# Create a mail template

Registers a template. The From address must be one this account may already send as; the copy is added per language afterwards.

## `POST /api/v1/accounts/{accountId}/templates`

### Path parameters

- `accountId` (string, required) — Account ULID identifier.

### Request body (required)

`application/json`

- `from` (string <email>, required, max 320 chars)
- `name` (string, required, 1–200 chars)
- `slug` (string, required, 1–64 chars, pattern `^[a-z0-9][a-z0-9_-]*$`) — The template's name within this account.
- `defaultLang` (string, 2–35 chars, pattern `^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$`) — Language tag, e.g. `en` or `de-AT`. Stored lowercased.
- `replyTo` (string | null, max 320 chars)
- `variables` (object) — Documentation and dummy data per variable. Never a schema: a body may use what this omits.

### Responses

**200** — Created

`application/json` → MailTemplate

- `createdAt` (integer, required)
- `defaultLang` (string, required)
- `from` (string | null, required) — The From address; always set on a template this API created
- `languages` (string[], required) — The languages this template has copy for
- `name` (string, required)
- `replyTo` (string | null, required)
- `slug` (string, required)
- `updatedAt` (integer, required)
- `variables` (object, required)
- `version` (integer, required) — Bumped by every write that changes what a send would produce

**400** — reserved_slug, from_not_sendable or an invalid variable declaration

`application/json` → ErrorOrValidation

**401** — unauthorized: the bearer credential is missing, malformed, expired, or revoked. Carries a `WWW-Authenticate: Bearer` challenge

`application/json` → ErrorBody

**404** — not_found

`application/json` → ErrorBody

**409** — slug_taken, or template_limit_reached carrying the effective ceiling

`application/json` → ErrorBody

**411** — length_required: Content-Length is required

`application/json` → ErrorBody

**413** — too_large: the JSON body exceeds 2 MiB

`application/json` → ErrorBody

**503** — temporary_failure: the platform's storage could not answer just now; retry after the Retry-After window. Any operation can answer this. A write that got it may have been applied, so retry it with the same idempotency key where it takes one, or read the state back first (see Transient failures in the API description)

`application/json` → ErrorBody

### Example request

```bash
curl -X POST 'https://api.open.email/api/v1/accounts/{accountId}/templates' \
  -H 'Authorization: Bearer oek_…' \
  -H 'Content-Type: application/json' \
  -d '{
    "from": "user@example.com",
    "name": "string",
    "slug": "string"
  }'
```

## TypeScript SDK

[`openemail.templates.create`](/docs/sdks/typescript/templates/create)

```ts
const mailTemplate = await openemail.templates.create(accountId, { slug: '…', name: 'Ada', from: 'ada@example.com' })
```
