Skip to main content

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.

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

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:

StatusDescriptionBody
200Successful responseapplication/json DefinitionPage
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
definitionsarray of DefinitionViewYesDefinitions

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:

NameInTypeRequiredDescription
workflow_idquerystringYes
versionqueryinteger or nullNo

Example request:

curl -X GET "http://localhost:4000/v1/workflows/definitions/info?workflow_id=workflow_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful responseapplication/json DefinitionInfo
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404No object with that id is visible to the callerapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
definitionDefinitionViewYes
versionVersionViewYes

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:

NameInTypeRequiredDescription
workflow_idquerystringYes

Example request:

curl -X GET "http://localhost:4000/v1/workflows/definitions/usages?workflow_id=workflow_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful responseapplication/json Usages
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404No object with that id is visible to the callerapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
workflow_idstringYesWorkflow Id
visiblearray of UsageYesVisible
hidden_countinteger or nullYesHidden 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):

FieldTypeRequiredDescription
namestringYesA short name people will recognise
descriptionstringNoWhat the workflow does
visibilityenum: "private", "team", "org"NoWho may see and run it: private, team or org
owner_team_idstring or nullNoThe owning team, for team visibility
versionVersionSpecYesThe 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:

StatusDescriptionBody
200Successful responseapplication/json DefinitionInfo
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
409The object already exists or is in a state that does not allow this changeapplication/json ErrorDetail
422A field failed validation and the detail names itapplication/json ErrorDetail
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
definitionDefinitionViewYes
versionVersionViewYes

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):

FieldTypeRequiredDescription
workflow_idstringYesWorkflow Id
versionVersionSpecYes

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:

StatusDescriptionBody
200Successful responseapplication/json DefinitionInfo
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404No object with that id is visible to the callerapplication/json ErrorDetail
422A field failed validation and the detail names itapplication/json ErrorDetail
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
definitionDefinitionViewYes
versionVersionViewYes

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:

NameInTypeRequiredDescription
workflow_idquerystringYes
from_versionqueryintegerYes
to_versionqueryintegerYes

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:

StatusDescriptionBody
200What changed between the two versionsapplication/json VersionComparison
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404No object with that id is visible to the callerapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
workflow_idstringYesWorkflow Id
from_versionintegerYesFrom Version
to_versionintegerYesTo Version
from_content_hashstringYesFrom Content Hash
to_content_hashstringYesTo Content Hash
identicalbooleanYesIdentical
changesarray of VersionChangeYesChanges

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):

FieldTypeRequiredDescription
workflow_idstringYesWorkflow Id
versionintegerYesThe 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:

StatusDescriptionBody
200The new latest version, a copy of the restored oneapplication/json DefinitionInfo
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404No object with that id is visible to the callerapplication/json ErrorDetail
409The object already exists or is in a state that does not allow this changeapplication/json ErrorDetail
422A field failed validation and the detail names itapplication/json ErrorDetail
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
definitionDefinitionViewYes
versionVersionViewYes

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):

FieldTypeRequiredDescription
workflow_idstringYesWorkflow Id
haltedbooleanYesTrue 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:

StatusDescriptionBody
200Successful responseapplication/json DefinitionView
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404No object with that id is visible to the callerapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
workflow_idstringYesWorkflow Id
namestringYesName
descriptionstringYesDescription
visibilityenum: "private", "team", "org"YesVisibility
owner_user_idstring or nullYesOwner User Id
owner_team_idstring or nullYesOwner Team Id
owner_organization_idstring or nullYesOwner Organization Id
latest_versionintegerYesLatest Version
halted_atstring or nullYesHalted At
created_atstringYesCreated At
updated_atstringYesUpdated 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):

FieldTypeRequiredDescription
workflow_idstringYesWorkflow 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:

StatusDescriptionBody
200Successful responseapplication/json Deleted
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404No object with that id is visible to the callerapplication/json ErrorDetail
409The object already exists or is in a state that does not allow this changeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
workflow_idstringYesWorkflow Id
deletedbooleanYesDeleted

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:

NameInTypeRequiredDescription
Idempotency-Keyheaderstring or nullNo

Request body (application/json, schema RunDefinitionRequest):

FieldTypeRequiredDescription
workflow_idstringYesWorkflow Id
versionintegerYesThe saved version to run
inputobjectNoValues for the input contract
run_budget_usdnumber or nullNoA spend cap for this run, in US dollars
run_as_keystring or nullNoThe 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:

StatusDescriptionBody
200Successful responseapplication/json RunWithSteps
400The request is malformed or breaks a rule named in the detailapplication/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404No object with that id is visible to the callerapplication/json ErrorDetail
409The object already exists or is in a state that does not allow this changeapplication/json ErrorDetail
422A field failed validation and the detail names itapplication/json ErrorDetail
429A rate or concurrency limit was reached, retry after Retry-After secondsapplication/json ErrorDetail
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail
503A dependency such as Lens, the queue or the database is unavailableapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
runRunViewYes
stepsarray of StepViewYesSteps

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:

NameInTypeRequiredDescription
organization_idquerystringYes

Example request:

curl -X GET "http://localhost:4000/v1/workflows/variables/list?organization_id=organization_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful responseapplication/json VariablePage
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403You are not a member of this organizationapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
variablesarray of VariableViewYesVariables

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):

FieldTypeRequiredDescription
organization_idstringYesOrganization Id
namestringYesName
valuestringYesValue

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:

StatusDescriptionBody
200Successful responseapplication/json VariableView
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403Only a proxy admin or an admin of this organization can do thisapplication/json ErrorDetail
409An organization can hold at most 200 variablesapplication/json ErrorDetail
422A field failed validation and the detail names itapplication/json ErrorDetail
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
organization_idstringYesOrganization Id
namestringYesName
valuestringYesValue
updated_atstringYesUpdated 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):

FieldTypeRequiredDescription
organization_idstringYesOrganization Id
namestringYesName

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:

StatusDescriptionBody
200Successful responseapplication/json VariableDelete
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403Only a proxy admin or an admin of this organization can do thisapplication/json ErrorDetail
404Variable support_region is not setapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
organization_idstringYesOrganization Id
namestringYesName