Skip to main content

Workflow runs

Workflow runs give an agent or an automation a place to keep state that outlives a single request. Think of a run as a job folder on the gateway. It has a type, an input, a status, metadata and an output, an ordered event log that shows what happened in which order, and a conversation history. These endpoints only store and return state, so any orchestrator, script or scheduler can use them to make a long running job observable and resumable without building its own database. To have the gateway itself run the steps against your agents, use the workflow runner, which records its runs here too.

Workflow runs need a Spanway enterprise license that includes the workflow_runner feature. Without it every /v1/workflows/runs route answers 403.

Scenario​

A release engineering team runs a nightly script that collects merged pull requests, drafts release notes with a model and posts them for review. When the script dies half way, nobody knows which step it reached. By recording each step as an event on a workflow run, the team can open the Workflow Runs page the next morning, see that collect-commits finished and draft-notes failed, read the failure, and resume from there.

Steps​

  1. Create a key with a budget for the script, or use an existing one, on the Virtual Keys page.

  2. From the script, create the run.

    curl -X POST http://localhost:4000/v1/workflows/runs -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{"workflow_type": "release-notes", "input": {"tag": "v2.4.0"}, "metadata": {"repo": "platform"}}'
  3. Before and after each step, append an event with the run id from the response.

    curl -X POST http://localhost:4000/v1/workflows/runs/run_01J.../events -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{"event_type": "step.started", "step_name": "collect-commits", "data": {"since": "v2.3.0"}}'
  4. Append the model's messages with POST /v1/workflows/runs/{run_id}/messages so the conversation is kept with the run, and set the final output with PATCH /v1/workflows/runs/{run_id} when the job is done.

  5. In the Admin UI open Workflow Runs under Agentic, stay on the Runs tab, use Filters to pick Status Failed, and click the row to open the run drawer with its event log and messages.

Expected result​

The create call answers 200 with the run record.

{"run_id": "run_01J...", "session_id": "ses_01J...", "workflow_type": "release-notes", "status": "pending", "created_by": "sk-...hash"}

Each event answers 200 with its sequence_number, the run's status follows the events, and the Runs tab shows the run with its latest event and lets you open the full log.

Lifecycle​

curl -X POST http://localhost:4000/v1/workflows/runs -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"workflow_type": "release-notes", "input": {"tag": "v2.4.0"}, "metadata": {"repo": "platform"}}'
{"run_id": "run_01J...", "session_id": "ses_01J...", "workflow_type": "release-notes", "status": "pending", "created_by": "sk-...hash"}

Status is one of pending, running, paused, completed, failed and cancelled. PATCH /v1/workflows/runs/{run_id} sets status, output or metadata directly. Events also move it: step.started sets running, step.failed sets failed, hook.waiting sets paused and hook.received sets running again.

curl -X POST http://localhost:4000/v1/workflows/runs/run_01J.../events -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"event_type": "step.started", "step_name": "collect-commits", "data": {"since": "v2.3.0"}}'

Each event gets the next sequence number for the run. Appends use optimistic concurrency, so two writers appending at once both succeed with distinct numbers, and the event and the status change are written in one transaction. Creating a run, changing it with PATCH and an event that moves it to another status each write an audit log row with the status before and after. Messages are conversation content and write no audit row. POST .../messages appends a conversation message with role, content and an optional session_id, stored in full, and GET .../messages returns the history in order.

GET /v1/workflows/runs lists runs, newest first, with workflow_type and status filters and a limit of up to 250 (50 by default). status takes one status or several separated by commas, for example status=running,paused. GET /v1/workflows/runs/{run_id} returns the run with its most recent event, and GET .../events returns the full log with a limit of up to 500.

Ownership​

The key that creates a run is recorded as created_by. A non admin key can only see and change its own runs, and internal users reach these routes without listing them in allowed_routes. Proxy admins and admin viewers see every run, and only proxy admins change runs they did not create. Read only roles (proxy_admin_viewer and internal_user_viewer) get 403 on every write. A custom role grants these routes through workflows.read and workflows.write. Runs need a database. Runs driven by the workflow runner can be read here, but PATCH, events and messages answer 409 for them because the runner owns their state.

