Skip to main content

Policy engine API

This page documents the 20 gateway endpoints tagged policy_engine 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
POST/policiesCreate a policy
POST/policies/attachmentsAttach a policy to teams, keys, models or tags
POST/policies/attachments/estimate-impactEstimate how many keys and teams an attachment would reach
GET/policies/attachments/listList policy attachments
GET/policies/attachments/{attachment_id}Read one policy attachment
DELETE/policies/attachments/{attachment_id}Delete a policy attachment
PUT/policies/attachments/{attachment_id}/modeSwitch an attachment between enforce and audit
GET/policies/compareCompare two policy versions
GET/policies/listList policies and their versions
DELETE/policies/name/{policy_name}/all-versionsDelete every version of a policy
GET/policies/name/{policy_name}/versionsList the versions of a policy
POST/policies/name/{policy_name}/versionsCreate a draft version of a policy
POST/policies/resolveSimulate which policies and guardrails a request would get
POST/policies/simulateReplay recent traffic through a policy
POST/policies/test-pipelineRun a guardrail pipeline on sample messages
GET/policies/{policy_id}Read one policy version
PUT/policies/{policy_id}Change a draft policy version
DELETE/policies/{policy_id}Delete one policy version
GET/policies/{policy_id}/resolved-guardrailsList the guardrails a policy resolves to
PUT/policies/{policy_id}/statusPublish or promote a policy version

Endpoints​

POST /policies​

Create a policy

Create a policy as version 1 in production, so it applies wherever it is attached right away. inherit names a parent whose guardrails are taken over, guardrails_add and guardrails_remove adjust them, condition.model limits the policy to models matching a regular expression, and pipeline runs the guardrails in a fixed order with an action per outcome. Proxy admins only. The change is written to the audit log.

Example Request:

curl -X POST "http://localhost:4000/policies" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"policy_name": "global-baseline",
"description": "Base guardrails for all requests",
"guardrails_add": ["pii_masking", "prompt_injection"],
"guardrails_remove": []
}'

Example Response:

{
"policy_id": "123e4567-e89b-12d3-a456-426614174000",
"policy_name": "global-baseline",
"inherit": null,
"description": "Base guardrails for all requests",
"guardrails_add": ["pii_masking", "prompt_injection"],
"guardrails_remove": [],
"condition": null,
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
}

Request body (application/json, schema PolicyCreateRequest):

FieldTypeRequiredDescription
conditionPolicyConditionRequest or nullNoCondition for when this policy applies.
descriptionstring or nullNoHuman-readable description of the policy.
guardrails_addarray of string or nullNoList of guardrail names to add.
guardrails_removearray of string or nullNoList of guardrail names to remove (from inherited).
inheritstring or nullNoName of parent policy to inherit from.
pipelineobject or nullNoOptional guardrail pipeline for ordered execution. Contains 'mode' and 'steps'.
policy_namestringYesUnique name for the policy.

Example request:

curl -X POST "http://localhost:4000/policies" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"condition": {
"model": "claude-sonnet-.*"
},
"description": "Extra checks for frontier models",
"guardrails_add": [
"prompt-injection"
],
"inherit": "global-baseline",
"policy_name": "frontier-safety"
}'

Responses:

StatusDescriptionBody
200The policy version as stored.application/json PolicyDBResponse
400A policy with this name exists.application/json ErrorDetail
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
403An admin viewer key tried to change a policy. Admin viewers can only readapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so policies cannot be stored.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
conditionobject or nullNoPolicy condition.
created_atstring or nullNoWhen the policy was created.
created_bystring or nullNoWho created the policy.
definition_locationenum: "db", "config"NoWhere this policy is defined: 'db' (database) or 'config' (config.yaml).
descriptionstring or nullNoPolicy description.
guardrails_addarray of stringNoGuardrails to add.
guardrails_removearray of stringNoGuardrails to remove.
inheritstring or nullNoParent policy name.
is_latestbooleanNoTrue if this is the latest version by version_number.
parent_version_idstring or nullNoPolicy ID this version was cloned from.
pipelineobject or nullNoOptional guardrail pipeline.
policy_idstringYesUnique ID of the policy.
policy_namestringYesName of the policy.
production_atstring or nullNoWhen this version was promoted to production.
published_atstring or nullNoWhen this version was published.
updated_atstring or nullNoWhen the policy was last updated.
updated_bystring or nullNoWho last updated the policy.
version_numberintegerNoVersion number of this policy.
version_statusstringNoOne of: draft, published, production.

