Loops

Files a new Loop under the Reason, which must be one of the caller's own live Reasons (404 reason_not_found otherwise). Give what wakes it in wake_on. A Loop woken by events opens a Session per event; webhook events sharing an X-Webhook-Correlation-Key continue one Session.

A Loop with a webhook returns webhook.url and webhook.key in this response only; store the key now, it is never readable again. The workspace's plan and credits must be able to run the Loop's model (402 loop_model_not_fundable).

<sub>Scope: automations:write</sub>

post/v3/organizations/{orgId}/reasons/{reasonId}/loops

Request

  • Base URL
    https://api.reasonmachines.com
  • URL
    https://api.reasonmachines.com/v3/organizations/{orgId}/reasons/{reasonId}/loops
  • Auth
    HTTP bearer

Request body

promptstring required

The instructions the Reason follows on each wake. An event's body reaches it as untrusted data, never as instructions.

namestring

Label in the Reason's Loops list. Defaults to the start of prompt.

enabledboolean

Send false to create it paused.

untilstring date-time nullable

End of a scheduled Loop: no wake after this time, then it reads completed. null clears it. A Loop woken by events has no end of its own.

max_runsinteger nullable

How many runs a scheduled Loop makes before it reads completed, counted from when it is set. null clears it.

execution_mode'session' | 'new_session'

session continues one Session across wakes, the one in session_id or else one of the Loop's own that its first wake opens; new_session opens a fresh Session on every wake. A Loop woken by events opens a Session per event (events sharing a correlation key continue one), so it takes neither.

session_idstring uuid nullable

An existing Session of the caller's that each wake continues. null unbinds it.

device_idstring uuid nullable

A connected computer of the caller's (listDevices) that its runs use; null runs them on a Reason cloud machine.

notification_policy'important_updates' | 'failed_runs_only'

When the Loop tells the person about a run: on important updates (the default) or only when a run fails.

timezonestring

IANA time zone a cron schedule is read in, such as America/Los_Angeles. Defaults to UTC, or keeps the Loop's own on update.

modelstring nullable

Model its runs use, as a Session model id. null or auto runs it on the model of the Session it continues, or the workspace's. An id the workspace cannot pin returns 400 invalid_model.

Example request

{
  "wake_on": [
    {
      "schedule": "0 9 * * 1-5"
    },
    {
      "webhook": {}
    }
  ]
}

Response

The new Loop, and its webhook's URL and key when it has one.

Changes