Skip to main content

AI Template Generation

POST https://api.getdocuforge.dev/v1/ai/generate-template Generate a complete HTML template from a natural language description using AI. The response includes ready-to-use HTML with Handlebars variables that you can save as a template or use directly with /v1/generate. Requires the ANTHROPIC_API_KEY environment variable to be configured on the server.

Request Body

ParameterTypeRequiredDescription
promptstringYesDescription of the template you want (1-2000 characters)
typestringNoTemplate type: "invoice", "receipt", "report", "certificate", "letter", "resume", or "other" (default)
stylestringNoVisual style: "professional" (default), "modern", "minimal", or "colorful"
variablesstring[]NoHandlebars variable names to include in the generated template

Example

curl -X POST https://api.getdocuforge.dev/v1/ai/generate-template \
  -H "Authorization: Bearer df_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A professional invoice for a freelance web developer with hourly billing, tax calculation, and payment terms",
    "type": "invoice",
    "style": "modern",
    "variables": ["company_name", "client_name", "items", "tax_rate", "due_date"]
  }'

Response

{
  "html": "<!DOCTYPE html><html>...<h1>Invoice for {{client_name}}</h1>...</html>",
  "variables": ["company_name", "client_name", "items", "tax_rate", "due_date", "subtotal", "total"],
  "type": "invoice",
  "style": "modern"
}
The variables array in the response includes all Handlebars variables detected in the generated HTML, which may include additional variables beyond those you requested.

Using the Generated Template

Save the generated HTML as a reusable template:
curl -X POST https://api.getdocuforge.dev/v1/templates \
  -H "Authorization: Bearer df_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Freelance Invoice",
    "html_content": "<the generated HTML>",
    "schema": {
      "company_name": "string",
      "client_name": "string",
      "items": "array",
      "tax_rate": "number",
      "due_date": "string"
    }
  }'
Or generate a PDF directly:
curl -X POST https://api.getdocuforge.dev/v1/generate \
  -H "Authorization: Bearer df_live_sk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<the generated HTML>"
  }'

Errors

StatusCodeDescription
400VALIDATION_ERRORInvalid request body or prompt too long
401UNAUTHORIZEDInvalid or missing API key
429RATE_LIMITEDToo many requests
502AI_ERRORAI provider returned an error
503AI_NOT_CONFIGUREDANTHROPIC_API_KEY is not set on the server