POST /policies/attachments​

Attach a policy to teams, keys, models or tags

Make a policy apply to traffic. scope: "*" applies it to every request, otherwise teams, keys, models and tags are combined, so an attachment with teams and models applies only to those models for those teams. priority orders attachments, lower first, and default makes one a fallback that applies only when no other attachment matches. Proxy admins only. The change is written to the audit log.

Example Request:

curl -X POST "http://localhost:4000/policies/attachments" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"policy_name": "global-baseline",
"scope": "*"
}'

Example with team-specific attachment:

curl -X POST "http://localhost:4000/policies/attachments" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"policy_name": "healthcare-compliance",
"teams": ["healthcare-team", "medical-research"]
}'

Example Response:

{
"attachment_id": "123e4567-e89b-12d3-a456-426614174000",
"policy_name": "global-baseline",
"scope": "*",
"teams": [],
"keys": [],
"models": [],
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
}

Request body (application/json, schema PolicyAttachmentCreateRequest):

FieldTypeRequiredDescription
defaultbooleanNoApply this attachment only when no non-default attachment matches the request.
keysarray of string or nullNoKey aliases or patterns this attachment applies to.
modeenum: "enforce", "audit"Noenforce blocks or redacts. audit only records what the guardrails would have done.
modelsarray of string or nullNoModel names or patterns this attachment applies to.
policy_namestringYesName of the policy to attach.
priorityinteger or nullNoExplicit execution order, lower runs first. Prioritised attachments run before those without one.
scopestring or nullNoUse '*' for global scope (applies to all requests).
tagsarray of string or nullNoTag patterns this attachment applies to. Supports wildcards (e.g., health-*).
teamsarray of string or nullNoTeam aliases or patterns this attachment applies to.

Example request:

curl -X POST "http://localhost:4000/policies/attachments" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"models": [
"claude-sonnet-*"
],
"policy_name": "frontier-safety",
"priority": 10,
"teams": [
"research"
]
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json PolicyAttachmentDBResponse
400A team, key alias or model without a wildcard does not exist.application/json ErrorDetail
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
403An admin viewer key tried to change an attachment. Admin viewers can only readapplication/json ErrorDetail
404No policy has this name.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so policies cannot be stored.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
attachment_idstringYesUnique ID of the attachment.
created_atstring or nullNoWhen the attachment was created.
created_bystring or nullNoWho created the attachment.
defaultbooleanNoApply this attachment only when no non-default attachment matches the request.
definition_locationenum: "db", "config"NoWhere this attachment is defined: 'db' (database) or 'config' (config.yaml).
keysarray of stringNoKey patterns.
modeenum: "enforce", "audit"Noenforce blocks or redacts. audit only records what the guardrails would have done.
modelsarray of stringNoModel patterns.
policy_namestringYesName of the attached policy.
priorityinteger or nullNoExplicit execution order, lower runs first. Prioritised attachments run before those without one.
scopestring or nullNoScope of the attachment.
tagsarray of stringNoTag patterns.
teamsarray of stringNoTeam patterns.
updated_atstring or nullNoWhen the attachment was last updated.
updated_bystring or nullNoWho last updated the attachment.

POST /policies/attachments/estimate-impact​

Estimate how many keys and teams an attachment would reach

Count the keys and teams an attachment with this scope would apply to, before you create it, with a sample of their aliases. Team patterns also count the keys of the matched teams, and keys and teams without an alias are counted separately. The Estimate Impact button of the Admin UI calls this route.

