API referenceTemplates

Create a template and publish version 1

Creates a template container and atomically publishes version 1 from the same request, so the template is immediately sendable.

Endpoint
POST https://api.dairo.app/v1/templates

Creates a template container and atomically publishes version 1 from the same request, so the template is immediately sendable. slug (1–64 chars, lowercase letters, digits, and hyphens, no leading or trailing hyphen), name (≤120 chars), and source (a React email component, ≤64 KiB) are required; subject (≤2000 chars, with {{variable}} placeholders), variables, and notes (≤500 chars) are optional. variables is a JSON-Schema-lite contract (≤8 KiB) accepting either the field-local shape { "amount": { "type": "number", "required": true } } or a standard JSON Schema with properties and a top-level required array, over the types string, number, integer, boolean, object, array, null, url, and email. Before the version is stored Dairo dry-renders the source against sample values derived from the schema and returns 400 with a renderer error code (such as NO_COMPONENT_EXPORT, FORBIDDEN_IMPORT, or RENDER_FAILED) if it cannot render, while dangerouslySetInnerHTML in the source adds a non-blocking USES_DANGEROUS_HTML entry to the response warnings array. A slug already in use within the project returns 409 before any rate-limit token or render is spent; creation is capped at 50 per hour with a shared 60-per-minute mutation limit and requires the templates:write scope. Responds 201 with the object: "template" and its published version nested under version.

Scope: templates:write. Send the API key as a bearer token; Scopes lists what each one reaches.

Request

cURL
curl -X POST "https://api.dairo.app/v1/templates" \
  -H "Authorization: Bearer $DAIRO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "slug": "welcome",
    "name": "Ada Lovelace",
    "source": "string"
  }'

Headers

NameTypeRequiredDescription
Idempotency-KeystringnoOptional idempotency key for safe retries of side-effecting operations. (max length 128)

Body

Required, application/json: TemplateCreateRequest.

FieldTypeRequiredDescription
slugstringyes
namestringyes(min length 1)
descriptionstringno
sourcestringyesReact Email TSX source for version 1.
subjectstringno
variablesTemplateVariableSchemano
notesstringno

Response

201 Created. Body: application/json, TemplateVersionResponse.

FieldTypeRequiredDescription
templateTemplateyes
versionTemplateVersionyes
warningsarray of stringyes
201
{
  "template": {
    "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "slug": "welcome",
    "name": "Ada Lovelace",
    "description": null,
    "currentVersion": null,
    "status": "string",
    "createdAt": "2026-10-19T09:30:00Z",
    "updatedAt": "2026-10-19T09:30:00Z"
  },
  "version": {
    "version": 0,
    "subject": "Hello from Acme",
    "variables": {},
    "notes": null,
    "createdAt": "2026-10-19T09:30:00Z"
  },
  "warnings": [
    "string"
  ]
}

Errors

Every error has the same body, {"error": {"type", "code", "message", "param"}}; branch on code. Errors lists every code.

StatusMeaning
400The request is malformed or a value is invalid (invalid_request, invalid_domain, idempotency_key_mismatch).
401The API key is missing or invalid.
403The key lacks the scope this endpoint needs (scope_missing) or may not do this (not_permitted).
404No such resource in this account (resource_not_found).
422The request is well-formed but a field failed validation (validation_failed).
429Rate limit, plan limit, budget or spend cap reached (rate_limited, plan_limit_reached, budget_exceeded, spend_cap_reached).
500An unexpected error; retry with backoff, then contact support (internal_error).

On this page