Workflow definitions API
This page documents the 13 gateway endpoints tagged workflow definitions 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/definitions/list | List saved workflows |
| GET | /v1/workflows/definitions/info | Read a saved workflow and one version |
| GET | /v1/workflows/definitions/usages | List the workflows that call this one |
| POST | /v1/workflows/definitions/new | Save a workflow definition |
| POST | /v1/workflows/definitions/versions/new | Add a version to a saved workflow |
| GET | /v1/workflows/definitions/compare | Compare two versions of a saved workflow |
| POST | /v1/workflows/definitions/versions/restore | Restore an earlier version of a saved workflow |
| POST | /v1/workflows/definitions/halt | Stop or allow new runs of a saved workflow |
| POST | /v1/workflows/definitions/delete | Delete a saved workflow and all its versions |
| POST | /v1/workflows/definitions/run | Run a version of a saved workflow |
| GET | /v1/workflows/variables/list | List an organization's workflow variables |
| POST | /v1/workflows/variables/set | Create or replace a workflow variable |
| POST | /v1/workflows/variables/delete | Delete a workflow variable |
Endpoints
GET /v1/workflows/definitions/list
List saved workflows
The saved workflow definitions the caller may see: their own, their teams' and their organization's. Docs (https://docs.spanway.ai/docs/proxy/workflow_definitions)
Example request:
curl -X GET "http://localhost:4000/v1/workflows/definitions/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json DefinitionPage |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
definitions | array of DefinitionView | Yes | Definitions |
GET /v1/workflows/definitions/info
Read a saved workflow and one version
A definition with one version (the latest by default), its contracts and their generated JSON Schemas.
Use it to see exactly what a saved workflow will do before you run it, or to build a form from its input schema. Anyone who can see the definition (its owner, its team or its organization, depending on its visibility) may read it. Nothing is changed. An id you cannot see, or a version that does not exist, answers 404.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
workflow_id | query | string | Yes | |
version | query | integer or null | No |
Example request:
curl -X GET "http://localhost:4000/v1/workflows/definitions/info?workflow_id=workflow_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json DefinitionInfo |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | No object with that id is visible to the caller | 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 |
|---|---|---|---|
definition | DefinitionView | Yes | |
version | VersionView | Yes |
GET /v1/workflows/definitions/usages
List the workflows that call this one
Every saved workflow version with a step that runs this definition, plus a count of callers the caller may not see. Docs (https://docs.spanway.ai/docs/proxy/workflow_definitions#call-a-definition-from-a-step)
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
workflow_id | query | string | Yes |
Example request:
curl -X GET "http://localhost:4000/v1/workflows/definitions/usages?workflow_id=workflow_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json Usages |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | No object with that id is visible to the caller | 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 |
|---|---|---|---|
workflow_id | string | Yes | Workflow Id |
visible | array of Usage | Yes | Visible |
hidden_count | integer or null | Yes | Hidden Count |
POST /v1/workflows/definitions/new
Save a workflow definition
Save a workflow definition with its first version.
A definition is a named, reusable plan of agent steps with an input and output contract, so people can run the same workflow again without writing the steps each time. Anyone whose role may change workflows can save one, as private, for a team they belong to, or for their organization. The new definition is recorded in the audit log. A plan or contract that does not validate, or a step that calls a workflow fewer people can see, answers 422.
Request body (application/json, schema DefinitionCreate):
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | A short name people will recognise |
description | string | No | What the workflow does |
visibility | enum: "private", "team", "org" | No | Who may see and run it: private, team or org |
owner_team_id | string or null | No | The owning team, for team visibility |
version | VersionSpec | Yes | The first version: its plan and its input and output contracts |
Example request:
curl -X POST "http://localhost:4000/v1/workflows/definitions/new" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "incident-summary",
"description": "Summarise the last week of incidents for one service",
"visibility": "team",
"owner_team_id": "team-platform",
"version": {
"plan": {
"mode": "sequential",
"run_budget_usd": 2,
"steps": [
{
"key": "research",
"target": {
"kind": "a2a_agent",
"agent_id": "research-agent"
},
"message": "List the incidents for {{input.service}} in the last week",
"budget_usd": 1
},
{
"key": "write",
"target": {
"kind": "custom_agent",
"custom_agent_id": "writer-agent"
},
"message": "Write a short summary of: {{steps.research.output}}",
"budget_usd": 0.5
}
]
},
"input_contract": {
"fields": [
{
"name": "service",
"type": "string",
"max_chars": 100
}
]
},
"output_contract": {
"fields": [
{
"name": "summary",
"type": "string"
}
]
},
"outputs": {
"summary": "{{steps.write.output}}"
}
}
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json DefinitionInfo |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 409 | The object already exists or is in a state that does not allow this change | application/json ErrorDetail |
| 422 | A field failed validation and the detail names it | application/json ErrorDetail |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
definition | DefinitionView | Yes | |
version | VersionView | Yes |
POST /v1/workflows/definitions/versions/new
Add a version to a saved workflow
Append an immutable version. Sending the latest version's content again returns it unchanged.
Use it to change a saved workflow without breaking runs and callers that use an older version, because every version stays as it was. The definition's owner, an admin of its team or a proxy admin may add a version, and a new version is recorded in the audit log. An unknown id answers 404 and an invalid plan 422.
Request body (application/json, schema VersionCreate):
| Field | Type | Required | Description |
|---|---|---|---|
workflow_id | string | Yes | Workflow Id |
version | VersionSpec | Yes |
Example request:
curl -X POST "http://localhost:4000/v1/workflows/definitions/versions/new" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"workflow_id": "wf_01J...",
"version": {
"plan": {
"mode": "sequential",
"run_budget_usd": 2,
"steps": [
{
"key": "research",
"target": {
"kind": "a2a_agent",
"agent_id": "research-agent"
},
"message": "List the incidents for {{input.service}} in the last week",
"budget_usd": 1
},
{
"key": "write",
"target": {
"kind": "custom_agent",
"custom_agent_id": "writer-agent"
},
"message": "Write a short summary of: {{steps.research.output}}",
"budget_usd": 0.5
}
]
},
"input_contract": {
"fields": [
{
"name": "service",
"type": "string",
"max_chars": 100
}
]
},
"output_contract": {
"fields": [
{
"name": "summary",
"type": "string"
}
]
},
"outputs": {
"summary": "{{steps.write.output}}"
}
}
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json DefinitionInfo |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | No object with that id is visible to the caller | application/json ErrorDetail |
| 422 | A field failed validation and the detail names it | application/json ErrorDetail |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
definition | DefinitionView | Yes | |
version | VersionView | Yes |
GET /v1/workflows/definitions/compare
Compare two versions of a saved workflow
List what changed between two versions of a saved workflow: each added, removed or changed setting, step,
prompt or contract field with its old and new value. Steps are matched by their key and contract fields by
their name, so a step added in the middle shows as one change. Anyone who can see the definition may compare
its versions, and nothing changes.
Docs (https://docs.spanway.ai/docs/proxy/workflow_definitions#compare-and-restore-versions)
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
workflow_id | query | string | Yes | |
from_version | query | integer | Yes | |
to_version | query | integer | Yes |
Example request:
curl -X GET "http://localhost:4000/v1/workflows/definitions/compare?workflow_id=workflow_id-123&from_version=1&to_version=1" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | What changed between the two versions | application/json VersionComparison |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | No object with that id is visible to the caller | 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 |
|---|---|---|---|
workflow_id | string | Yes | Workflow Id |
from_version | integer | Yes | From Version |
to_version | integer | Yes | To Version |
from_content_hash | string | Yes | From Content Hash |
to_content_hash | string | Yes | To Content Hash |
identical | boolean | Yes | Identical |
changes | array of VersionChange | Yes | Changes |
POST /v1/workflows/definitions/versions/restore
Restore an earlier version of a saved workflow
Make an earlier version the latest again by saving its content as a new version. Nothing is deleted, so
runs and triggers pinned to any version keep working, and the content is checked again as if saved today. The
same people who may add a version may restore one, and the restore is written to the audit log with the
version it came from. Restoring content equal to the latest version returns it unchanged.
Docs (https://docs.spanway.ai/docs/proxy/workflow_definitions#compare-and-restore-versions)
Request body (application/json, schema RestoreVersion):
| Field | Type | Required | Description |
|---|---|---|---|
workflow_id | string | Yes | Workflow Id |
version | integer | Yes | The earlier version whose content becomes the new latest version |
Example request:
curl -X POST "http://localhost:4000/v1/workflows/definitions/versions/restore" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"workflow_id": "wf_01J...",
"version": 1
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The new latest version, a copy of the restored one | application/json DefinitionInfo |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | No object with that id is visible to the caller | application/json ErrorDetail |
| 409 | The object already exists or is in a state that does not allow this change | application/json ErrorDetail |
| 422 | A field failed validation and the detail names it | application/json ErrorDetail |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
definition | DefinitionView | Yes | |
version | VersionView | Yes |
POST /v1/workflows/definitions/halt
Stop or allow new runs of a saved workflow
Stop (or allow again) new runs of every version of a definition. Proxy admins only.
Use it as an emergency brake when a saved workflow misbehaves: with halted true, new runs of any version are
refused with 409 until a proxy admin sends halted false. Runs already going are not stopped. Every change is
recorded in the audit log as blocked or unblocked.
Request body (application/json, schema HaltRequest):
| Field | Type | Required | Description |
|---|---|---|---|
workflow_id | string | Yes | Workflow Id |
halted | boolean | Yes | True stops new runs, false allows them again |
Example request:
curl -X POST "http://localhost:4000/v1/workflows/definitions/halt" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"workflow_id": "wf_01J...",
"halted": true
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json DefinitionView |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | No object with that id is visible to the caller | 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 |
|---|---|---|---|
workflow_id | string | Yes | Workflow Id |
name | string | Yes | Name |
description | string | Yes | Description |
visibility | enum: "private", "team", "org" | Yes | Visibility |
owner_user_id | string or null | Yes | Owner User Id |
owner_team_id | string or null | Yes | Owner Team Id |
owner_organization_id | string or null | Yes | Owner Organization Id |
latest_version | integer | Yes | Latest Version |
halted_at | string or null | Yes | Halted At |
created_at | string | Yes | Created At |
updated_at | string | Yes | Updated At |
POST /v1/workflows/definitions/delete
Delete a saved workflow and all its versions
Hard delete a definition and all its versions. Proxy admins only, and only while no other definition pins it.
The deletion cannot be undone. Triggers that start this definition are turned off, and the deletion is recorded in the audit log with the number of versions and the triggers it disabled. A definition another saved workflow still calls answers 409, so remove that step first.
Request body (application/json, schema DeleteRequest):
| Field | Type | Required | Description |
|---|---|---|---|
workflow_id | string | Yes | Workflow Id |
Example request:
curl -X POST "http://localhost:4000/v1/workflows/definitions/delete" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"workflow_id": "wf_01J..."
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json Deleted |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | No object with that id is visible to the caller | application/json ErrorDetail |
| 409 | The object already exists or is in a state that does not allow this change | 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 |
|---|---|---|---|
workflow_id | string | Yes | Workflow Id |
deleted | boolean | Yes | Deleted |
POST /v1/workflows/definitions/run
Run a version of a saved workflow
Start a runner run from a pinned definition version, with its input checked against the input contract.
Use it to run a saved workflow with fresh input, for example a service name for an incident summary. Anyone
whose role may change workflows and who can see the definition may run it. The run is billed to the
calling virtual key, an Admin UI session names the key to use in run_as_key, and the master key cannot
start runs. Send an Idempotency-Key header to make retries safe: the same key returns
the run already started with the Idempotent-Replayed: true header. Input that breaks the contract answers
422, a halted definition 409, and a busy runner 429 or 503.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
Idempotency-Key | header | string or null | No |
Request body (application/json, schema RunDefinitionRequest):
| Field | Type | Required | Description |
|---|---|---|---|
workflow_id | string | Yes | Workflow Id |
version | integer | Yes | The saved version to run |
input | object | No | Values for the input contract |
run_budget_usd | number or null | No | A spend cap for this run, in US dollars |
run_as_key | string or null | No | The virtual key a dashboard session runs as, a virtual key runs as itself |
Example request:
curl -X POST "http://localhost:4000/v1/workflows/definitions/run" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"workflow_id": "wf_01J...",
"version": 1,
"input": {
"service": "checkout"
}
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json RunWithSteps |
| 400 | The request is malformed or breaks a rule named in the detail | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | No object with that id is visible to the caller | application/json ErrorDetail |
| 409 | The object already exists or is in a state that does not allow this change | application/json ErrorDetail |
| 422 | A field failed validation and the detail names it | application/json ErrorDetail |
| 429 | A rate or concurrency limit was reached, retry after Retry-After seconds | application/json ErrorDetail |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
| 503 | A dependency such as Lens, the queue or the database is unavailable | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
run | RunView | Yes | |
steps | array of StepView | Yes | Steps |
GET /v1/workflows/variables/list
List an organization's workflow variables
The organization's workflow variables. Steps of its definitions read them as {{vars.<name>}}.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
organization_id | query | string | Yes |
Example request:
curl -X GET "http://localhost:4000/v1/workflows/variables/list?organization_id=organization_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json VariablePage |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | You are not a member of this organization | 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 |
|---|---|---|---|
variables | array of VariableView | Yes | Variables |
POST /v1/workflows/variables/set
Create or replace a workflow variable
Create or replace one non-secret variable. Values that look like keys or tokens are refused.
Request body (application/json, schema VariableSet):
| Field | Type | Required | Description |
|---|---|---|---|
organization_id | string | Yes | Organization Id |
name | string | Yes | Name |
value | string | Yes | Value |
Example request:
curl -X POST "http://localhost:4000/v1/workflows/variables/set" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"organization_id": "org_01J...",
"name": "support_region",
"value": "eu-west"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json VariableView |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | Only a proxy admin or an admin of this organization can do this | application/json ErrorDetail |
| 409 | An organization can hold at most 200 variables | application/json ErrorDetail |
| 422 | A field failed validation and the detail names it | application/json ErrorDetail |
| 500 | The gateway hit an internal error, usually the database is not connected | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
organization_id | string | Yes | Organization Id |
name | string | Yes | Name |
value | string | Yes | Value |
updated_at | string | Yes | Updated At |
POST /v1/workflows/variables/delete
Delete a workflow variable
Remove one variable. Runs that already started keep the value they were given.
Request body (application/json, schema VariableDelete):
| Field | Type | Required | Description |
|---|---|---|---|
organization_id | string | Yes | Organization Id |
name | string | Yes | Name |
Example request:
curl -X POST "http://localhost:4000/v1/workflows/variables/delete" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"organization_id": "org_01J...",
"name": "support_region"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json VariableDelete |
| 401 | No valid key or Admin UI session was presented | application/json ErrorDetail |
| 403 | Only a proxy admin or an admin of this organization can do this | application/json ErrorDetail |
| 404 | Variable support_region is not set | 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 |
|---|---|---|---|
organization_id | string | Yes | Organization Id |
name | string | Yes | Name |