Docs (https://docs.spanway.ai/docs/proxy/guardrails/policy_simulation)

Request body (application/json, schema PolicyAttachmentCreateRequest):

FieldTypeRequiredDescription
defaultbooleanNoApply this attachment only when no non-default attachment matches the request.
keysarray of string or nullNoKey aliases or patterns this attachment applies to.
modeenum: "enforce", "audit"Noenforce blocks or redacts. audit only records what the guardrails would have done.
modelsarray of string or nullNoModel names or patterns this attachment applies to.
policy_namestringYesName of the policy to attach.
priorityinteger or nullNoExplicit execution order, lower runs first. Prioritised attachments run before those without one.
scopestring or nullNoUse '*' for global scope (applies to all requests).
tagsarray of string or nullNoTag patterns this attachment applies to. Supports wildcards (e.g., health-*).
teamsarray of string or nullNoTeam aliases or patterns this attachment applies to.

Example request:

curl -X POST "http://localhost:4000/policies/attachments/estimate-impact" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"models": [
"claude-sonnet-*"
],
"policy_name": "frontier-safety",
"teams": [
"research*"
]
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json AttachmentImpactResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so attachments cannot be read.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
affected_keys_countintegerNoNumber of keys that would be affected (named + unnamed).
affected_teams_countintegerNoNumber of teams that would be affected (named + unnamed).
sample_keysarray of stringNoSample of affected key aliases (up to 10).
sample_teamsarray of stringNoSample of affected team aliases (up to 10).
unnamed_keys_countintegerNoNumber of affected keys without an alias.
unnamed_teams_countintegerNoNumber of affected teams without an alias.

GET /policies/attachments/list​

List policy attachments

List every attachment from the database and the config file, each saying which policy applies to which teams, keys, models or tags.

Config-defined attachments are returned with definition_location "config" and a synthetic attachment_id ("config-<index>").

Example Request:

curl -X GET "http://localhost:4000/policies/attachments/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Example Response:

{
"attachments": [
{
"attachment_id": "123e4567-e89b-12d3-a456-426614174000",
"policy_name": "global-baseline",
"scope": "*",
"teams": [],
"keys": [],
"models": [],
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
}
],
"total_count": 1
}

Example request:

curl -X GET "http://localhost:4000/policies/attachments/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json PolicyAttachmentListResponse
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
500The database raised an error.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
attachmentsarray of PolicyAttachmentDBResponseNoList of policy attachments.
total_countintegerNoTotal number of attachments.

GET /policies/attachments/{attachment_id}​

Read one policy attachment

Read one attachment by its attachment_id.

Example Request:

curl -X GET "http://localhost:4000/policies/attachments/123e4567-e89b-12d3-a456-426614174000" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Parameters:

NameInTypeRequiredDescription
attachment_idpathstringYes

Example request:

curl -X GET "http://localhost:4000/policies/attachments/attachment_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json PolicyAttachmentDBResponse
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
404No attachment has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so policies cannot be stored.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
attachment_idstringYesUnique ID of the attachment.
created_atstring or nullNoWhen the attachment was created.
created_bystring or nullNoWho created the attachment.
defaultbooleanNoApply this attachment only when no non-default attachment matches the request.
definition_locationenum: "db", "config"NoWhere this attachment is defined: 'db' (database) or 'config' (config.yaml).
keysarray of stringNoKey patterns.
modeenum: "enforce", "audit"Noenforce blocks or redacts. audit only records what the guardrails would have done.
modelsarray of stringNoModel patterns.
policy_namestringYesName of the attached policy.
priorityinteger or nullNoExplicit execution order, lower runs first. Prioritised attachments run before those without one.
scopestring or nullNoScope of the attachment.
tagsarray of stringNoTag patterns.
teamsarray of stringNoTeam patterns.
updated_atstring or nullNoWhen the attachment was last updated.
updated_bystring or nullNoWho last updated the attachment.

DELETE /policies/attachments/{attachment_id}​

Delete a policy attachment

Remove an attachment so its policy no longer applies to that traffic. The policy and its versions are kept. Proxy admins only. The change is written to the audit log.

Example Request:

curl -X DELETE "http://localhost:4000/policies/attachments/123e4567-e89b-12d3-a456-426614174000" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Example Response:

{
"message": "Attachment 123e4567-e89b-12d3-a456-426614174000 deleted successfully"
}

Parameters:

NameInTypeRequiredDescription
attachment_idpathstringYes

Example request:

curl -X DELETE "http://localhost:4000/policies/attachments/attachment_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The attachment is gone. The policy itself is kept.application/json PolicyDeletedResponse
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
403An admin viewer key tried to change an attachment. Admin viewers can only readapplication/json ErrorDetail
404No attachment has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so policies cannot be stored.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
messagestringYesWhich policy or attachment was deleted.
warningstring or nullNoSet when the deletion changed what the gateway enforces, for example production went.

PUT /policies/attachments/{attachment_id}/mode​

Switch an attachment between enforce and audit

Turn an attachment from audit into enforce, or back. In audit mode the policy's guardrails still run on every matching request but only record what they would have done (each verdict carries audit_policy in the guardrail information of the spend log), so you can watch a new policy on live traffic before it blocks anything. Switch to enforce when the verdicts look right. The change applies to new requests at once and is written to the audit log with the old and new attachment.

Example curl:

curl -X PUT http://0.0.0.0:4000/policies/attachments/123e4567-e89b-12d3-a456-426614174000/mode \
-H "Authorization: Bearer sk-admin" -H "Content-Type: application/json" \
-d '{"mode": "enforce"}'

Parameters:

NameInTypeRequiredDescription
attachment_idpathstringYes

Request body (application/json, schema PolicyAttachmentModeUpdateRequest):

FieldTypeRequiredDescription
modeenum: "enforce", "audit"Yesenforce blocks or redacts. audit only records what the guardrails would have done.

Example request:

curl -X PUT "http://localhost:4000/policies/attachments/attachment_id-123/mode" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"mode": "enforce"
}'

