# Render a template without sending it

Returns the subject and bodies a send would produce, and a report on every variable: what the declaration says, which body uses it, and whether a sample filled it. With `preview`, any variable the caller omits is filled from its declared sample. With `draft`, it renders that copy instead of the stored one, under the checks a save makes, and stores nothing: saving a variant publishes it, so this is how copy is seen before it is live.

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

### Path parameters

- `accountId` (string, required) — Account ULID identifier.
- `slug` (string, required, 1–64 chars, pattern `^[a-z0-9][a-z0-9_-]*$`) — The template's name within this account.

### Request body (optional)

`application/json`

- `draft` (object | null) — Copy not stored yet, rendered in the language asked for (else the template's default) with no fallback, since it IS that language's copy. Held to the checks a save makes, so a broken draft gets the refusal saving it would; nothing is written.
  - `subject` (string, required, 1–500 chars)
  - `text` (string, required, min 1 chars)
  - `html` (string | null)
- `lang` (string | null, 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.
- `preview` (boolean)
- `recipient` (object | null)
  - `email` (string <email>, required)
  - `name` (string | null, max 200 chars)
- `vars` (object)

### Responses

**200** — The rendered message

`application/json` → MailTemplateRender

- `html` (string | null, required)
- `langUsed` (string, required)
- `slug` (string, required)
- `source` ("stored" | "draft", required) — `draft` when the call carried copy to preview, `stored` when it rendered the template's own copy
- `subject` (string, required)
- `templateVersion` (integer, required)
- `text` (string, required)
- `variables` (MailTemplateVariable[], required)
  - `bodies` ("subject" | "text" | "html"[], required) — Which fields reference it
  - `description` (string | null, required)
  - `filledFromSample` (boolean, required) — True when the preview's sample stood in for a value not passed
  - `name` (string, required)
  - `sample` (string | number | boolean | null, required)
    - _option 1: string_
    - _option 2: number_
    - _option 3: boolean_
    - _option 4: null_

**400** — missing_variable, rendered_too_large, rendered_subject_too_long, template_invalid, no_variant_for_language, a draft's own refusal (text_required, subject_too_long, body_too_large, as a save answers it), or validation_failed for an unknown key

`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

**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/{slug}/render' \
  -H 'Authorization: Bearer oek_…' \
  -H 'Content-Type: application/json' \
  -d '{}'
```

## TypeScript SDK

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

```ts
const mailTemplateRender = await openemail.templates.render(accountId, slug, {})
```
