# POST /ai/generate-form

**Resource:** [AI](./ai.md)  
**Scopes:** `ai:use`  
**Write operation:** yes

Generate a complete form template with AI, auto-wired to CRM variables. The generator maps fields whose labels unambiguously match a writable CRM variable (e.g. Email -> contact.email, ABN -> account.tax_number). Workspace custom fields are included in the wiring vocabulary. By default (persist=true), creates the form_templates row and all form_template_fields rows and returns the new template_id. Costs credits (ai_tool_generate).

## Parameters

| Name | In | Type | Required | Description |
|------|----|------|----------|-------------|
| `prompt` | body | string | yes | Plain-language description of the form to generate. Be specific about fields needed. |
| `persist` | body | boolean | no | If true (default), creates the form template and fields in the workspace. If false, returns only the generated structure without persisting. |
| `name` | body | string | no | Override the AI-generated form name. |
| `folder` | body | string | no | Folder to place the template in. |

## Response example

```json
{
  "data": {
    "template": {
      "id": "uuid",
      "name": "Client Intake Form",
      "description": "...",
      "slug": "client-intake-form",
      "created_at": "2026-04-19T..."
    },
    "fields": [
      {
        "id": "uuid",
        "type": "text",
        "label": "First Name",
        "content": {
          "crm_variable": "contact.first_name",
          "crm_variable_mode": "overwrite"
        }
      }
    ],
    "persisted": true,
    "stats": {
      "total_fields": 6,
      "wired_fields": 5,
      "unwired_fields": 1
    }
  },
  "meta": {
    "credits_remaining": 9250
  }
}
```

---
Base URL: `https://api.trustpager.com/functions/v1/api/v1` — Auth: `Authorization: Bearer YOUR_API_KEY`