> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anyreach.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Sync vs async execution

> Pick the right execution mode for your workflow.

Workflows can run synchronously (the caller waits for completion) or asynchronously (the caller gets an `execution_id` immediately and the workflow runs in the background).

## At a glance

|                 | Sync                              | Async                                                    |
| --------------- | --------------------------------- | -------------------------------------------------------- |
| Caller behavior | Waits for completion              | Returns immediately with `execution_id`                  |
| Wait steps      | Block the caller (avoid)          | Suspend the execution (works correctly)                  |
| Max duration    | \~60s practical limit             | Up to the workflow's configured timeout (default 1 hour) |
| Retries         | Not supported                     | Configurable per workflow                                |
| Used by         | Agent tools, Ongoing Conversation | Timer, External Apps, Post Call, batch jobs              |

## When to use sync

* The caller needs the result immediately (agent tool during a live call)
* Total expected duration is well under 30 seconds
* No Wait steps
* Low-latency response matters

## When to use async

* The workflow has Wait steps
* Total duration could exceed 30 seconds
* Retry on failure matters
* The caller doesn't need the result synchronously
* High-concurrency batch processing

## Sync execution

```bash theme={null}
curl -X POST https://api.anyreach.ai/workflow/workflow-executions \
  -H "Authorization: Bearer $ANYREACH_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "workflow_id": "wf_...",
    "workflow_version": "latest",
    "input_data": { "customer_email": "alice@example.com" }
  }'
```

Success response:

```json theme={null}
{
  "status": "success",
  "execution_id": "exec_...",
  "output": { /* whatever the Output step returned */ }
}
```

Failure response:

```json theme={null}
{
  "status": "failed",
  "execution_id": "exec_...",
  "error": { "step_name": "Lookup contact", "message": "..." }
}
```

## Async execution

```bash theme={null}
curl -X POST https://api.anyreach.ai/workflow/workflow-executions/async \
  -H "Authorization: Bearer $ANYREACH_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "workflow_id": "wf_...",
    "workflow_version": "latest",
    "input_data": { "customer_email": "alice@example.com" }
  }'
```

Immediate response:

```json theme={null}
{
  "status": "pending",
  "execution_id": "exec_..."
}
```

Poll for the result:

```bash theme={null}
curl https://api.anyreach.ai/workflow/workflow-executions/$EXEC_ID \
  -H "Authorization: Bearer $ANYREACH_TOKEN"
```
