Generate an Action
POST /ai/action takes a natural language prompt and returns a complete action draft. The draft is ready to post to POST /action to create the live row.
Request
{
"prompt": "When a booking is created on a meeting room, send a confirmation email to the booker with the room name, start time and end time."
}prompt is required. input is optional: pass a pre-defined input schema when an upstream form already knows the input shape and you want the generated script to bind to those exact keys.
Response
{
"data": {
"request_id": "5fb1c0ad-8a02-4e2a-9aa5-2d51c4f8bba4",
"action": {
"name": "Send booking confirmation email",
"description": "Sends an email to the user who created the booking with room and time details.",
"summary": "Loads the booking, formats the start and end time, and emails the booker.",
"trigger": "booking_created",
"code": "/* generated tengo */",
"input": {
"email_from": { "type": "string", "description": "Sender address" }
},
"public": false,
"continue_on_fail": false,
"dedup_mode": "per_attachment"
}
},
"request_id": "fa1de5d0-e9f0-46fb-9aa1-32b6b8b9a2a4",
"count": 1
}data.request_id points at the ai_request row that holds the prompt, model, and audit trail for the generation. The outer request_id is the standard response envelope id.
Saving the Draft
Send the action block directly to POST /action. The draft is discarded if not saved. The ai_request row stays for the audit trail regardless.
Following Progress
Generation runs inline, so the response body arrives only when the model finishes. To observe progress while a run is in flight, open a second connection to GET /ai/request/{id} or GET /ai/request/{id}/response with Accept: text/event-stream. The server streams status, progress, and messages until the run settles.
Refining the Code
If the structure of the draft is right but the script needs changes, hand the code and summary back through Generate Action Code along with a new instruction.