Skip to Content
AI Generation

AI Form Generation

Generate form fields using AI from a text description or by analyzing an existing webpage.

AI generation uses the same limits as your dashboard: 5/month on Free, unlimited on Pro+.

Endpoint

POST /api/v1/forms/generate

Scope required: forms:write

Description Mode

Generate a form from a natural language description.

curl -X POST "https://trigglio.com/api/v1/forms/generate" \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d '{ "description": "A customer feedback form for a SaaS product with name, email, satisfaction rating, and open-ended feedback", "maxFields": 10 }'

URL Analysis Mode

Analyze a webpage and generate a similar form.

{ "sourceUrl": "https://example.com/contact", "maxFields": 20 }

The API will fetch the page, extract form elements, and generate a matching form schema.

Response

{ "data": { "suggestedName": "Customer Feedback Form", "fields": [ { "id": "field-1708...", "type": "short_text", "label": "Full Name", "required": true, "placeholder": "Jane Doe" }, { "id": "field-1708...", "type": "email", "label": "Email Address", "required": true }, { "id": "field-1708...", "type": "rating", "label": "How satisfied are you with our product?", "required": true, "ratingConfig": { "style": "stars", "maxRating": 5, "startLabel": "Very Unsatisfied", "endLabel": "Very Satisfied" } } ], "sourceAnalysis": null } }

Generate and Create Workflow

The generation endpoint returns fields but does not save a form. To create a form from generated fields:

// Step 1: Generate fields const genRes = await fetch('/api/v1/forms/generate', { method: 'POST', headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ description: 'Employee onboarding form' }) }); const { data: generated } = await genRes.json(); // Step 2: Create the form with generated fields const createRes = await fetch('/api/v1/forms', { method: 'POST', headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ name: generated.suggestedName, schema: { fields: generated.fields, settings: { submitButtonText: 'Submit', successMessage: 'Thank you!' } }, status: 'published' }) }); const { data: form } = await createRes.json(); console.log(`Form created: ${form.id}`);

Parameters

ParameterTypeRequiredDescription
descriptionstringOne of description or sourceUrl requiredNatural language description of the form
sourceUrlstringOne of description or sourceUrl requiredURL of a webpage to analyze
maxFieldsnumberNoMaximum fields to generate (1-30, default: 25)

Tips for Better Results

  • Be specific: “Customer feedback form with name, email, 5-star rating, and comments” works better than “feedback form”
  • Mention field types: “Include a dropdown for department selection” helps the AI choose the right field type
  • Describe purpose: “Lead capture form for a real estate website” gives context for appropriate fields
  • Set maxFields: For simple forms, use maxFields: 5-8. For comprehensive ones, use 15-25.

Error Codes

CodeStatusDescription
validation_error400Missing or invalid input
generation_failed400AI could not generate valid fields
limit_exceeded403Monthly AI generation limit reached
timeout408URL fetch timed out (15s limit)
ai_rate_limited429AI service temporarily busy
ai_service_unavailable503AI service not configured
Last updated on