MethodPathSummary
GET/v1/workflows/definitions/listList saved workflows
GET/v1/workflows/definitions/infoRead a saved workflow and one version
GET/v1/workflows/definitions/usagesList the workflows that call this one
POST/v1/workflows/definitions/newSave a workflow definition
POST/v1/workflows/definitions/versions/newAdd a version to a saved workflow
GET/v1/workflows/definitions/compareCompare two versions of a saved workflow
POST/v1/workflows/definitions/versions/restoreRestore an earlier version of a saved workflow
POST/v1/workflows/definitions/haltStop or allow new runs of a saved workflow
POST/v1/workflows/definitions/deleteDelete a saved workflow and all its versions
POST/v1/workflows/definitions/runRun a version of a saved workflow
GET/v1/workflows/variables/listList an organization's workflow variables
POST/v1/workflows/variables/setCreate or replace a workflow variable
POST/v1/workflows/variables/deleteDelete a workflow variable
GET/v1/workflows/runsList workflow runs
POST/v1/workflows/runsCreate a workflow run
GET/v1/workflows/runs/{run_id}Read a workflow run
PATCH/v1/workflows/runs/{run_id}Update a workflow run's status, output or metadata
GET/v1/workflows/runs/{run_id}/eventsList a run's events
POST/v1/workflows/runs/{run_id}/eventsAppend an event to a run
GET/v1/workflows/runs/{run_id}/messagesList a run's conversation messages
POST/v1/workflows/runs/{run_id}/messagesAppend a conversation message to a run
POST/v1/workflows/runner/startStart a workflow run
GET/v1/workflows/runner/runsList workflow runner runs
GET/v1/workflows/runner/runs/{run_id}/stepsRead a run with its steps
GET/v1/workflows/runner/runs/{run_id}/historyRead every attempt of every step
POST/v1/workflows/runner/runs/{run_id}/cancelCancel a run
POST/v1/workflows/runner/runs/{run_id}/resumeResume a failed or cancelled run
POST/v1/workflows/runner/agents/{agent_id}/releaseRelease an agent halted by the kill switch
GET/v1/workflows/runner/statusRead the runner's status
GET/v1/workflows/runner/dead_lettersList dead letters
GET/v1/workflows/runner/dead_letters/{dead_letter_id}Read one dead letter
POST/v1/workflows/runner/dead_letters/{dead_letter_id}/requeueRequeue a dead letter's run
POST/v1/workflows/runner/dead_letters/{dead_letter_id}/discardDiscard a dead letter
POST/v1/workflows/runner/runs/{run_id}/replayReplay a run from one step
POST/v1/workflows/runner/pins/newPin a step output as test data
GET/v1/workflows/runner/pinsList pinned test data
POST/v1/workflows/runner/pins/deleteDelete a pin

Admin UI​

The Runs tab of the Workflow Runs page under Agentic lists runs, their status and their latest event, and opens the event log and messages of each run. Internal users see every runner run of their own keys, and the stored runs that the key they signed in with created, because a stored run only records the key that created it. Anyone who may change a run can also set its status from the run's detail sheet, except for runs the workflow runner drives.

Retention and data subject requests​

Stored runs follow the same rules as runner runs. Set maximum_workflow_run_retention_period in the compliance settings to delete runs, with their events and messages, that were not updated within that period, and maximum_spend_logs_retention_period applies when it is shorter. Erasing a user through a data subject request deletes the runs their keys stored, and a data subject export includes them. See the runner's retention section for the details.

Errors​

StatusWhat it meansFix
403 workflow_runner license messageThe license lacks the workflow_runner feature.Add the feature to the license or ask sales@spanway.ai.
403 "Your role can read workflow runs but not change them"A read only role tried to create or change a run.Use a key with a writing role, or grant workflows.write to the custom role.
404 "Run 'run_...' not found"The id is wrong, or the run belongs to another key and the caller is not an admin.Check the id on the Runs tab, or call with the key that created the run.
409 on PATCH, events or messagesThe run is driven by the workflow runner, which owns its state.Read the run here and use the runner's routes to cancel or resume it.
409 "Another writer appended to this run at the same time, retry the request"Several writers kept appending events or messages to one run at the same moment, and five tries in a row collided.Send the event or message again.
400 "No fields to update"The PATCH body carried none of status, output or metadata.Send at least one of them.
500 database not connectedThe gateway has no database, so runs cannot be stored.Set DATABASE_URL and restart the gateway.
500 "The workflow run store could not complete the request, see the gateway log for the cause"The database refused the read or write. The cause is logged as Error creating workflow run, Error listing workflow runs and similar, never sent to the caller.Read the gateway log line and check the database.

Logs​

LevelLineMeaningAction needed
ERRORError creating workflow run: <error>, Error listing workflow runs, Error getting workflow run, Error updating workflow run, Error appending workflow event, Error listing workflow events, Error appending workflow message or Error listing workflow messagesThe database refused a stored-run request, and the caller got the 500 above.Read the error and check the database.
ERRORSequence number collision after 5 retries for run <run id>Appends to one run kept colliding, and the caller got the 409 above.None if rare. Several writers on one run should send their events one at a time.