Responses:

StatusDescriptionBody
200The attachment with its new mode.application/json PolicyAttachmentDBResponse
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
403Only proxy admins can change how a policy is enforced.application/json ErrorDetail
404No attachment has this id. Config attachments cannot change.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The gateway has no database.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
attachment_idstringYesUnique ID of the attachment.
created_atstring or nullNoWhen the attachment was created.
created_bystring or nullNoWho created the attachment.
defaultbooleanNoApply this attachment only when no non-default attachment matches the request.
definition_locationenum: "db", "config"NoWhere this attachment is defined: 'db' (database) or 'config' (config.yaml).
keysarray of stringNoKey patterns.
modeenum: "enforce", "audit"Noenforce blocks or redacts. audit only records what the guardrails would have done.
modelsarray of stringNoModel patterns.
policy_namestringYesName of the attached policy.
priorityinteger or nullNoExplicit execution order, lower runs first. Prioritised attachments run before those without one.
scopestring or nullNoScope of the attachment.
tagsarray of stringNoTag patterns.
teamsarray of stringNoTeam patterns.
updated_atstring or nullNoWhen the attachment was last updated.
updated_bystring or nullNoWho last updated the attachment.

GET /policies/compare​

Compare two policy versions

Show the fields that differ between two policy versions, given their policy_id values as version_a and version_b. The Compare versions button in the Admin UI calls this route.

Parameters:

NameInTypeRequiredDescription
version_aquerystringYes
version_bquerystringYes

Example request:

curl -X GET "http://localhost:4000/policies/compare?version_a=string&version_b=string" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json PolicyVersionCompareResponse
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
404No policy version has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so policies cannot be stored.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
field_diffsobjectNoField name -> {version_a: val, version_b: val} for differing fields.
version_aPolicyDBResponseYesFirst version.
version_bPolicyDBResponseYesSecond version.

GET /policies/list​

List policies and their versions

List every policy version from the database together with the policies in the config file. Filter with version_status set to draft, published or production.

Config-defined policies are returned with definition_location "config" and are treated as production versions. On a name conflict with a production DB policy, only the DB policy is returned, mirroring runtime resolution where only production DB versions override config. A draft or published DB version does not hide the config policy, since the config version is still the one being enforced.

Query params:

  • version_status: Optional. One of "draft", "published", "production". If omitted, all versions are returned.

Example Request:

curl -X GET "http://localhost:4000/policies/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
curl -X GET "http://localhost:4000/policies/list?version_status=production" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Example Response:

{
"policies": [
{
"policy_id": "123e4567-e89b-12d3-a456-426614174000",
"policy_name": "global-baseline",
"version_number": 1,
"version_status": "production",
"inherit": null,
"description": "Base guardrails for all requests",
"guardrails_add": ["pii_masking"],
"guardrails_remove": [],
"condition": null,
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
}
],
"total_count": 1
}

Parameters:

NameInTypeRequiredDescription
version_statusquerystring or nullNo

Example request:

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

Responses:

StatusDescriptionBody
200Successful Responseapplication/json PolicyListDBResponse
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
422Validation Errorapplication/json HTTPValidationError
500The database raised an error.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
policiesarray of PolicyDBResponseNoList of policies.
total_countintegerNoTotal number of policies.

DELETE /policies/name/{policy_name}/all-versions​

Delete every version of a policy

Delete every stored version of the policy with this name, including the production version, so the gateway stops applying it. Attachments that name the policy are left in place. When a config file policy has the same name, the answer carries a warning that the config version is enforced again. Proxy admins only. The change is written to the audit log.

