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
-
Create a key with a budget for the script, or use an existing one, on the Virtual Keys page.
-
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"}}' -
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"}}' -
Append the model's messages with
POST /v1/workflows/runs/{run_id}/messagesso the conversation is kept with the run, and set the finaloutputwithPATCH /v1/workflows/runs/{run_id}when the job is done. -
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.
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
| Status | What it means | Fix |
|---|---|---|
403 workflow_runner license message | The 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 messages | The 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 connected | The 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
| Level | Line | Meaning | Action needed |
|---|---|---|---|
| ERROR | Error 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 messages | The database refused a stored-run request, and the caller got the 500 above. | Read the error and check the database. |
| ERROR | Sequence 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. |
Related
- Workflow runner runs the steps for you and records them here.
- Workflow Runs page describes every control of the Admin UI page.
- Run ledger joins a run with its model requests, tool calls and spend.
- Compliance settings hold the retention period for runs.