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
| Parameter | Type | Required | Description |
|---|---|---|---|
prompt | string | Yes | Description of the template you want (1-2000 characters) |
type | string | No | Template type: "invoice", "receipt", "report", "certificate", "letter", "resume", or "other" (default) |
style | string | No | Visual style: "professional" (default), "modern", "minimal", or "colorful" |
variables | string[] | No | Handlebars variable names to include in the generated template |
Example
Response
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:Errors
| Status | Code | Description |
|---|---|---|
| 400 | VALIDATION_ERROR | Invalid request body or prompt too long |
| 401 | UNAUTHORIZED | Invalid or missing API key |
| 429 | RATE_LIMITED | Too many requests |
| 502 | AI_ERROR | AI provider returned an error |
| 503 | AI_NOT_CONFIGURED | ANTHROPIC_API_KEY is not set on the server |