Parameters:

NameInTypeRequiredDescription
policy_namepathstringYes

Example request:

curl -X DELETE "http://localhost:4000/policies/name/policy_name-123/all-versions" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Every version is gone and the gateway stops applying the policy.application/json PolicyDeletedResponse
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
403An admin viewer key tried to change a policy. Admin viewers can only readapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so policies cannot be stored.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
messagestringYesWhich policy or attachment was deleted.
warningstring or nullNoSet when the deletion changed what the gateway enforces, for example production went.

GET /policies/name/{policy_name}/versions​

List the versions of a policy

List every version of the policy with this name, newest first, with each version's status. Use it to find the policy_id of the draft to edit or the version to promote.

Parameters:

NameInTypeRequiredDescription
policy_namepathstringYes

Example request:

curl -X GET "http://localhost:4000/policies/name/policy_name-123/versions" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json PolicyVersionListResponse
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so policies cannot be stored.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
policy_namestringYesName of the policy.
total_countintegerNoTotal number of versions.
versionsarray of PolicyDBResponseNoAll versions ordered by version_number desc.

POST /policies/name/{policy_name}/versions​

Create a draft version of a policy

Open a new draft of the policy by copying every field of the production version, or of the version named by source_policy_id. The draft gets the next version number and changes nothing until it is published and promoted. Proxy admins only.

Parameters:

NameInTypeRequiredDescription
policy_namepathstringYes

Request body (application/json, schema PolicyVersionCreateRequest):

FieldTypeRequiredDescription
source_policy_idstring or nullNoPolicy ID to clone from. If None, clone from current production version.

Example request:

curl -X POST "http://localhost:4000/policies/name/policy_name-123/versions" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"source_policy_id": "0b3f6c2d-8e4a-4f1b-9c7d-5a6e8f9b0c1d"
}'

Responses:

StatusDescriptionBody
200The new draft.application/json PolicyDBResponse
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
403An admin viewer key tried to change a policy. Admin viewers can only readapplication/json ErrorDetail
404The policy has no version to copy from.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so policies cannot be stored.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
conditionobject or nullNoPolicy condition.
created_atstring or nullNoWhen the policy was created.
created_bystring or nullNoWho created the policy.
definition_locationenum: "db", "config"NoWhere this policy is defined: 'db' (database) or 'config' (config.yaml).
descriptionstring or nullNoPolicy description.
guardrails_addarray of stringNoGuardrails to add.
guardrails_removearray of stringNoGuardrails to remove.
inheritstring or nullNoParent policy name.
is_latestbooleanNoTrue if this is the latest version by version_number.
parent_version_idstring or nullNoPolicy ID this version was cloned from.
pipelineobject or nullNoOptional guardrail pipeline.
policy_idstringYesUnique ID of the policy.
policy_namestringYesName of the policy.
production_atstring or nullNoWhen this version was promoted to production.
published_atstring or nullNoWhen this version was published.
updated_atstring or nullNoWhen the policy was last updated.
updated_bystring or nullNoWho last updated the policy.
version_numberintegerNoVersion number of this policy.
version_statusstringNoOne of: draft, published, production.

POST /policies/resolve​

Simulate which policies and guardrails a request would get

Work out which policy attachments match a request with this team alias, key alias, model and tags, and which guardrails it would run, without sending a request. Every field is optional. The answer names each matched policy and what matched it, such as team:research or scope:*. The Policy Simulator tab of the Admin UI calls this route. Pass force_sync=true to read the attachments from the database instead of the in-memory copy.

