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.
| Method | Path | Summary |
|---|---|---|
| GET | /v1/environments/info | Read this environment |
| GET | /v1/environments/plans/list | List plans |
| GET | /v1/environments/plans/info | Read one plan |
| GET | /v1/environments/managed/list | List the objects applies wrote |
| POST | /v1/environments/export | Export the scope's config as a bundle |
| POST | /v1/environments/plan | Plan a bundle against this environment |
| POST | /v1/environments/plans/approve | Approve a plan |
| POST | /v1/environments/plans/reject | Reject a plan |
| POST | /v1/environments/plans/apply | Apply 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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
organization_id | query | string or null | No |
Example request:
curl -X GET "http://localhost:4000/v1/environments/info" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json EnvironmentInfo |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | Organization org-platform not found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | DB 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_keys | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
environment_name | string or null | Yes | Environment Name |
scope_key | string | Yes | Scope Key |
require_approval | boolean | Yes | Require Approval |
plan_ttl_minutes | integer | Yes | Plan Ttl Minutes |
kinds | array of enum: "Toolset", "Policy", "RoutingPreset", "RouterSettings", "CustomAgent", "WorkflowDefinition", "ApprovalPolicy" | Yes | Kinds |
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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
organization_id | query | string or null | No |
Example request:
curl -X GET "http://localhost:4000/v1/environments/plans/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json PlanPage |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | Organization org-platform not found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | DB 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_keys | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
plans | array of PlanSummary | Yes | Plans |
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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
plan_id | query | string | Yes | |
organization_id | query | string or null | No |
Example request:
curl -X GET "http://localhost:4000/v1/environments/plans/info?plan_id=plan_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json PlanView |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 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 | DB 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_keys | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
summary | PlanSummary | Yes | |
changes | array of ObjectChange | Yes | Changes |
secret_refs | array of SecretRefStatus | No | Secret Refs |
result | array of ObjectResult | No | Result |
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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
organization_id | query | string or null | No |
Example request:
curl -X GET "http://localhost:4000/v1/environments/managed/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json ManagedPage |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | Organization org-platform not found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | DB 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_keys | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
objects | array of ManagedView | Yes | Objects |
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):
| Field | Type | Required | Description |
|---|---|---|---|
kinds | array of enum: "Toolset", "Policy", "RoutingPreset", "RouterSettings", "CustomAgent", "WorkflowDefinition", "ApprovalPolicy" or null | No | Kinds |
organization_id | string or null | No | Organization 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:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json ExportView |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | Organization org-platform not found | application/json ErrorDetail |
| 422 | A field failed validation and the detail names it | application/json ErrorDetail |
| 500 | DB 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_keys | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
export_id | string | Yes | Export Id |
bundle | Bundle | Yes |
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):
| Field | Type | Required | Description |
|---|---|---|---|
bundle | Bundle | Yes | |
target_environment | string | Yes | Target Environment |
prune | boolean | No | Prune |
organization_id | string or null | No | Organization Id |
source | PlanSource | No |
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:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json PlanView |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key's role, grants or license do not allow this action | application/json ErrorDetail |
| 404 | Organization org-platform not found | application/json ErrorDetail |
| 409 | The object already exists or is in a state that does not allow this change | application/json ErrorDetail |
| 413 | A bundle may be at most 2097152 bytes | application/json ErrorDetail |
| 422 | The bundle holds secrets or references this scope may not use | application/json ErrorDetail |
| 500 | DB 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_keys | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
summary | PlanSummary | Yes | |
changes | array of ObjectChange | Yes | Changes |
secret_refs | array of SecretRefStatus | No | Secret Refs |
result | array of ObjectResult | No | Result |
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):
| Field | Type | Required | Description |
|---|---|---|---|
plan_id | string | Yes | Plan Id |
organization_id | string or null | No | Organization Id |
note | string or null | No | Note |
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:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json PlanView |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 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 | DB 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_keys | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
summary | PlanSummary | Yes | |
changes | array of ObjectChange | Yes | Changes |
secret_refs | array of SecretRefStatus | No | Secret Refs |
result | array of ObjectResult | No | Result |
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):
| Field | Type | Required | Description |
|---|---|---|---|
plan_id | string | Yes | Plan Id |
organization_id | string or null | No | Organization Id |
note | string or null | No | Note |
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:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json PlanView |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 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 | DB 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_keys | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
summary | PlanSummary | Yes | |
changes | array of ObjectChange | Yes | Changes |
secret_refs | array of SecretRefStatus | No | Secret Refs |
result | array of ObjectResult | No | Result |
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):
| Field | Type | Required | Description |
|---|---|---|---|
plan_id | string | Yes | Plan Id |
organization_id | string or null | No | Organization 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:
| Status | Description | Body |
|---|---|---|
| 200 | Successful response | application/json PlanView |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 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 | DB 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_keys | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
summary | PlanSummary | Yes | |
changes | array of ObjectChange | Yes | Changes |
secret_refs | array of SecretRefStatus | No | Secret Refs |
result | array of ObjectResult | No | Result |