Templates
AI templates
Describe the document you need. DevilPDF designs a template for it, with sample data, and saves it to your account. From then on it is an ordinary template: render it with JSON as often as you like, and edit it by hand if you want to.
Generation happens once, when you create the template. Rendering never involves AI, so your documents are fast and identical every time.
#Generate a template
curl https://devilpdf.com/v1/templates/generate \
-H "Authorization: Bearer $DEVILPDF_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A packing slip for a coffee roaster. Logo top left, order number and date top right, ship-to address, then a table of items with SKU, name and quantity. A thank-you note at the bottom. Letter size, warm brown accent."
}'const res = await fetch("https://devilpdf.com/v1/templates/generate", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.DEVILPDF_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
prompt:
"A packing slip for a coffee roaster. Logo top left, order number and date top right, " +
"ship-to address, then a table of items with SKU, name and quantity. " +
"A thank-you note at the bottom. Letter size, warm brown accent.",
}),
});
const template = await res.json();
console.log(template.id, template.sample_data);import os, requests
template = requests.post(
"https://devilpdf.com/v1/templates/generate",
headers={"Authorization": f"Bearer {os.environ['DEVILPDF_API_KEY']}"},
json={
"prompt": "A packing slip for a coffee roaster. Logo top left, order number and date top right, "
"ship-to address, then a table of items with SKU, name and quantity. "
"A thank-you note at the bottom. Letter size, warm brown accent."
},
timeout=180,
).json()
print(template["id"], template["sample_data"])You get a saved template object back with status 201. Its sample_data shows the JSON shape to send when you render.
{
"object": "template",
"id": "tpl_8sK2mQx7Lp0aVn3RtYc1",
"name": "Packing slip",
"description": "Packing slip with ship-to address and a table of items.",
"kind": "html",
"settings": { "page_size": "Letter", "orientation": "portrait", "margin": "15mm 16mm 17mm", "font": "inter", "heading_font": "inter", "accent": "#7c4a1e", "page_numbers": true, "footer_text": "" },
"source": "ai",
"html": "<header class=\"doc-head\">...</header>",
"css": "",
"sample_data": {
"order": { "number": "SO-1182", "date": "2026-03-14" },
"company": { "name": "Ember & Oak Coffee", "logo_url": "" },
"ship_to": { "name": "Dana Whitfield", "address": "2200 Mission Street\nSan Francisco, CA 94110" },
"items": [{ "sku": "ETH-250", "name": "Ethiopia Guji, 250 g", "quantity": 2 }]
}
}Then render it like any template:
curl https://devilpdf.com/v1/render \
-H "Authorization: Bearer $DEVILPDF_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "template": "tpl_8sK2mQx7Lp0aVn3RtYc1", "data": { "order": { "number": "SO-1183" }, "items": [] } }'#Parameters
| Field | Type | Description |
|---|---|---|
prompt | string | Required. What the document is and what it contains. 3 to 4,000 characters. |
name | string | Name for the saved template. If you leave it out, one is chosen for you. |
save | boolean | Default true. Set false to get a draft back without saving it. |
#Drafts
With "save": false the response is a template_draft: the same name, description, html, css, settings and sample_data, with no id. Nothing is stored. Preview it by rendering the html and css directly, then save the one you like with POST /v1/templates.
{
"html": "<the draft html>",
"css": "<the draft css>",
"data": { "order": { "number": "SO-1182" } },
"options": { "kit": true, "page_size": "Letter", "accent": "#7c4a1e" }
}A draft still uses one AI generation.
#Revise a template
Change an existing template by saying what you want changed.
curl https://devilpdf.com/v1/templates/tpl_8sK2mQx7Lp0aVn3RtYc1/revise \
-H "Authorization: Bearer $DEVILPDF_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "prompt": "Add a column for unit weight, and a total weight under the table." }'The template is updated in place and returned. Existing field names are kept unless the change needs otherwise, so your integration keeps working. Its version goes up by one.
| Field | Type | Description |
|---|---|---|
prompt | string | Required. The change to make. |
save | boolean | Default true. Set false to get the revised version back as a template_draft and leave the saved template alone. |
html, css, settings, sample_data | Optional. Revise this working copy instead of the saved version. Useful when your own editor holds unsaved changes. |
Revising a starter (invoice, quote, certificate) always returns a draft, because starters are read-only. Only HTML templates can be revised.
#Writing good prompts
The more specific the description, the closer the first result.
- Name the document and who sends it. "A monthly statement for a property management company."
- List the content, top to bottom. Header, parties, the table and its columns, totals, footer.
- Say what repeats. "A table of line items with description, hours and rate."
- Say what is optional. "A PO number, when there is one."
- Give the look. Page size, serif or sans, accent colour, formal or friendly.
- Mention the maths. "Subtotal, 13% HST, total." Generated templates calculate totals from the line items.
Then use revise for small corrections. "Move the logo to the right", "make it A4", "add a notes section" each work better as a follow-up than as a rewrite.
#Usage
Each generate or revise call uses one AI generation from your monthly allowance.
| Plan | AI generations per month |
|---|---|
| Free | 10 |
| Starter | 50 |
| Growth | 200 |
| Business | 500 |
| Scale | 1,000 |
A call that fails is not counted. Rendering a generated template uses documents, not generations.
Generation takes much longer than a render. Give your HTTP client a timeout of at least two minutes.
#Errors
| Type | Status | Meaning |
|---|---|---|
ai_refused | 422 | The description could not be turned into a document template. Describe a business document. |
ai_unavailable | 503 | The generator is busy, or the result did not pass validation. Try again. Not counted. |
quota_exceeded | 429 | You have used this month's AI generations. |
plan_limit | 403 | Saving would exceed your plan's template limit. Use "save": false or delete a template. |