Skip to main content

Environments API

This page documents the 9 gateway endpoints tagged environments 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/environments/infoRead this environment
GET/v1/environments/plans/listList plans
GET/v1/environments/plans/infoRead one plan
GET/v1/environments/managed/listList the objects applies wrote
POST/v1/environments/exportExport the scope's config as a bundle
POST/v1/environments/planPlan a bundle against this environment
POST/v1/environments/plans/approveApprove a plan
POST/v1/environments/plans/rejectReject a plan
POST/v1/environments/plans/applyApply an approved plan

Endpoints​

GET /v1/environments/info​

Read this environment

Shows which environment this gateway is (for example prod), the scope a plan would use, whether plans need a second person to approve them, how long a plan stays valid and the kinds of config the scope can promote. Proxy admins and admin viewers read the gateway scope; organization admins pass organization_id to read their own. Nothing changes.

Parameters:

NameInTypeRequiredDescription
organization_idquerystring or nullNo

Example request:

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

Responses:

StatusDescriptionBody
200Successful responseapplication/json EnvironmentInfo
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404Organization org-platform not foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keysapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
environment_namestring or nullYesEnvironment Name
scope_keystringYesScope Key
require_approvalbooleanYesRequire Approval
plan_ttl_minutesintegerYesPlan Ttl Minutes
kindsarray of enum: "Toolset", "Policy", "RoutingPreset", "RouterSettings", "CustomAgent", "WorkflowDefinition", "ApprovalPolicy"YesKinds

GET /v1/environments/plans/list​

List plans

Lists the latest promotion plans of the caller's scope, newest first, with each plan's status, change counts, who made and approved it and when it expires. Any admin can read the gateway scope; organization admins pass organization_id. Nothing changes.

Parameters:

NameInTypeRequiredDescription
organization_idquerystring or nullNo

Example request:

curl -X GET "http://localhost:4000/v1/environments/plans/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful responseapplication/json PlanPage
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404Organization org-platform not foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keysapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
plansarray of PlanSummaryYesPlans

GET /v1/environments/plans/info​

Read one plan

Shows one promotion plan in full: every object it would create, update or delete, any problems that block it, whether each secret reference resolves on this gateway and, once applied, what happened to each object. Readable by the same admins who can list plans. Nothing changes.

Parameters:

NameInTypeRequiredDescription
plan_idquerystringYes
organization_idquerystring or nullNo

Example request:

curl -X GET "http://localhost:4000/v1/environments/plans/info?plan_id=plan_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful responseapplication/json PlanView
401No valid key or Admin UI session was presentedapplication/json ProxyError
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
500DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keysapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
summaryPlanSummaryYes
changesarray of ObjectChangeYesChanges
secret_refsarray of SecretRefStatusNoSecret Refs
resultarray of ObjectResultNoResult

GET /v1/environments/managed/list​

List the objects applies wrote

Lists the objects that a plan apply created or last wrote in the caller's scope, and whether someone changed them by hand since (drift) or deleted them. Readable by the same admins who can list plans. Nothing changes.

Parameters:

NameInTypeRequiredDescription
organization_idquerystring or nullNo

Example request:

curl -X GET "http://localhost:4000/v1/environments/managed/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful responseapplication/json ManagedPage
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404Organization org-platform not foundapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keysapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
objectsarray of ManagedViewYesObjects

POST /v1/environments/export​

Export the scope's config as a bundle

Exports the scope's promotable config (agents, workflows, policies and the other listed kinds) as a portable bundle with no ids, owners or secrets, ready to commit to a repository and plan on another environment. The export fails with the JSON path of every object that holds an inline secret or a reference with no portable name. Proxy admins export the gateway scope and organization admins their organization. Each export is recorded.

Request body (application/json, schema ExportRequest):

FieldTypeRequiredDescription
kindsarray of enum: "Toolset", "Policy", "RoutingPreset", "RouterSettings", "CustomAgent", "WorkflowDefinition", "ApprovalPolicy" or nullNoKinds
organization_idstring or nullNoOrganization Id

Example request:

curl -X POST "http://localhost:4000/v1/environments/export" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"kinds": [
"CustomAgent",
"WorkflowDefinition",
"ApprovalPolicy"
]
}'

Responses:

StatusDescriptionBody
200Successful responseapplication/json ExportView
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404Organization org-platform not foundapplication/json ErrorDetail
422A field failed validation and the detail names itapplication/json ErrorDetail
500DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keysapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
export_idstringYesExport Id
bundleBundleYes

POST /v1/environments/plan​

Plan a bundle against this environment

Compares a bundle with this environment and stores the result as a plan, without changing any config. target_environment must name this environment, so a bundle meant for staging is never planned on prod. The plan expires after the configured time and replaces older open plans of the same scope. Proxy admins plan the gateway scope and organization admins their organization; read-only roles are refused.