Docs (https://docs.spanway.ai/docs/proxy/guardrails/policy_simulation)

Parameters:

NameInTypeRequiredDescription
force_syncquerybooleanNoForce a DB sync before resolving. Default uses in-memory cache.

Request body (application/json, schema PolicyResolveRequest):

FieldTypeRequiredDescription
key_aliasstring or nullNoKey alias to resolve for.
modelstring or nullNoModel name to resolve for.
tagsarray of string or nullNoTags to resolve for.
team_aliasstring or nullNoTeam alias to resolve for.

Example request:

curl -X POST "http://localhost:4000/policies/resolve" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"key_alias": "research-batch",
"model": "claude-sonnet-5-5",
"tags": [
"health-eu"
],
"team_alias": "research"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json PolicyResolveResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so attachments cannot be read.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
effective_guardrailsarray of stringNoFinal list of guardrails that would be applied.
matched_policiesarray of PolicyMatchDetailNoDetails about each matched policy and why it matched.

POST /policies/simulate​

Replay recent traffic through a policy

Try a policy on real traffic before it goes live. The gateway takes the newest stored requests of one team or one virtual key from the last few hours, runs each through the policy's request guardrails in audit mode and returns, per guardrail, how many requests it would have blocked, redacted or passed. Nothing is blocked, no model is called and no budget or rate limit counter moves. Replays need stored request bodies (general_settings.store_prompts_in_spend_logs: true), requests without one are counted in requests_without_content. Each run writes an invoked audit row on the policy table.

Example curl:

curl -X POST http://0.0.0.0:4000/policies/simulate \
-H "Authorization: Bearer sk-admin" -H "Content-Type: application/json" \
-d '{"policy_name": "pii-draft", "team_id": "team-support", "hours": 24, "sample_size": 50}'

Request body (application/json, schema PolicySimulateRequest):

FieldTypeRequiredDescription
guardrailsarray of string or nullNoDraft policy as a list of guardrail names. Set one of the three policy fields.
hoursintegerNoHow far back to sample, in hours.
key_hashstring or nullNoReplay traffic of this hashed virtual key (the token column). Set this or team_id.
policy_idstring or nullNoStored policy version to replay, drafts included, by its policy_id.
policy_namestring or nullNoProduction policy to replay. Set one of policy_name, policy_id or guardrails.
sample_sizeintegerNoMost recent requests to replay, newest first.
team_idstring or nullNoReplay traffic of this team. Set this or key_hash.

Example request:

curl -X POST "http://localhost:4000/policies/simulate" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json PolicySimulateResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
403Only proxy admins can replay stored traffic.application/json ErrorDetail
404The named policy or policy version does not exist.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The gateway has no database, so there is no stored traffic.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
guardrailsarray of GuardrailSimulationCountsYesPer guardrail block, redact and pass counts.
policy_namestringYesPolicy that was replayed, or 'draft' for a guardrail list.
requests_blockedintegerYesReplayed requests at least one guardrail would have blocked.
requests_consideredintegerYesStored requests found in the window.
requests_replayedintegerYesRequests that had stored content and were replayed.
requests_without_contentintegerYesRequests skipped because the spend log holds no request body (prompt storage was off).
skipped_guardrailsarray of SkippedGuardrailNoGuardrails of the policy that the replay cannot run.

POST /policies/test-pipeline​

Run a guardrail pipeline on sample messages

Run a pipeline definition against sample messages without saving it, and report what each step did, how long it took and the final decision. The guardrails really run, so a guardrail that calls a paid service is billed. The Test Pipeline panel of the Admin UI calls this route.

Example Request:

curl -X POST "http://localhost:4000/policies/test-pipeline" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"pipeline": {
"mode": "pre_call",
"steps": [
{"guardrail": "pii-guard", "on_pass": "next", "on_fail": "block"}
]
},
"test_messages": [{"role": "user", "content": "My SSN is 123-45-6789"}]
}'

Request body (application/json, schema PipelineTestRequest):

FieldTypeRequiredDescription
pipelineobjectYesPipeline definition with 'mode' and 'steps'.
test_messagesarray of objectYesTest messages to run through the pipeline, e.g. [{'role': 'user', 'content': '...'}].

Example request:

curl -X POST "http://localhost:4000/policies/test-pipeline" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"pipeline": {
"mode": "pre_call",
"steps": [
{
"guardrail": "pii-mask",
"on_fail": "block",
"on_pass": "next"
}
]
},
"test_messages": [
{
"content": "My card is 4111 1111 1111 1111",
"role": "user"
}
]
}'

Responses:

StatusDescriptionBody
200The decision and one result per step.application/json PipelineTestResponse
400The pipeline definition is not valid.application/json ErrorDetail
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
422Validation Errorapplication/json HTTPValidationError
500A guardrail raised an error the pipeline could not handle.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
error_messagestring or nullNoThe reason a step blocked, when one did.
modified_dataobject or nullNoThe request after the steps that rewrite content, when one did.
modify_response_messagestring or nullNoThe custom response text of a modify_response step, when one fired.
step_resultsarray of PipelineStepResultYesOne entry per step, in the order they ran.
terminal_actionstringYesWhat the pipeline decided for the request: allow, block or modify_response.

