Skip to main content

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 fieldWhat it does
initial_variablesThe run's inputs.
tagRuns the prepared version with this tag, such as "v1.0".
compilation_idRuns 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."

StatusMessageCause
402Account 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.
403Workflow runtime limit exceeded. Contact support for further assistance.Your organization has reached its limit on total run time.
429Account concurrency limit reached: …Your organization already has as many runs in flight as it may. Try again once some finish.
404No successful compilation found. Workflow must be prepared first.The workflow doesn't exist, or it has never been prepared.
404This workflow has no prepared version tagged '…'.The request's tag matches no prepared version. The code is TAG_NOT_FOUND.
409The 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.
409Workflow 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
ParameterMeaning
statusOnly 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.
limit1 to 100. The default is 50.
cursorThe 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.

FieldTypeMeaning
run_idstringThe run's ID.
statusstringOne of the status values below.
initiator_typestring, or nullWhat started the run.
created_at, completed_atstring, or nullTimestamps in ISO 8601.
duration_secondsnumber, or nullHow long the run worked. Time spent waiting for a review isn't counted.
StatusMessageCause
400Invalid cursorcursor isn't a value a previous response returned.
404Workflow not foundThe workflow doesn't exist in your organization.
422Request validation failedstatus isn't one of the values above.

Get run logs​

GET /api/v1/external/accounts/<organization-id>/workflows/<workflow-id>/runs/<run-id>/logs
ParameterMeaning
levelOnly events at this level: debug, info, warn or error.
limit1 to 500. The default is 200.
cursorThe 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.

FieldTypeMeaning
tsstringWhen the event happened, in ISO 8601.
levelstring, or nulldebug, info, warn or error.
sourcestring, or nullWhat produced the event.
phasestring, or nullThe phase of the step.
step_idstring, or nullThe step the event belongs to.
messagestring, or nullThe event's text.
StatusMessageCause
400Invalid cursorcursor isn't a value a previous response returned.
400This run's logs are outside the searchable window.The run spans more time than the log search allows.
404Run not foundThe 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.

ParameterMeaning
viewall (the default), active, needs_attention or finished.
statusOnly runs with this status, from the list under The run object. Narrows the view.
windowHow far back to look: 1h, 24h, 7d (the default), 30d or 90d.
workflowA workflow ID, or part of a workflow name.
limit1 to 100. The default is 50.
cursorThe next_cursor from the previous page.
viewRuns it holds
activequeued, running and resuming runs, and runs waiting on a tool limit. window doesn't apply: every active run in the organization is listed.
needs_attentionfailed 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.
finishedcompleted, partial, failed and cancelled runs.
allEvery 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.

FieldTypeMeaning
run_id, workflow_idstringThe run and its workflow.
workflow_namestring, or nullThe workflow's name.
statusstringOne of the values under The run object.
summarystringOne line: the status in words, and for a failed, partial or cancelled run the start of its error message.
initiator_typestring, or nullWhat started the run.
created_at, started_at, completed_atstring, or nullTimestamps in ISO 8601.
duration_secondsnumber, or nullHow long the run worked. Time spent waiting for a review isn't counted.
retry_ofstring, or nullThe run this one started again, when it came from Start again from the beginning.
recoveryobject, or nullFor 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:

FieldTypeMeaning
error_messagestring, or nullWhy a failed or partial run stopped.
error_categorystring, or nullcredentials, timeout, tool_unavailable, quota, validation or unknown.
failed_stepobject, or nullThe step that failed: its id and a label in plain words, when there is one.
error_linesarray, or nullThe last five error events of the run, oldest first, each with ts, step_id and message.
suggestionstring, or nullWhat to try, matched to the category and to whether Continue from where it stopped is available.
hitl_ticket_idsarray of strings, or nullThe run's open review tickets, while it waits for a review.
throttled_untilstring, or nullWhen a run waiting on a tool limit tries again.
retried_asstring, or nullThe newest run that started this one again.
recovery_optionsobjectThe 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:

