# Processes

A Process is a stored sequence of steps. Its steps call APIs, generate structured data with an LLM, send SMS and email, branch on conditions, and loop over lists. A [Trigger](/docs/triggers) or an [API call](/docs/runs#start-a-process) starts it, and each start creates a [Run](/docs/runs).

## Create a Process

Create a Process through the Data API at `/automation/processes`. This Process posts the title and duration of a completed conversation to your endpoint:

```bash title="Create a Process"
curl https://data.reecall.io/automation/processes \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer sk_YOUR_API_KEY' \
  --data '{
    "name": "Post call summary",
    "description": "Send the title and duration of each completed call to the CRM",
    "steps": [
      {
        "type": "request",
        "output": "crm",
        "config": {
          "url": "https://crm.example.com/calls",
          "method": "POST",
          "headers": { "Authorization": "Bearer {{ variables.CRM_TOKEN }}" },
          "data": {
            "exchangeId": "{{ event.refId }}",
            "title": "{{ event.data.title }}",
            "duration": "{{ event.data.duration }}"
          }
        }
      }
    ]
  }'
```

The response is the stored Process with its `id`. Link it to a System event with a [Trigger](/docs/triggers#create-a-trigger), or start it with [`POST /v2/execute/{id}`](/docs/runs#start-a-process).

## Fields

| Field | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `string` | No | | Name shown in lists |
| `description` | `string` | No | | What the Process does |
| `steps` | `array` | Yes | | The steps to run, in order. See [Steps](#steps). |
| `defaultContext` | `object` or `null` | No | `null` | Values the Process reads under `input` when its caller leaves them out. Anyone who can read the Process can read them, so keep secrets in [Variables](/docs/variables). |
| `projectId` | `string` (UUID) or `null` | Depends on the key | | The Project of the Process, or `null` for an organization-level Process |
| `organizationId` | `string` (UUID) | Set from the key | | Cannot change after creation |

A project-scoped API key creates Processes in its Project. An organization-scoped key creates a project Process when you set `projectId`, and an organization-level Process when you leave it out. An organization-level Process can be started by the Triggers of every Project in the Organization.

## Steps

Each step has a `type` that selects its action and a `config` object for its settings. Steps run in order, and a failed step fails the Run.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `type` | `string` | Yes | The step type, from the table below |
| `config` | `object` | Yes | Settings of the step type. Most fields accept [templates](/docs/templating-language). |
| `output` | `string` | No | Name under which later steps read the step's result. See [Context](/docs/context-manipulation). |
| `timeout` | `number` | No | Step timeout in milliseconds. Defaults to `30000`, at most `300000` (5 minutes). |

| Step | Use it to |
| --- | --- |
| [Request](/docs/request) | Call an HTTP API |
| [Agent](/docs/agent) | Generate structured data with an LLM |
| [SMS](/docs/sms) and [Email](/docs/email) | Send messages through the configured providers |
| [Rule](/docs/rules) | Run the first branch whose conditions match |
| [Batch](/docs/batch) | Run independent steps in parallel |
| [Map](/docs/map) | Run a sequence for each item in an array |
| [Respond](/docs/respond) | End the Run and store a status, body, and headers as its result |

## What a Process reads

Templates and conditions read the Run's context. It starts with four values, and each step with an `output` adds its result:

| Name | Holds |
| --- | --- |
| `event` | The System event that started the Run: `id`, `type`, `occurredAt`, `refId`, and `data`. Absent when an API call started the Run. See [System events](/docs/system-events). |
| `input` | The Process's `defaultContext`, overridden by the Trigger's `input` or by the `context` of the API call |
| `variables` | The [Variables](#variables) of the Run's Organization and Project |
| `run` | The Run: `id`, `attempt` (starting at 1), `triggerId`, and `processId` |

For example, with `defaultContext` set to `{ "lang": "fr", "limit": 10 }` and a Trigger `input` of `{ "lang": "en" }`, the Process reads `input.lang` as `"en"` and `input.limit` as `10`.

`event`, `input`, `variables`, and `run` are reserved: a step whose `output` uses one of these names fails with `STEP_INVALID`. See [Context](/docs/context-manipulation) for how step results add to the context.

## Variables

A Run reads the [Variables](/docs/variables) of its Organization and of its Project under `variables`. When both define the same key, the Project's value wins.

```json title="A request step reading a secret Variable"
{
  "type": "request",
  "config": {
    "url": "https://crm.example.com/calls",
    "method": "POST",
    "headers": { "Authorization": "Bearer {{ variables.CRM_TOKEN }}" },
    "data": { "exchangeId": "{{ event.refId }}" }
  }
}
```

- Each attempt reads the current values, so a retry uses a Variable you changed after the first attempt.
- SMS and email steps do not receive secret Variables. Use them in request and agent steps.
- Rule conditions read Variables with a `source` such as `variables.REGION`.

## Change or delete a Process

Each attempt of a Run reads the Process's current steps. A change applies to Runs still in the queue and to retries. Deleting a Process fails its queued Runs with `PROCESS_DELETED`.
