---
title: "Create an email template"
method: POST
path: "/email_templates"
tags: ["Email Templates"]
---

# Create an email template

`POST /email_templates`

## Request

- Base URL: `https://api.telnyx.com/v2`
- URL: `https://api.telnyx.com/v2/email_templates`
- Auth: HTTP bearer

Creates a Liquid email template. Variables are auto-extracted when omitted.

## Headers

- `Idempotency-Key` string

## Request body

- CreateEmailTemplateRequest
  - `name` string, required: Letters, numbers, spaces, hyphens, and underscores only.
  - `subject` string, nullable: Liquid template subject.
  - `html_body` string, nullable: Liquid template HTML body.
  - `text_body` string, nullable: Liquid template text body.
  - `variables` string[], nullable: Persisted variable names. In `automatic` mode a non-null array is rejected; in `explicit` mode this is the exact manual array and each item is limited to 255 Unicode code points.
  - `variables_mode` 'automatic' | 'explicit': Controls how `variables` is maintained. If both fields are omitted (or `variables` is null), the template uses `automatic` mode and extracts variable names from the effective subject, HTML body, and text body. A non-null `variables` array with no mode selects `explicit`. `automatic` rejects a simultaneous non-null array; `explicit` requires a non-null array, including valid `[]`, and preserves its exact order, duplicates, and string contents.
  - `strict_variables` boolean: Per-template strict variable-validation setting. Defaults to `false` for backward compatibility. When `true`, a send or render that is missing a variable marked `required: true` in `variable_schema` fails with 422 naming the variable. Missing optional variables never fail; their schema `default` (when set) is applied to the render.
  - `autoescape` boolean: Per-template HTML autoescaping setting. Defaults to `false` for backward compatibility. When `true`, the rendered `html_body` HTML-escapes each Liquid expression's output at the output boundary (after its filters run, before concatenation with literal template markup). Input values are never mutated and `subject`/`text_body` are never autoescaped. The boundary escape is idempotent: HTML entities already present in the output (e.g. from an explicit `escape` filter) are preserved, so an explicit `escape`/`escape_once` is never double-escaped, and markup introduced by any later filter in the chain is still escaped.
  - `variable_schema` object, nullable: Structured variable requirements. Required variables cannot define defaults; invalid combinations return 422. This is independent of the legacy `variables` array. On render with `strict_variables` enabled: `required` variables must be supplied as non-empty values — absent, `null`, empty string, empty object `{}`, and empty array `[]` all fail with 422 naming the variable, while present values such as `false` and `0` pass (they are present, not empty). Optional variables fall back to their `default` when absent.

## Response `201`

Template created.

- EmailTemplateResponse
  - `data` EmailTemplate, required
    - `record_type` 'email_template', required
    - `id` string, uuid, required
    - `name` string, required
    - `html_body` string, nullable, required
    - `text_body` string, nullable, required
    - `variables` string[], required: Persisted variable names. In `explicit` mode this array preserves the exact provided order, duplicates, and string contents; in `automatic` mode it is derived from the stored subject and bodies.
    - `variables_mode` 'automatic' | 'explicit', required: `automatic` when variable names are derived from template content; `explicit` when `variables` is the exact manually managed array.
    - `strict_variables` boolean, required: Whether strict variable validation is enabled for this template. When `true`, sends and renders that are missing a variable marked `required: true` in `variable_schema` fail with 422 naming the variable.
    - `autoescape` boolean, required: Whether HTML autoescaping is enabled for this template. When `true`, only rendered `html_body` expression output is HTML-escaped at the output boundary; `subject` and `text_body` are never autoescaped.
    - `variable_schema` object, nullable, required: Structured variable requirements, or `null` when the template uses only the legacy `variables` array.
    - `created_at` string, date-time, required
    - `updated_at` string, date-time, required
    - `subject` string, nullable, required

## Other responses

- `400`: Bad Request / Validation Failed (10015). Invalid, duplicate, empty, malformed, or overlong Idempotency-Key headers are rejected by Edge with HTTP 400 and error code 10015.
- `401`: Not authorized (10006).
- `409`: A request with the same Idempotency-Key is still being processed (10036). Retry later with the same key and request.
- `413`: Request body exceeds the 8,000,000-byte limit for this endpoint.
- `422`: Validation Failed (10015) or changeset validation error. Reusing an Idempotency-Key with a different request also returns 422 (10027).
- `503`: Service unavailable (10016), including an unavailable upstream dependency or unavailable Edge idempotency protection for a keyed request.

## Changes

- **2026-10-15** `a72569d69430`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/team-telnyx/apis/telnyx-api/changes/email_templates/post.md)

---

[API](https://skmtc.dev/team-telnyx/apis/telnyx-api.md) - [All operations](https://skmtc.dev/team-telnyx/apis/telnyx-api/llms.txt) - [OpenAPI document](https://skmtc.dev/team-telnyx/apis/telnyx-api/revisions/a73101b68823?raw)
