Runs
Start an Unstract Flow workflow from your own system, follow the run to its end, read its logs, and recover a run that failed. The run uses the workflow's most recently prepared version, unless the request names another.
Start a run
POST /api/v1/external/accounts/<organization-id>/workflows/<workflow-id>/runs
The workflow ID is the part of the editor's address between /workflows/ and the next /.
The body holds the run's inputs under initial_variables. Send {} for a run with no inputs.
curl -X POST "$FLOW_URL/api/v1/external/accounts/$FLOW_ORG/workflows/$WORKFLOW_ID/runs" \
-H "X-API-Key: $FLOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"initial_variables": {"order_id": "SO-1042"}}'
The response is 202 Accepted with the run, described below. Keep its run_id, for example in RUN_ID.
| Body field | What it does |
|---|---|
initial_variables | The run's inputs. |
tag | Runs the prepared version with this tag, such as "v1.0". |
compilation_id | Runs the prepared version with this ID. Send tag or compilation_id, not both. |
A field the API doesn't know gets 422, so a misspelt field can't start a run without its inputs.
Retry safely
Send an Idempotency-Key header with a value of your own, such as an order number. If the request times out, send it again with the same key and the same body: within 24 hours, Flow returns the run the first request started and adds the header Idempotent-Replayed: true. Without the header, a repeated request starts another run.
curl -X POST "$FLOW_URL/api/v1/external/accounts/$FLOW_ORG/workflows/$WORKFLOW_ID/runs" \
-H "X-API-Key: $FLOW_API_KEY" \
-H "Idempotency-Key: SO-1042" \
-H "Content-Type: application/json" \
-d '{"initial_variables": {"order_id": "SO-1042"}, "tag": "v1.0"}'
The workflow receives initial_variables as its run inputs. Name each input in the spec, for example "The request carries order_id. Look up that order in @database."
| Status | Message | Cause |
|---|---|---|
| 402 | Account allowance exceeded for the current billing period. | Your organization has used its allowance for the current billing period. The code is QUOTA_EXCEEDED. Rate limits and errors shows the body. |
| 403 | Workflow runtime limit exceeded. Contact support for further assistance. | Your organization has reached its limit on total run time. |
| 429 | Account concurrency limit reached: … | Your organization already has as many runs in flight as it may. Try again once some finish. |
| 404 | No successful compilation found. Workflow must be prepared first. | The workflow doesn't exist, or it has never been prepared. |
| 404 | This workflow has no prepared version tagged '…'. | The request's tag matches no prepared version. The code is TAG_NOT_FOUND. |
| 409 | The build you asked to run is not a finished build of this workflow. … | The request's compilation_id isn't a prepared version of this workflow. The code is COMPILATION_NOT_READY. |
| 409 | Workflow is archived. Unarchive it to run it. | The workflow is archived. |
Flow checks in that order, so a request that fails more than one check gets the first code in the table.
Get a run
GET /api/v1/external/accounts/<organization-id>/workflows/<workflow-id>/runs/<run-id>
curl "$FLOW_URL/api/v1/external/accounts/$FLOW_ORG/workflows/$WORKFLOW_ID/runs/$RUN_ID" \
-H "X-API-Key: $FLOW_API_KEY"
A run ID that doesn't belong to that workflow returns 404 Run not found.
List runs
GET /api/v1/external/accounts/<organization-id>/workflows/<workflow-id>/runs
| Parameter | Meaning |
|---|---|
status | Only runs with this status: queued, running, resuming, hitl_paused, completed, partial, failed or cancelled. running also returns runs waiting on a tool limit, which are reported as running. Any other value returns 422. |
limit | 1 to 100. The default is 50. |
cursor | The next_cursor from the previous page. |
curl "$FLOW_URL/api/v1/external/accounts/$FLOW_ORG/workflows/$WORKFLOW_ID/runs?status=failed&limit=20" \
-H "X-API-Key: $FLOW_API_KEY"
The response holds runs, newest first, and next_cursor. Pass next_cursor as cursor to get the next page. It is null on the last page.
| Field | Type | Meaning |
|---|---|---|
run_id | string | The run's ID. |
status | string | One of the status values below. |
initiator_type | string, or null | What started the run. |
created_at, completed_at | string, or null | Timestamps in ISO 8601. |
duration_seconds | number, or null | How long the run worked. Time spent waiting for a review isn't counted. |
| Status | Message | Cause |
|---|---|---|
| 400 | Invalid cursor | cursor isn't a value a previous response returned. |
| 404 | Workflow not found | The workflow doesn't exist in your organization. |
| 422 | Request validation failed | status isn't one of the values above. |
Get run logs
GET /api/v1/external/accounts/<organization-id>/workflows/<workflow-id>/runs/<run-id>/logs
| Parameter | Meaning |
|---|---|
level | Only events at this level: debug, info, warn or error. |
limit | 1 to 500. The default is 200. |
cursor | The next_cursor from the previous page. |
curl "$FLOW_URL/api/v1/external/accounts/$FLOW_ORG/workflows/$WORKFLOW_ID/runs/$RUN_ID/logs?level=error" \
-H "X-API-Key: $FLOW_API_KEY"
The response holds events, oldest first, and next_cursor, which is null on the last page. A run's logs return up to 10,000 events. When the run logged more, the pages hold the newest 10,000 and events_truncated is true. The pages after the first read the run's logs as they were at the first request. For a run that is still going, request again without cursor: the new pages also hold the events it logged since.
| Field | Type | Meaning |
|---|---|---|
ts | string | When the event happened, in ISO 8601. |
level | string, or null | debug, info, warn or error. |
source | string, or null | What produced the event. |
phase | string, or null | The phase of the step. |
step_id | string, or null | The step the event belongs to. |
message | string, or null | The event's text. |
| Status | Message | Cause |
|---|---|---|
| 400 | Invalid cursor | cursor isn't a value a previous response returned. |
| 400 | This run's logs are outside the searchable window. | The run spans more time than the log search allows. |
| 404 | Run not found | The run doesn't exist, or belongs to another workflow. |
List runs across the organization
GET /api/v1/external/accounts/<organization-id>/runs
This lists the runs of every workflow in your organization, newest first.
| Parameter | Meaning |
|---|---|
view | all (the default), active, needs_attention or finished. |
status | Only runs with this status, from the list under The run object. Narrows the view. |
window | How far back to look: 1h, 24h, 7d (the default), 30d or 90d. |
workflow | A workflow ID, or part of a workflow name. |
limit | 1 to 100. The default is 50. |
cursor | The next_cursor from the previous page. |
view | Runs it holds |
|---|---|
active | queued, running and resuming runs, and runs waiting on a tool limit. window doesn't apply: every active run in the organization is listed. |
needs_attention | failed and partial runs, runs that wait for a review, and runs that have waited on a tool limit for over 30 minutes. window applies only to the failed and partial runs: a run that waits for a review or on a tool limit is listed however long ago it started. |
finished | completed, partial, failed and cancelled runs. |
all | Every run in the window. |
curl "$FLOW_URL/api/v1/external/accounts/$FLOW_ORG/runs?view=needs_attention&window=24h" \
-H "X-API-Key: $FLOW_API_KEY"
The response holds runs and next_cursor, which is null on the last page.
| Field | Type | Meaning |
|---|---|---|
run_id, workflow_id | string | The run and its workflow. |
workflow_name | string, or null | The workflow's name. |
status | string | One of the values under The run object. |
summary | string | One line: the status in words, and for a failed, partial or cancelled run the start of its error message. |
initiator_type | string, or null | What started the run. |
created_at, started_at, completed_at | string, or null | Timestamps in ISO 8601. |
duration_seconds | number, or null | How long the run worked. Time spent waiting for a review isn't counted. |
retry_of | string, or null | The run this one started again, when it came from Start again from the beginning. |
recovery | object, or null | For a failed, partial or cancelled run: available and best_option, the option See how a run can be recovered recommends. |
A bad cursor gets 400 Invalid cursor, and a value that isn't in a list above gets 422.
Get a run
GET /api/v1/external/accounts/<organization-id>/runs/<run-id>
Reads one run by its ID alone, whichever workflow it belongs to. A run that doesn't exist in your organization gets 404 Run not found.
curl "$FLOW_URL/api/v1/external/accounts/$FLOW_ORG/runs/$RUN_ID" \
-H "X-API-Key: $FLOW_API_KEY"
The response has every field of a list row, and these:
| Field | Type | Meaning |
|---|---|---|
error_message | string, or null | Why a failed or partial run stopped. |
error_category | string, or null | credentials, timeout, tool_unavailable, quota, validation or unknown. |
failed_step | object, or null | The step that failed: its id and a label in plain words, when there is one. |
error_lines | array, or null | The last five error events of the run, oldest first, each with ts, step_id and message. |
suggestion | string, or null | What to try, matched to the category and to whether Continue from where it stopped is available. |
hitl_ticket_ids | array of strings, or null | The run's open review tickets, while it waits for a review. |
throttled_until | string, or null | When a run waiting on a tool limit tries again. |
retried_as | string, or null | The newest run that started this one again. |
recovery_options | object | The full answer of See how a run can be recovered. |
An error that says a rate limit was reached ("rate limit exceeded", "rate-limited", "rate limit hit", userRateLimitExceeded), says "Too Many Requests", or carries a 429 status ("HTTP 429", "Request failed: 429", "status": 429) reports quota, even when it also mentions 401 or 403, because a rate limit clears on its own and reconnecting the account doesn't help. A rate-limit counter doesn't count, even one of 429: an error that only mentions a limit, such as a ratelimit_remaining count or a link to a rate-limits page, goes to the other categories, so a 401 that carries the count reports credentials.
For a failed or partial run, summary names the failed step: "Failed at Post to Slack: the first sentence of the error."
See how a run can be recovered
GET /api/v1/external/accounts/<organization-id>/runs/<run-id>/recovery
The response lists all five options for the run, with the reason for each one that is unavailable. It holds run_id, status, best_option (the first offered of continue, rerun_failed_items and start_over, or null) and options. Each option has:
| Field | Meaning |
|---|---|
option | The value to send to Recover a run. |
label | The name the app shows. |
what_happens | What the option does, in a sentence. |
available | true when you can use it now. |
creates_new_run | true only for start_over. |
reason, message | When it isn't available: a code from the second table, and the sentence that goes with it. |
option | Label | Offered when | What happens |
|---|---|---|---|
continue | Continue from where it stopped (Continue from the last checkpoint when the run stopped at a checkpoint, not at a failed step) | The run is failed and saved a point to continue from. | Retries the failed step and carries on in the same run. |
skip_step | Skip the failed step and continue | The run is failed and stopped at a failed step. | Marks the step as skipped and carries on in the same run. Later steps that need its output may fail or be skipped. |
rerun_failed_items | Re-run only the items that failed | The run is partial and recorded failed items. | Runs only the failed items again, in the same run. |
start_over | Start again from the beginning | The run is failed, partial or cancelled. | Starts a new run with the same version and the same inputs. It counts as a new run for usage, and its retry_of names the old run. |
release_items | Return the items it was working on | The run finished and still holds items it claimed from one of the workflow's pipelines and hadn't finished: table rows, inbox threads or files that are Claimed or In progress. | Puts them back in the pool, so the next run picks them up. The run can't then continue in place. |
The three options that continue the same run also need the workflow to be unarchived and still on the version the run used. A same-run option moves the run to resuming, and the run counts toward your organization's limit on runs in flight until it finishes.
reason | message |
|---|---|
wrong_status | This option is for {statuses} runs; this run is {status}. |
archived | The workflow is archived. |
restarts_only | This workflow starts again from the beginning when it fails. Use Start again. |
no_checkpoint | This run didn't save a point to continue from. Use Start again. |
no_failed_step | This run stopped at a checkpoint, not at a failed step. Use Continue. |
no_failed_items | No failed items were recorded for this run. |
build_changed | The workflow was changed after this run, so it can't continue. Use Start again. |
no_active_build | The workflow has no prepared version to continue on. Prepare it, or use Start again. |
build_missing | The version this run used is no longer available. |
attempts_used | This run has already been recovered {n} times, the most allowed. Use Start again. |
in_progress | A recovery is already in progress for this run. |
restart_running | Already started again as run {run_id}, which is still running. |
already_restarted | Already started again as run {id}. Follow that run instead. |
claims_released | This run's claims were released, so another run may have taken its items. Start a new run instead. |
no_pool | This run isn't holding any work items. |
still_stopping | This run is still stopping. Try again in a moment. |
A run that was started again refuses continue, skip_step and rerun_failed_items with already_restarted, so the same work doesn't run twice. The app's own Resume and Re-run buttons refuse such a run too.
start_over leaves the old run's pipeline items claimed, so the new run skips them. Return them with release_items first; start_over is still offered afterwards. The app's own Start again from the beginning differs in two ways: its new run uses the version the workflow runs now, not the old run's, and it refuses a run whose restart has finished with already_restarted. See Run details.
Once a run's items were returned, with release_items or the app's Release claims, continue, skip_step and rerun_failed_items refuse it with claims_released: another run may already have taken its items, and working on them again could send a reply or write a row twice. This holds even when nothing was returned. start_over is still offered.
A cancelled run whose last step is still finishing refuses start_over with still_stopping, so two runs don't work at the same time.
When you read a run or its recovery options, available for release_items is a quick check: it looks at table rows, and at inbox threads and files only where the platform keeps them in its database. The recover call itself checks every pipeline and decides. So a run can show no_pool and still have items to return.
release_items covers every pipeline of the workflow. It leaves alone an inbox thread the run already read (Staged) and items the run finished; to return those too, use Release claims in the app. An item another run claimed in the meantime stays with that run.
Recover a run
POST /api/v1/external/accounts/<organization-id>/runs/<run-id>/recover
The body names one option: {"option": "continue"}. Send an Idempotency-Key header to retry safely: within 24 hours, the same key and body returns the first answer with Idempotent-Replayed: true.
curl -X POST "$FLOW_URL/api/v1/external/accounts/$FLOW_ORG/runs/$RUN_ID/recover" \
-H "X-API-Key: $FLOW_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: recover-$RUN_ID-1" \
-d '{"option": "continue"}'
The answer is 202 Accepted, or 200 for release_items, which finishes at once.
| Field | Meaning |
|---|---|
option | The option carried out. |
run_id | The run to follow. It is the same run for every option except start_over, which answers the new run's ID. |
same_run | true when run_id is the run you sent. |
status | The run's status now: resuming for a same-run option, queued for start_over. |
released_items | For release_items, how many items went back to the pool. Otherwise null. |
message | A sentence saying what Flow did. |
When an item is busy, because a run or a reset is changing it at that moment, or a pipeline can't be reached, release_items still answers 200 and returns what it could. message says what was left, for example Returned 2 item(s) to the pool; 1 was busy and was not released. Try again. Send the request again, with a new Idempotency-Key if you sent one, to return the rest.
The request acts as the person who created the key and needs the run:retry permission. It adds an entry to the run's history that names the key.
| Status | Code | When |
|---|---|---|
| 402 | QUOTA_EXCEEDED | Your organization has used its allowance. See Rate limits and errors. |
| 403 | HTTP_403 | Your organization has reached its limit on total run time. |
| 404 | HTTP_404 | The run doesn't exist in your organization. |
| 409 | RECOVERY_NOT_AVAILABLE | The option isn't available. details.reason is a code from the table above, and message says why. |
| 429 | HTTP_429 | Your organization already has as many runs in flight as it may. |
- A workflow that starts again from the beginning when it fails offers only Start again from the beginning and Return the items it was working on.
- Continue from where it stopped works only on the version the run used. After you prepare the workflow again, start the run again instead.
- A run can be recovered in place a limited number of times; after that,
attempts_usedpoints to Start again from the beginning.
Cancel a run
POST /api/v1/external/accounts/<organization-id>/runs/<run-id>/cancel
curl -X POST "$FLOW_URL/api/v1/external/accounts/$FLOW_ORG/runs/$RUN_ID/cancel" \
-H "X-API-Key: $FLOW_API_KEY"
A queued or hitl_paused run, or a run waiting for a call limit (throttled is true), is cancelled at once, with 200. Any other running run, and a resuming one, gets a stop signal, with 202 Accepted, and stops at its next step. The run reads cancelled at once, but the step it is on can keep going until it finishes or reaches its time limit: 3 minutes for most steps, 16 minutes for a website or terminal session, and up to the instance's Max Polling Time for an Unstract or LLMWhisperer step. Wait that long before you start work that depends on the run having stopped. Work the run already did isn't undone. Cancelling a run that is already cancelled answers 200 and changes nothing.
| Field | Meaning |
|---|---|
run_id | The run you sent. |
status | cancelled. |
message | Run cancelled., Stop signal sent; the run stops at its next step. or Run was already cancelled. |
cancelled_at | When the run was cancelled, or null. |
The request acts as the person who created the key and needs the run:cancel permission. The run records that person as the one who cancelled it, and the key's name as the reason.
| Status | Code | When |
|---|---|---|
| 404 | HTTP_404 | The run doesn't exist in your organization. |
| 409 | RUN_FINISHED | The run already ended completed, partial or failed. details.status is its status. |
The run object
| Field | Type | Meaning |
|---|---|---|
run_id | string | The run's ID. |
status | string | One of the values below. The Runs page shows each with the label beside it. |
hitl_paused | boolean | true while the run waits for a review. |
hitl_ticket_ids | array of strings, or null | The run's open review tickets while it waits for a review, including any still-open ticket from an earlier Info only, no stop review. |
throttled | boolean | true while the run waits for a call limit. |
throttled_until | string, or null | When a waiting run tries again, in ISO 8601. |
error_message | string, or null | Why the run failed. A cancelled run says why it was cancelled, and a run that was stuck and recovered may keep its earlier message, so read status to tell whether a run failed. |
created_at, started_at, completed_at | string, or null | Timestamps in ISO 8601. |
status | Meaning |
|---|---|
queued | Queued: waiting to start. |
running | Running: working through its steps. A run shown as Waiting for quota also reports running, with throttled: true. |
resuming | Resuming: picking up again after a pause. |
hitl_paused | Needs review: waiting for a person to answer a review. |
completed | Succeeded: finished. |
partial | Partial: finished, and some items in a loop failed. |
failed | Failed: stopped on an error. error_message says why. |
cancelled | Cancelled. |
completed, partial, failed and cancelled are final. Poll until you see one of them. Runs and run statuses explains each status.
Get a run's result
GET /api/v1/external/accounts/<organization-id>/workflows/<workflow-id>/runs/<run-id>/results
curl "$FLOW_URL/api/v1/external/accounts/$FLOW_ORG/workflows/$WORKFLOW_ID/runs/$RUN_ID/results" \
-H "X-API-Key: $FLOW_API_KEY"
The response holds what the workflow returned, under value, with its value_type (dict, list, string, number, boolean or null). Add ?path= and a dot path to read one field of it, for example ?path=totals.count. A path that leads nowhere answers 404.
A run that hasn't finished answers 409. A run that finished without recording a result answers 404 This run recorded no result; one that failed or was cancelled answers 404 This run did not finish, so it recorded no result. A result over 64 KB comes back as {"truncated": true, "preview": "…"}, a result Flow couldn't read as {"unavailable": true, "reason": "…"}, and a workflow that returns something other than a record comes back as {"value": …}, so ?path=value reads it.
- A replay returns the first request's run as it is now. If that request failed after its run was created, the run it returns stays
queuedand is later markedfailed; send the request again with a new key. - Write IDs in the address in lower case with hyphens, as Flow shows them. Any other spelling gets 404.
- An
Idempotency-Keyis remembered for 24 hours, for one workflow. The same key with a different body gets 422IDEMPOTENCY_KEY_REUSED, and a retry sent while the first request is still starting its run gets 409IDEMPOTENCY_IN_PROGRESS. This also happens for up to 15 minutes after a first request that failed while starting its run; after that, send it again or use a new key. When Flow can't check the key, the request gets 503IDEMPOTENCY_UNAVAILABLEand starts nothing; send it again. - A run that has stopped making progress reports
runningwith anerror_messageset, for up to 30 minutes, thenfailed. Common problems covers it.