GET /policies/{policy_id}​

Read one policy version

Read one policy version by its policy_id.

Example Request:

curl -X GET "http://localhost:4000/policies/123e4567-e89b-12d3-a456-426614174000" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Parameters:

NameInTypeRequiredDescription
policy_idpathstringYes

Example request:

curl -X GET "http://localhost:4000/policies/policy_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The policy version as stored.application/json PolicyDBResponse
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
404No policy version has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so policies cannot be stored.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
conditionobject or nullNoPolicy condition.
created_atstring or nullNoWhen the policy was created.
created_bystring or nullNoWho created the policy.
definition_locationenum: "db", "config"NoWhere this policy is defined: 'db' (database) or 'config' (config.yaml).
descriptionstring or nullNoPolicy description.
guardrails_addarray of stringNoGuardrails to add.
guardrails_removearray of stringNoGuardrails to remove.
inheritstring or nullNoParent policy name.
is_latestbooleanNoTrue if this is the latest version by version_number.
parent_version_idstring or nullNoPolicy ID this version was cloned from.
pipelineobject or nullNoOptional guardrail pipeline.
policy_idstringYesUnique ID of the policy.
policy_namestringYesName of the policy.
production_atstring or nullNoWhen this version was promoted to production.
published_atstring or nullNoWhen this version was published.
updated_atstring or nullNoWhen the policy was last updated.
updated_bystring or nullNoWho last updated the policy.
version_numberintegerNoVersion number of this policy.
version_statusstringNoOne of: draft, published, production.

PUT /policies/{policy_id}​

Change a draft policy version

Change the fields you send on a draft version and keep the rest. Published and production versions are read only, so open a draft with POST /policies/name/{policy_name}/versions first. Proxy admins only. The change is written to the audit log.

Example Request:

curl -X PUT "http://localhost:4000/policies/123e4567-e89b-12d3-a456-426614174000" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"description": "Updated description",
"guardrails_add": ["pii_masking", "toxicity_filter"]
}'

Parameters:

NameInTypeRequiredDescription
policy_idpathstringYes

Request body (application/json, schema PolicyUpdateRequest):

FieldTypeRequiredDescription
conditionPolicyConditionRequest or nullNoCondition for when this policy applies.
descriptionstring or nullNoHuman-readable description of the policy.
guardrails_addarray of string or nullNoList of guardrail names to add.
guardrails_removearray of string or nullNoList of guardrail names to remove (from inherited).
inheritstring or nullNoName of parent policy to inherit from.
pipelineobject or nullNoOptional guardrail pipeline for ordered execution. Contains 'mode' and 'steps'.
policy_namestring or nullNoNew name for the policy.

Example request:

curl -X PUT "http://localhost:4000/policies/policy_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"description": "Extra checks for frontier models",
"guardrails_add": [
"prompt-injection",
"pii-mask"
]
}'

Responses:

StatusDescriptionBody
200The draft as stored.application/json PolicyDBResponse
400The version is published or in production.application/json ErrorDetail
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
403An admin viewer key tried to change a policy. Admin viewers can only readapplication/json ErrorDetail
404No policy version has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so policies cannot be stored.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
conditionobject or nullNoPolicy condition.
created_atstring or nullNoWhen the policy was created.
created_bystring or nullNoWho created the policy.
definition_locationenum: "db", "config"NoWhere this policy is defined: 'db' (database) or 'config' (config.yaml).
descriptionstring or nullNoPolicy description.
guardrails_addarray of stringNoGuardrails to add.
guardrails_removearray of stringNoGuardrails to remove.
inheritstring or nullNoParent policy name.
is_latestbooleanNoTrue if this is the latest version by version_number.
parent_version_idstring or nullNoPolicy ID this version was cloned from.
pipelineobject or nullNoOptional guardrail pipeline.
policy_idstringYesUnique ID of the policy.
policy_namestringYesName of the policy.
production_atstring or nullNoWhen this version was promoted to production.
published_atstring or nullNoWhen this version was published.
updated_atstring or nullNoWhen the policy was last updated.
updated_bystring or nullNoWho last updated the policy.
version_numberintegerNoVersion number of this policy.
version_statusstringNoOne of: draft, published, production.

DELETE /policies/{policy_id}​

Delete one policy version

