Skip to main content

Workflow management API

This page documents the 8 gateway endpoints tagged workflow management in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.

MethodPathSummary
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

Endpoints​

GET /v1/workflows/runs​

List workflow runs

List stored workflow runs, newest first, up to limit (50 by default, at most 250).

Filter by workflow_type and by status, which takes one status or several separated by commas, such as status=running,paused. Proxy admins and admin viewers see every run, and every other key only the runs it created. Nothing is changed.

Parameters:

NameInTypeRequiredDescription
workflow_typequerystring or nullNo
statusquerystring or nullNo
limitqueryintegerNo

Example request:

curl -X GET "http://localhost:4000/v1/workflows/runs" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The runs the caller may seeapplication/json WorkflowRunListResponse
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
runsarray of WorkflowRunResponseYesRuns
countintegerYesCount

POST /v1/workflows/runs​

Create a workflow run

Create a new workflow run. Returns run_id and session_id.

The caller's API key token is stored as created_by so that non-admin keys can only see and modify their own runs.

Request body (application/json, schema WorkflowRunCreateRequest):

FieldTypeRequiredDescription
workflow_typestringYesWorkflow Type
inputobject or nullNoInput
metadataobject or nullNoMetadata

Example request:

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"
}
}'

Responses:

StatusDescriptionBody
200The new runapplication/json WorkflowRunResponse
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403Your role can read workflow runs but not change themapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
run_idstringYesRun Id
session_idstringYesSession Id
workflow_typestringYesWorkflow Type
statusstringYesStatus
created_bystring or nullNoCreated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At
inputany or nullNoInput
outputany or nullNoOutput
metadataany or nullNoMetadata

GET /v1/workflows/runs/{run_id}​

Read a workflow run

Read one stored workflow run with its most recent event.

Use it to check where a run your agent or app recorded has got to. A proxy admin or an admin viewer can read any run, and every other key only the runs it created, so another key's run answers 404 exactly like an unknown id. Nothing is changed.

Parameters:

NameInTypeRequiredDescription
run_idpathstringYes

Example request:

curl -X GET "http://localhost:4000/v1/workflows/runs/run_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The run with its latest eventapplication/json WorkflowRunResponse
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
404Run 'run_01J...' not foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
run_idstringYesRun Id
session_idstringYesSession Id
workflow_typestringYesWorkflow Type
statusstringYesStatus
created_bystring or nullNoCreated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At
inputany or nullNoInput
outputany or nullNoOutput
metadataany or nullNoMetadata

PATCH /v1/workflows/runs/{run_id}​

Update a workflow run's status, output or metadata

Change the status, output or metadata of a stored workflow run.

Send only the fields to change, an empty body answers 400. A proxy admin can change any run and every other key only the runs it created, so another key's run answers 404. A run driven by the workflow runner answers 409 and is changed through its runner routes instead. The change is written to the audit log with the status before and after.

Parameters:

NameInTypeRequiredDescription
run_idpathstringYes

Request body (application/json, schema WorkflowRunUpdateRequest):

FieldTypeRequiredDescription
statusenum: "pending", "running", "paused", "completed", "failed", "cancelled" or nullNoStatus
outputobject or nullNoOutput
metadataobject or nullNoMetadata

Example request:

curl -X PATCH "http://localhost:4000/v1/workflows/runs/run_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"status": "completed",
"output": {
"notes_url": "https://docs.example.com/v2.4.0"
}
}'

Responses:

StatusDescriptionBody
200The updated runapplication/json WorkflowRunResponse
400No fields to updateapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403Your role can read workflow runs but not change themapplication/json ErrorDetail
404Run 'run_01J...' not foundapplication/json ErrorDetail
409Run 'run_01J...' is driven by the workflow runner; use /v1/workflows/runner/runs/run_01J.../cancelapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
run_idstringYesRun Id
session_idstringYesSession Id
workflow_typestringYesWorkflow Type
statusstringYesStatus
created_bystring or nullNoCreated By
created_atstring or nullNoCreated At
updated_atstring or nullNoUpdated At
inputany or nullNoInput
outputany or nullNoOutput
metadataany or nullNoMetadata

GET /v1/workflows/runs/{run_id}/events​

List a run's events

Fetch event log for a run, ordered by sequence_number. Default limit 100, max 500.

Parameters:

NameInTypeRequiredDescription
run_idpathstringYes
limitqueryintegerNo

Example request:

curl -X GET "http://localhost:4000/v1/workflows/runs/run_id-123/events" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The event log in orderapplication/json WorkflowEventListResponse
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
404Run 'run_01J...' not foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
eventsarray of WorkflowEventResponseYesEvents
countintegerYesCount

POST /v1/workflows/runs/{run_id}/events​

Append an event to a run

Append an event to the run's event log. Also updates run.status if event_type maps to a status.

Sequence numbers use optimistic concurrency: on a unique-constraint collision (concurrent append), retries up to _MAX_SEQUENCE_RETRIES times with a fresh MAX+1. The event+status update is atomic in a single DB transaction.

Parameters:

NameInTypeRequiredDescription
run_idpathstringYes

Request body (application/json, schema WorkflowEventCreateRequest):

FieldTypeRequiredDescription
event_typestringYesEvent Type
step_namestringYesStep Name
dataobject or nullNoData

Example request:

curl -X POST "http://localhost:4000/v1/workflows/runs/run_id-123/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"
}
}'

Responses:

StatusDescriptionBody
200The stored event with its sequence numberapplication/json WorkflowEventResponse
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403Your role can read workflow runs but not change themapplication/json ErrorDetail
404Run 'run_01J...' not foundapplication/json ErrorDetail
409Another writer appended to this run at the same time, retry the requestapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
event_idstringYesEvent Id
run_idstringYesRun Id
event_typestringYesEvent Type
step_namestringYesStep Name
sequence_numberintegerYesSequence Number
dataany or nullNoData
created_atstring or nullNoCreated At

GET /v1/workflows/runs/{run_id}/messages​

List a run's conversation messages

Fetch conversation history for a run, ordered by sequence_number. Default limit 100, max 500.

Parameters:

NameInTypeRequiredDescription
run_idpathstringYes
limitqueryintegerNo

Example request:

curl -X GET "http://localhost:4000/v1/workflows/runs/run_id-123/messages" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The conversation in orderapplication/json WorkflowMessageListResponse
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
404Run 'run_01J...' not foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
messagesarray of WorkflowMessageResponseYesMessages
countintegerYesCount

POST /v1/workflows/runs/{run_id}/messages​

Append a conversation message to a run

Append a conversation message. Stores full content (not truncated).

Uses optimistic concurrency for sequence numbers.

Parameters:

NameInTypeRequiredDescription
run_idpathstringYes

Request body (application/json, schema WorkflowMessageCreateRequest):

FieldTypeRequiredDescription
rolestringYesRole
contentstringYesContent
session_idstring or nullNoSession Id

Example request:

curl -X POST "http://localhost:4000/v1/workflows/runs/run_id-123/messages" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"role": "assistant",
"content": "Collected 14 merged pull requests since v2.3.0.",
"session_id": "ses_01J..."
}'

Responses:

StatusDescriptionBody
200The stored messageapplication/json WorkflowMessageResponse
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403Your role can read workflow runs but not change themapplication/json ErrorDetail
404Run 'run_01J...' not foundapplication/json ErrorDetail
409Another writer appended to this run at the same time, retry the requestapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
message_idstringYesMessage Id
run_idstringYesRun Id
rolestringYesRole
contentstringYesContent
sequence_numberintegerYesSequence Number
session_idstring or nullNoSession Id
created_atstring or nullNoCreated At