Generate a Form with AI
Create a new form by providing a natural language prompt. The AI will generate appropriate form fields, labels, and validation rules based on your description.Endpoint
Authentication
Requires Clerk authentication. The form will be associated with the authenticated user’s account.Request Body
A natural language description of the form you want to create. Cannot be empty.Examples:
- “Create a contact form with name, email, and message”
- “Generate an event registration form with attendee details”
- “Make a job application form with personal info and resume upload”
Response
Indicates whether the form was generated successfully
Unique identifier for the generated form (UUID format)
URL-friendly slug for accessing the form publicly
The generated title of the form
Confirmation message: “Form generated successfully”
Example Request
Example Response
Error Responses
Implementation Details
The endpoint performs the following steps:- Validates the user’s Clerk authentication session
- Validates the prompt is not empty
- Calls the AI service to generate a form schema from the prompt
- Validates the generated schema structure
- Creates a new form record in the database with
isPublished: false - Returns the form ID, slug, and title
app/api/forms/generate/route.ts:6
Next Steps
After generating a form:- Use the
formIdto fetch full form details via GET /api/forms/[id] - Use the
slugto share a public URL:https://your-domain.com/forms/{slug} - Update the form’s publish status via PATCH /api/forms/[id]