Delete one version of a policy by its policy_id. Deleting the production version stops the policy from being enforced until another version is promoted, and the answer says so in warning. Proxy admins only. The change is written to the audit log.

Example Request:

curl -X DELETE "http://localhost:4000/policies/123e4567-e89b-12d3-a456-426614174000" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Example Response:

{
"message": "Policy 123e4567-e89b-12d3-a456-426614174000 deleted successfully"
}

Parameters:

NameInTypeRequiredDescription
policy_idpathstringYes

Example request:

curl -X DELETE "http://localhost:4000/policies/policy_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The version is gone. A warning says when it was the production version.application/json PolicyDeletedResponse
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
403An admin viewer key tried to change a policy. Admin viewers can only readapplication/json ErrorDetail
404No policy version has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so policies cannot be stored.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
messagestringYesWhich policy or attachment was deleted.
warningstring or nullNoSet when the deletion changed what the gateway enforces, for example production went.

GET /policies/{policy_id}/resolved-guardrails​

List the guardrails a policy resolves to

Walk the inheritance chain of this policy version and return the guardrails it ends up running, after the parent's guardrails, guardrails_add and guardrails_remove are applied. The version you name is resolved even when it is a draft, and its parents are resolved at their production versions. Answers 400 when a parent has no production version or the chain loops.

Example Request:

curl -X GET "http://localhost:4000/policies/123e4567-e89b-12d3-a456-426614174000/resolved-guardrails" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Example Response:

{
"policy_id": "123e4567-e89b-12d3-a456-426614174000",
"policy_name": "healthcare-compliance",
"resolved_guardrails": ["pii_masking", "prompt_injection", "toxicity_filter"]
}

Parameters:

NameInTypeRequiredDescription
policy_idpathstringYes

Example request:

curl -X GET "http://localhost:4000/policies/policy_id-123/resolved-guardrails" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The final guardrail list.application/json PolicyResolvedGuardrailsResponse
400The inheritance chain is broken, for example the parent does not exist or inherits in a cycle.application/json ErrorDetail
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
404No policy version has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so policies cannot be stored.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
policy_idstringYesID of the policy version that was resolved.
policy_namestringYesName of the policy.
resolved_guardrailsarray of stringNoEvery guardrail the policy runs once inheritance, additions and removals are applied.

PUT /policies/{policy_id}/status​

Publish or promote a policy version

Move a policy version along: a draft becomes published, a published version becomes production and the previous production version drops back to published. A production version cannot be set back to published directly, promote another version instead. Only the production version is applied to traffic. Proxy admins only. The change, and the demotion of the previous production version, are written to the audit log with the value before and after.

Parameters:

NameInTypeRequiredDescription
policy_idpathstringYes

Request body (application/json, schema PolicyVersionStatusUpdateRequest):

FieldTypeRequiredDescription
version_statusstringYesNew status: 'published' or 'production'.

Example request:

curl -X PUT "http://localhost:4000/policies/policy_id-123/status" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"version_status": "production"
}'

Responses:

StatusDescriptionBody
200The policy version as stored.application/json PolicyDBResponse
400The transition is not allowed, for example a draft straight to production.application/json ErrorDetail
401No key was sent, or the key is not a proxy admin key. A non-admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams.application/json ProxyError
403An admin viewer key tried to change a policy. Admin viewers can only readapplication/json ErrorDetail
404No policy version has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so policies cannot be stored.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
conditionobject or nullNoPolicy condition.
created_atstring or nullNoWhen the policy was created.
created_bystring or nullNoWho created the policy.
definition_locationenum: "db", "config"NoWhere this policy is defined: 'db' (database) or 'config' (config.yaml).
descriptionstring or nullNoPolicy description.
guardrails_addarray of stringNoGuardrails to add.
guardrails_removearray of stringNoGuardrails to remove.
inheritstring or nullNoParent policy name.
is_latestbooleanNoTrue if this is the latest version by version_number.
parent_version_idstring or nullNoPolicy ID this version was cloned from.
pipelineobject or nullNoOptional guardrail pipeline.
policy_idstringYesUnique ID of the policy.
policy_namestringYesName of the policy.
production_atstring or nullNoWhen this version was promoted to production.
published_atstring or nullNoWhen this version was published.
updated_atstring or nullNoWhen the policy was last updated.
updated_bystring or nullNoWho last updated the policy.
version_numberintegerNoVersion number of this policy.
version_statusstringNoOne of: draft, published, production.