# Runs

import { CodePreview } from "../../src/CodePreview";

A Run is one time a [Process](/docs/processes) runs. A [Trigger](/docs/triggers) creates one for each System event that matches it, and you can start one through the API. Every Run is asynchronous: starting it returns a Run ID, and you read the Run to follow its status and result.

The Runs API is at `https://workflows.reecall.io/v2`. Send your [API key](/docs/authentication) in the `Authorization` header. The [API reference](/api) lists every field under Automation > Run.

## Start a Process

Send `POST /v2/execute/{processId}`. `context` becomes the Run's `input`, over the Process's `defaultContext`:

```bash title="Start a Process"
curl https://workflows.reecall.io/v2/execute/<your-process-id> \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer sk_YOUR_API_KEY' \
  --data '{
    "context": { "customerId": "123", "lang": "en" },
    "retry": { "delays": ["5m", "1h"] }
  }'
```

```json title="202 Accepted"
{ "runId": "5d1f0c8e-2b7a-4e3d-9c6f-8a1b2c3d4e5f" }
```

The `Location` header points to the Run, `/v2/runs/{runId}`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `context` | `object` | No | Values the Process reads under `input` |
| `retry` | `string` or `object` | No | [Retry policy](/docs/triggers#retry-policy) of this Run. `"none"` by default. |

A project-scoped key starts the Processes of its Project and the organization-level Processes. An organization-scoped key starts every Process of its Organization. A Process out of reach of the key answers `404 NOT_FOUND`.

### Run steps without storing a Process

`POST /v2/execute` runs the steps sent in the request, which helps when you test steps before storing them. The Run has `kind: "inline"` and no `processId`:

```bash title="Run steps sent with the request"
curl https://workflows.reecall.io/v2/execute \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer sk_YOUR_API_KEY' \
  --data '{
    "steps": [
      {
        "type": "request",
        "config": {
          "url": "https://api.example.com/users/{{ input.userId }}",
          "method": "GET"
        }
      }
    ],
    "context": { "userId": "123" }
  }'
```

`steps` needs at least one step. Without it, the API answers `400 INVALID_REQUEST`.

## Read a Run

```bash title="Read a Run"
curl https://workflows.reecall.io/v2/runs/<run-id> \
  --header 'Authorization: Bearer sk_YOUR_API_KEY'
```

<CodePreview>

```json title="A Run started by a Trigger"
{
  "id": "5d1f0c8e-2b7a-4e3d-9c6f-8a1b2c3d4e5f",
  "status": "succeeded",
  "kind": "process",
  "origin": "event",
  "processId": "3c4d5e6f-7a8b-4c9d-8e1f-2a3b4c5d6e7f",
  "triggerId": "9e8d7c6b-5a4f-4e3d-8c2b-1a0f9e8d7c6b",
  "eventId": "0b2e6f4a-8c1d-5e7f-9a3b-4c5d6e7f8a9b",
  "eventType": "exchange.completed",
  "refId": "72770d5a-5b25-4118-ba88-786972b29de7",
  "attempts": 1,
  "errorCode": null,
  "errorMessage": null,
  "failedStep": null,
  "usage": { "llmTokens": 1830 },
  "nextAttemptAt": null,
  "startedAt": "2026-12-01T10:15:42.410Z",
  "endedAt": "2026-12-01T10:15:47.902Z",
  "createdAt": "2026-12-01T10:15:42.230Z",
  "organizationId": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
  "projectId": "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e",
  "result": null,
  "stepRecords": [
    {
      "runAttempt": 1,
      "position": "0",
      "stepType": "agent",
      "status": "succeeded",
      "attempts": 1,
      "errorCode": null,
      "errorMessage": null,
      "params": { "provider": "openai", "model": "gpt-6-luna", "inputTokens": 1520, "outputTokens": 310 },
      "startedAt": "2026-12-01T10:15:42.415Z",
      "endedAt": "2026-12-01T10:15:47.511Z"
    },
    {
      "runAttempt": 1,
      "position": "1",
      "stepType": "request",
      "status": "succeeded",
      "attempts": 1,
      "errorCode": null,
      "errorMessage": null,
      "params": { "method": "POST", "host": "crm.example.com", "status": 200 },
      "startedAt": "2026-12-01T10:15:47.512Z",
      "endedAt": "2026-12-01T10:15:47.901Z"
    }
  ]
}
```

</CodePreview>

| Field | Description |
| --- | --- |
| `status` | See [Statuses](#statuses) |
| `kind` | `process` for a stored Process, `inline` for steps sent with the request |
| `origin` | `event` when a Trigger started the Run, `api` when an API call did |
| `processId`, `triggerId` | The Process and the Trigger of the Run. `triggerId` is `null` for an API call. |
| `eventId`, `eventType`, `refId` | The [System event](/docs/system-events) that started the Run, and the ID of the record it points to |
| `attempts` | Attempts so far, retries included |
| `errorCode`, `errorMessage`, `failedStep` | Why the Run failed, as a code and a sentence, and the position of the failed step. See [Why a Run failed](#why-a-run-failed). |
| `usage` | Resources the Run used: `llmTokens`, `sms`, and `email` counts |
| `nextAttemptAt` | When a `waiting` Run tries again |
| `result` | The status, body, and headers set by a [Respond step](/docs/respond), or `null` |
| `stepRecords` | One record per step and attempt. See [Step records](#step-records). |

A Run never returns its input, its System event's data, or its steps. To send data out of a Run, use a [Request step](/docs/request) or a Respond step.

### Statuses

| Status | Meaning |
| --- | --- |
| `queued` | Waiting for its turn |
| `running` | An attempt is in progress |
| `waiting` | The attempt failed and a retry is scheduled at `nextAttemptAt` |
| `succeeded` | The last attempt finished, or a Respond step ended it |
| `failed` | The last attempt failed and no retry is left |
| `cancelled` | Cancelled through the API |

### Step records

A step record shows how one step ran, without its input or output:

| Field | Description |
| --- | --- |
| `runAttempt` | The attempt of the Run |
| `position` | Where the step sits in the Process: `"2"` is the third top-level step, `"3.rules.0.then.1"` is the second step in the first branch of the Rule at position 3 |
| `stepType` | The step type |
| `status` | `running`, `succeeded`, or `failed` |
| `attempts` | Tries of the step within the attempt |
| `errorCode`, `errorMessage` | Why the step failed. A step that contains the failed step, such as a Batch or a Rule, shows the same code and message. |
| `params` | Safe details. Request: `method`, `host`, `status`. Agent: `provider`, `model`, `inputTokens`, `outputTokens`. SMS and email: `provider`, `providerErrorCode`. |

### Why a Run failed

A failed Run says why in two fields:

- `errorCode` names the cause, for your code to test.
- `errorMessage` describes it in one sentence of at most 1,000 characters, for a person to read.

`failedStep` is the position of the step that failed, the same as in [Step records](#step-records). It is `null` when the Run failed outside a step, as when the attempt timed out.

The message never holds the Run's data: no value from the System event or the input, no response body, no text written by a model or a provider. A request step that got an answer reports its status code and the standard phrase for it, such as `Request failed with status code 422 (Unprocessable Entity)`. An SMS or email failure quotes the provider's error code, such as `21211`, never its answer.

A Run waiting for a retry shows the failure of its last attempt. A later attempt that succeeds sets both fields back to `null`.

| `errorCode` | Cause | `errorMessage` example |
| --- | --- | --- |
| `REQUEST_ERROR` | A request step got an error answer or no answer | `Request failed with status code 503 (Service Unavailable)` |
| `REQUEST_BLOCKED` | A request step targeted a private or internal address | `Request blocked: internal address` |
| `TEMPLATE_ERROR` | A [template](/docs/templating-language) could not be rendered | `Template error: number could not convert a string to a number.` |
| `STEP_TIMEOUT` | A step ran past its timeout | `Step timeout` |
| `STEP_INVALID` | A step's `output` uses a reserved name | `Output name 'event' is reserved` |
| `UNKNOWN_STEP_TYPE` | A step's `type` does not exist | `Handler not found: notify` |
| `AGENT_ERROR` | An Agent step got no usable answer from its model | `The model's answer does not match the output schema (openai gpt-6-luna)` |
| `AGENT_RATE_LIMIT` | The model provider limited the rate | `Rate limit exceeded for openai` |
| `AGENT_AUTH_ERROR` | The model provider refused the API key | `Invalid API key for openai` |
| `AGENT_VALIDATION_ERROR` | An Agent step's configuration is invalid | `outputSchema required for consensus mode` |
| `AGENT_CONSENSUS_ERROR` | The models of a consensus Agent step did not agree | `Consensus failed: agreement 0.55 < 0.66` |
| `SMS_ERROR` | The SMS was not sent | `The SMS provider twilio rejected the message (21211)` |
| `EMAIL_ERROR` | The email was not sent | `Mailjet rejected the email (send-0003)` |
| `CANCELLED` | The Run was cancelled during a step | `Run cancelled` |
| `STEP_ERROR` | A step failed in an unexpected way | `Unexpected error in a map step` |
| `PROCESS_DELETED` | The Process was deleted before the attempt | `The Process was deleted before this attempt started.` |
| `RUN_ATTEMPT_TIMEOUT` | The attempt ran longer than 15 minutes | `The attempt ran past the time limit of a Run.` |
| `RUN_ATTEMPT_LOST` | The last attempt was interrupted on Reecall's side | `The attempt stopped without finishing, and no attempt was left.` |
| `RUN_ERROR` | Any other failure | `Unexpected error while running the Run.` |

The step pages list the messages of each step type, such as [Request](/docs/request#error-handling) and [Agent](/docs/agent#error-handling).

In a Run of a Process that belongs to your Organization or Project, a template error also names the field and the expression:

```text title="errorMessage of a template error"
Template error in the "data.phone" field, {{ event.data.phone | number }}: number could not convert a string to a number.
```

A Run of steps sent with the API call names neither.

## List Runs

`GET /v2/runs` lists Runs, newest first, without `result` and `stepRecords`:

```bash title="Runs of a Trigger that failed"
curl 'https://workflows.reecall.io/v2/runs?triggerId=<trigger-id>&status=failed&limit=20' \
  --header 'Authorization: Bearer sk_YOUR_API_KEY'
```

```json title="Response"
{
  "runs": [
    { "id": "5d1f0c8e-2b7a-4e3d-9c6f-8a1b2c3d4e5f", "status": "failed", "errorCode": "REQUEST_ERROR", "errorMessage": "Request failed with status code 503 (Service Unavailable)", "failedStep": "1" }
  ],
  "nextCursor": "5d1f0c8e-2b7a-4e3d-9c6f-8a1b2c3d4e5f",
  "total": 1
}
```

The response is shortened. `total` counts the Runs that match the filters, across all pages.

Filter with `processId`, `triggerId`, `status`, `kind`, `origin`, `organizationId` and `projectId`. A filter takes several values, comma-separated or repeated, and matches any of them: `status=failed,cancelled`. `createdAfter` and `createdBefore` take a date-time, such as `2026-12-01T00:00:00Z`.

`limit` takes 1 to 100 Runs per page, 50 by default. Read the next page in one of two ways:

- Pass `nextCursor` as `cursor`. `nextCursor` is `null` on the last page. A cursor never skips or repeats a Run while new ones start.
- Pass `page`, from 1, to jump to a page. Don't send `page` and `cursor` together.

A project-scoped key lists the Runs of its Project. An organization-scoped key lists the Runs of its Organization.

## Cancel a Run

```bash title="Cancel a Run"
curl --request POST https://workflows.reecall.io/v2/runs/<run-id>/cancel \
  --header 'Authorization: Bearer sk_YOUR_API_KEY'
```

The Run's status becomes `cancelled` at once. A running attempt stops within about 20 seconds, and the step in progress is interrupted when possible. Steps that already finished stay done: a sent email is not recalled. A Run that already ended answers `409 RUN_ENDED`.

## Retries

Retries are off by default. Turn them on with the `retry` field of a [Trigger](/docs/triggers#retry-policy) or of `POST /v2/execute`.

Only failures that are safe to repeat start a retry:

- A request step whose endpoint answers `429`, `502`, `503`, or `504`
- A request step that cannot connect or times out
- An Agent step whose model provider limits its rate

Other failures end the Run at once, including `4xx` and `500` answers and template errors. When a `429` answer has a `Retry-After` header, the retry waits at least that long, up to 24 hours.

:::warning{title="A retry runs the whole Process again"}

Each retry starts from the first step. Steps that succeeded before the failure run again, and SMS and email steps send their messages again.

:::

Request steps in a Run send an `Idempotency-Key` header, `{runId}:{position}`, with the same value on every attempt. Your endpoint can use it to ignore a request it already processed.

## Limits

| Limit | Value |
| --- | --- |
| Step timeout | 30 seconds by default. Set `timeout` on a step, up to 5 minutes. |
| Attempt duration | 15 minutes. A longer attempt fails with `RUN_ATTEMPT_TIMEOUT`, which is never retried. |
| Runs at once | 10 per Organization. Other Runs wait in the `queued` status. |
| Retries | 3 per Run |
| Request body | 10 MB |

Request steps in a Run cannot reach private or internal network addresses. Such a request fails with `REQUEST_BLOCKED`.

## Data retention

- A Run's input and its System event's data are deleted when the Run ends, after its last attempt, or when it is cancelled.
- The Run keeps `refId`, so you can find the Runs of a record, never the record's data.
- `result` stays with the Run.
- Step records hold no data.
- Runs and their step records are deleted 30 days after they end.

## Error codes

API errors have this body:

```json title="Error body"
{ "success": false, "error": { "code": "RUN_ENDED", "message": "The Run has already ended.", "details": {} } }
```

| Code | Status | Cause |
| --- | --- | --- |
| `INVALID_REQUEST` | 400 | The request body is invalid, such as an empty `steps` array |
| `INVALID_RETRY_POLICY` | 400 | `retry` is not one of the accepted forms |
| `UNAUTHORIZED` | 401 | No API key. The body is `{ "message": "UNAUTHORIZED" }`. |
| `NOT_FOUND` | 404 | No Process or Run with this ID in reach of the key |
| `RUN_ENDED` | 409 | The Run to cancel has already ended |
