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.
| Method | Path | Summary |
|---|---|---|
| GET | /v1/workflows/runs | List workflow runs |
| POST | /v1/workflows/runs | Create 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}/events | List a run's events |
| POST | /v1/workflows/runs/{run_id}/events | Append an event to a run |
| GET | /v1/workflows/runs/{run_id}/messages | List a run's conversation messages |
| POST | /v1/workflows/runs/{run_id}/messages | Append 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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
workflow_type | query | string or null | No | |
status | query | string or null | No | |
limit | query | integer | No |
Example request:
curl -X GET "http://localhost:4000/v1/workflows/runs" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The runs the caller may see | application/json WorkflowRunListResponse |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
runs | array of WorkflowRunResponse | Yes | Runs |
count | integer | Yes | Count |
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):
| Field | Type | Required | Description |
|---|---|---|---|
workflow_type | string | Yes | Workflow Type |
input | object or null | No | Input |
metadata | object or null | No | Metadata |
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:
| Status | Description | Body |
|---|---|---|
| 200 | The new run | application/json WorkflowRunResponse |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | Your role can read workflow runs but not change them | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
run_id | string | Yes | Run Id |
session_id | string | Yes | Session Id |
workflow_type | string | Yes | Workflow Type |
status | string | Yes | Status |
created_by | string or null | No | Created By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
input | any or null | No | Input |
output | any or null | No | Output |
metadata | any or null | No | Metadata |
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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
run_id | path | string | Yes |
Example request:
curl -X GET "http://localhost:4000/v1/workflows/runs/run_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The run with its latest event | application/json WorkflowRunResponse |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 404 | Run 'run_01J...' not found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
run_id | string | Yes | Run Id |
session_id | string | Yes | Session Id |
workflow_type | string | Yes | Workflow Type |
status | string | Yes | Status |
created_by | string or null | No | Created By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
input | any or null | No | Input |
output | any or null | No | Output |
metadata | any or null | No | Metadata |
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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
run_id | path | string | Yes |
Request body (application/json, schema WorkflowRunUpdateRequest):
| Field | Type | Required | Description |
|---|---|---|---|
status | enum: "pending", "running", "paused", "completed", "failed", "cancelled" or null | No | Status |
output | object or null | No | Output |
metadata | object or null | No | Metadata |
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:
| Status | Description | Body |
|---|---|---|
| 200 | The updated run | application/json WorkflowRunResponse |
| 400 | No fields to update | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | Your role can read workflow runs but not change them | application/json ErrorDetail |
| 404 | Run 'run_01J...' not found | application/json ErrorDetail |
| 409 | Run 'run_01J...' is driven by the workflow runner; use /v1/workflows/runner/runs/run_01J.../cancel | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
run_id | string | Yes | Run Id |
session_id | string | Yes | Session Id |
workflow_type | string | Yes | Workflow Type |
status | string | Yes | Status |
created_by | string or null | No | Created By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
input | any or null | No | Input |
output | any or null | No | Output |
metadata | any or null | No | Metadata |
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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
run_id | path | string | Yes | |
limit | query | integer | No |
Example request:
curl -X GET "http://localhost:4000/v1/workflows/runs/run_id-123/events" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The event log in order | application/json WorkflowEventListResponse |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 404 | Run 'run_01J...' not found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
events | array of WorkflowEventResponse | Yes | Events |
count | integer | Yes | Count |
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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
run_id | path | string | Yes |
Request body (application/json, schema WorkflowEventCreateRequest):
| Field | Type | Required | Description |
|---|---|---|---|
event_type | string | Yes | Event Type |
step_name | string | Yes | Step Name |
data | object or null | No | Data |
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:
| Status | Description | Body |
|---|---|---|
| 200 | The stored event with its sequence number | application/json WorkflowEventResponse |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | Your role can read workflow runs but not change them | application/json ErrorDetail |
| 404 | Run 'run_01J...' not found | application/json ErrorDetail |
| 409 | Another writer appended to this run at the same time, retry the request | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
event_id | string | Yes | Event Id |
run_id | string | Yes | Run Id |
event_type | string | Yes | Event Type |
step_name | string | Yes | Step Name |
sequence_number | integer | Yes | Sequence Number |
data | any or null | No | Data |
created_at | string or null | No | Created 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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
run_id | path | string | Yes | |
limit | query | integer | No |
Example request:
curl -X GET "http://localhost:4000/v1/workflows/runs/run_id-123/messages" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The conversation in order | application/json WorkflowMessageListResponse |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 404 | Run 'run_01J...' not found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
messages | array of WorkflowMessageResponse | Yes | Messages |
count | integer | Yes | Count |
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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
run_id | path | string | Yes |
Request body (application/json, schema WorkflowMessageCreateRequest):
| Field | Type | Required | Description |
|---|---|---|---|
role | string | Yes | Role |
content | string | Yes | Content |
session_id | string or null | No | Session 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:
| Status | Description | Body |
|---|---|---|
| 200 | The stored message | application/json WorkflowMessageResponse |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | Your role can read workflow runs but not change them | application/json ErrorDetail |
| 404 | Run 'run_01J...' not found | application/json ErrorDetail |
| 409 | Another writer appended to this run at the same time, retry the request | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
message_id | string | Yes | Message Id |
run_id | string | Yes | Run Id |
role | string | Yes | Role |
content | string | Yes | Content |
sequence_number | integer | Yes | Sequence Number |
session_id | string or null | No | Session Id |
created_at | string or null | No | Created At |