---
title: "Ai Generate Template"
method: POST
path: "/api/declaration-templates/ai-generate"
tags: ["Declaration Templates (Admin)"]
---

# Ai Generate Template

`POST /api/declaration-templates/ai-generate`

Generate declaration template HTML using AI (Claude).

The AI generates HTML body content using the V5 CSS design system and we
return it as an editable DRAFT (design_json + html_content) — it is NOT
saved. The frontend opens it in the editor; the user picks the mandatory
Tipo de Documento and saves via the normal POST /declaration-templates
(which enforces a valid tipo_doc). This mirrors the import-document flow
and guarantees no NULL-tipo_doc template is ever persisted.

Body:
    example_text: str (required, min 10 chars) — description of what the user wants
    placeholders: list[str] (required, min 1) — placeholder keys to include
    id_modulo: int (required) — 5, 11, or 12
    name: str (optional) — template name (defaults to "Declaração IA")
    trigger_action: str (optional) — trigger for auto-generation
    tipo_doc: int (optional) — document type ID, pre-fills the draft's metadata

## Headers

- `x-api-token` string, nullable

## Request body

- object

## Response `200`

Successful Response

- unknown

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.dev/multigest/apis/multigest-protected-api.md) · [All operations](https://skmtc.dev/multigest/apis/multigest-protected-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/multigest/multigest-protected-api/revisions/4b44eb76b3ee/schema)
