Skip to main content

AI template generation

Easy Email Pro includes a standalone API for creating a complete email template from source material. It is separate from the in-editor AI Agent: the API returns a full Easy Email Pro template, while the Agent applies targeted edits to the current template.

The recommended workflow is:

  1. Crawl a public brand website with /v1/easy-email/crawl-brand.
  2. Let the user review or edit the returned source text.
  3. Send the source and a campaign prompt to /v1/easy-email/generate-template.
  4. Load the returned { subject, content } object into the editor.

Crawl a website​

const response = await fetch(
"https://agent-api.beacas.com/v1/easy-email/crawl-brand",
{
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ url: "https://example.com/" }),
},
);

if (!response.ok) throw new Error(await response.text());

const { source } = await response.json();

The crawler collects brand metadata, copy, public links, theme colors, and exact image URL/alt pairs. It follows a small number of relevant public pages; it does not crawl private pages or analyze the contents of images.

Treat the returned source as editable reference material. The source is plain text/Markdown and does not need to have a fixed schema.

Generate a complete template​

const response = await fetch(
"https://agent-api.beacas.com/v1/easy-email/generate-template",
{
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
prompt: [
"Create a complete product-promotion email.",
"Use a compact hero, a two-column feature grid, one CTA, and a concise footer.",
"Keep every feature card to one short sentence.",
].join(" "),
source,
}),
},
);

if (!response.ok) {
const error = await response.json();
throw new Error(error.message || "Template generation failed");
}

const template = await response.json();
// template.subject
// template.content — Easy Email Pro page data

The generation endpoint accepts:

FieldTypeDescription
promptstringCampaign goal and layout direction.
sourcestringBrand/source material, usually the crawler's Markdown output.

The response is a complete template, not an Agent event stream. It can be passed to the editor as the initial template or applied as a full-template replacement.

Error handling​

StatusMeaning
400Request JSON or required fields are invalid.
413The website or source is too large to process.
415The crawl target did not return HTML.
422The model returned a template that still failed validation after retries.
502The crawl target or AI provider could not be reached.

See the AI Agent guide for streaming in-editor edits and tool calls.