FieldMeaning
optionThe value to send to Recover a run.
labelThe name the app shows.
what_happensWhat the option does, in a sentence.
availabletrue when you can use it now.
creates_new_runtrue only for start_over.
reason, messageWhen it isn't available: a code from the second table, and the sentence that goes with it.
optionLabelOffered whenWhat happens
continueContinue 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_stepSkip the failed step and continueThe 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_itemsRe-run only the items that failedThe run is partial and recorded failed items.Runs only the failed items again, in the same run.
start_overStart again from the beginningThe 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_itemsReturn the items it was working onThe 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.

reasonmessage
wrong_statusThis option is for {statuses} runs; this run is {status}.
archivedThe workflow is archived.
restarts_onlyThis workflow starts again from the beginning when it fails. Use Start again.
no_checkpointThis run didn't save a point to continue from. Use Start again.
no_failed_stepThis run stopped at a checkpoint, not at a failed step. Use Continue.
no_failed_itemsNo failed items were recorded for this run.
build_changedThe workflow was changed after this run, so it can't continue. Use Start again.
no_active_buildThe workflow has no prepared version to continue on. Prepare it, or use Start again.
build_missingThe version this run used is no longer available.
attempts_usedThis run has already been recovered {n} times, the most allowed. Use Start again.
in_progressA recovery is already in progress for this run.
restart_runningAlready started again as run {run_id}, which is still running.
already_restartedAlready started again as run {id}. Follow that run instead.
claims_releasedThis run's claims were released, so another run may have taken its items. Start a new run instead.
no_poolThis run isn't holding any work items.
still_stoppingThis 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.

FieldMeaning
optionThe option carried out.
run_idThe run to follow. It is the same run for every option except start_over, which answers the new run's ID.
same_runtrue when run_id is the run you sent.
statusThe run's status now: resuming for a same-run option, queued for start_over.
released_itemsFor release_items, how many items went back to the pool. Otherwise null.
messageA 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.

StatusCodeWhen
402QUOTA_EXCEEDEDYour organization has used its allowance. See Rate limits and errors.
403HTTP_403Your organization has reached its limit on total run time.
404HTTP_404The run doesn't exist in your organization.
409RECOVERY_NOT_AVAILABLEThe option isn't available. details.reason is a code from the table above, and message says why.
429HTTP_429Your organization already has as many runs in flight as it may.
Limitations
  • 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_used points 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.

FieldMeaning
run_idThe run you sent.
statuscancelled.
messageRun cancelled., Stop signal sent; the run stops at its next step. or Run was already cancelled.
cancelled_atWhen 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.

StatusCodeWhen
404HTTP_404The run doesn't exist in your organization.
409RUN_FINISHEDThe run already ended completed, partial or failed. details.status is its status.

The run object​

FieldTypeMeaning
run_idstringThe run's ID.
statusstringOne of the values below. The Runs page shows each with the label beside it.
hitl_pausedbooleantrue while the run waits for a review.
hitl_ticket_idsarray of strings, or nullThe run's open review tickets while it waits for a review, including any still-open ticket from an earlier Info only, no stop review.
throttledbooleantrue while the run waits for a call limit.
throttled_untilstring, or nullWhen a waiting run tries again, in ISO 8601.
error_messagestring, or nullWhy 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_atstring, or nullTimestamps in ISO 8601.
statusMeaning
queuedQueued: waiting to start.
runningRunning: working through its steps. A run shown as Waiting for quota also reports running, with throttled: true.
resumingResuming: picking up again after a pause.
hitl_pausedNeeds review: waiting for a person to answer a review.
completedSucceeded: finished.
partialPartial: finished, and some items in a loop failed.
failedFailed: stopped on an error. error_message says why.
cancelledCancelled.

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.

Limitations
  • 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 queued and is later marked failed; 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-Key is remembered for 24 hours, for one workflow. The same key with a different body gets 422 IDEMPOTENCY_KEY_REUSED, and a retry sent while the first request is still starting its run gets 409 IDEMPOTENCY_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 503 IDEMPOTENCY_UNAVAILABLE and starts nothing; send it again.
  • A run that has stopped making progress reports running with an error_message set, for up to 30 minutes, then failed. Common problems covers it.