Request body (application/json, schema PlanRequest):

FieldTypeRequiredDescription
bundleBundleYes
target_environmentstringYesTarget Environment
prunebooleanNoPrune
organization_idstring or nullNoOrganization Id
sourcePlanSourceNo

Example request:

curl -X POST "http://localhost:4000/v1/environments/plan" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"bundle": {
"manifest": {
"api_version": "spanway.ai/env/v1",
"kinds": [
"CustomAgent"
]
},
"objects": [
{
"api_version": "spanway.ai/env/v1",
"kind": "CustomAgent",
"name": "release-notes-writer",
"spec": {
"display_name": "Release notes writer",
"model": "claude-sonnet-5-5",
"instructions": "Write short release notes grouped by area.",
"visibility": "team",
"owner_team": "team-platform"
}
}
]
},
"target_environment": "prod",
"prune": false,
"source": {
"commit": "9f3c...",
"ref": "origin/main",
"path": "spanway/bundle.json"
}
}'

Responses:

StatusDescriptionBody
200Successful responseapplication/json PlanView
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
404Organization org-platform not foundapplication/json ErrorDetail
409The object already exists or is in a state that does not allow this changeapplication/json ErrorDetail
413A bundle may be at most 2097152 bytesapplication/json ErrorDetail
422The bundle holds secrets or references this scope may not useapplication/json ErrorDetail
500DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keysapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
summaryPlanSummaryYes
changesarray of ObjectChangeYesChanges
secret_refsarray of SecretRefStatusNoSecret Refs
resultarray of ObjectResultNoResult

POST /v1/environments/plans/approve​

Approve a plan

Approves a plan so it can be applied. The approver must be a person signed in with their own key, never the master key, and never the person who made the plan. Only the plan's status, approver and note change.

Request body (application/json, schema PlanDecision):

FieldTypeRequiredDescription
plan_idstringYesPlan Id
organization_idstring or nullNoOrganization Id
notestring or nullNoNote

Example request:

curl -X POST "http://localhost:4000/v1/environments/plans/approve" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"plan_id": "6f1c0e2a-9b7d-4c3e-8a21-5d4f3b2a1c09",
"note": "Reviewed in PR 42"
}'

Responses:

StatusDescriptionBody
200Successful responseapplication/json PlanView
401No valid key or Admin UI session was presentedapplication/json ProxyError
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
500DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keysapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
summaryPlanSummaryYes
changesarray of ObjectChangeYesChanges
secret_refsarray of SecretRefStatusNoSecret Refs
resultarray of ObjectResultNoResult

POST /v1/environments/plans/reject​

Reject a plan

Rejects a plan so it can never be applied, with an optional note saying why. The same admins who can approve a plan can reject it. Only the plan's status, decider and note change; no config is touched.

Request body (application/json, schema PlanDecision):

FieldTypeRequiredDescription
plan_idstringYesPlan Id
organization_idstring or nullNoOrganization Id
notestring or nullNoNote

Example request:

curl -X POST "http://localhost:4000/v1/environments/plans/reject" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"plan_id": "6f1c0e2a-9b7d-4c3e-8a21-5d4f3b2a1c09",
"note": "Wrong model for production"
}'

Responses:

StatusDescriptionBody
200Successful responseapplication/json PlanView
401No valid key or Admin UI session was presentedapplication/json ProxyError
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
500DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keysapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
summaryPlanSummaryYes
changesarray of ObjectChangeYesChanges
secret_refsarray of SecretRefStatusNoSecret Refs
resultarray of ObjectResultNoResult

POST /v1/environments/plans/apply​

Apply an approved plan

Writes exactly the planned bundle to this environment, each object through its feature's own write path, so the same checks and audit rows apply as for a change made by hand. Refused when the plan still needs approval, has expired, has problems or the environment changed since the plan was made. The first failing object stops the apply. Proxy admins apply gateway plans and organization admins their organization's plans.

Request body (application/json, schema PlanRef):

FieldTypeRequiredDescription
plan_idstringYesPlan Id
organization_idstring or nullNoOrganization Id

Example request:

curl -X POST "http://localhost:4000/v1/environments/plans/apply" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"plan_id": "6f1c0e2a-9b7d-4c3e-8a21-5d4f3b2a1c09"
}'

Responses:

StatusDescriptionBody
200Successful responseapplication/json PlanView
401No valid key or Admin UI session was presentedapplication/json ProxyError
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
500DB not connected. This endpoint needs a database; set DATABASE_URL to a PostgreSQL connection string (postgresql://...) to enable it. See https://docs.spanway.ai/docs/proxy/virtual_keysapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
summaryPlanSummaryYes
changesarray of ObjectChangeYesChanges
secret_refsarray of SecretRefStatusNoSecret Refs
resultarray of ObjectResultNoResult