Skip to main content

Guardrails API

This page documents the 25 gateway endpoints tagged guardrails 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/apply_guardrailRun one guardrail on a piece of text
POST/guardrailsCreate a guardrail
POST/guardrails/apply_guardrailRun one guardrail on a piece of text
GET/guardrails/listList every guardrail the gateway knows
POST/guardrails/registerSubmit a team guardrail for admin review
GET/guardrails/submissionsList team guardrail submissions
GET/guardrails/submissions/{guardrail_id}Read one team guardrail submission
POST/guardrails/submissions/{guardrail_id}/approveApprove a team guardrail submission
POST/guardrails/submissions/{guardrail_id}/rejectReject a team guardrail submission
POST/guardrails/test_custom_codeRun custom guardrail code against a sample input
GET/guardrails/ui/add_guardrail_settingsRead the choices the Create guardrail form offers
GET/guardrails/ui/category_yaml/{category_name}Read a content filter category definition
GET/guardrails/ui/competitor_brandsRead the competitor brand list
GET/guardrails/ui/provider_specific_paramsRead the fields each guardrail provider takes
GET/guardrails/usage/detail/{guardrail_id}Read one guardrail's usage, cost and daily series
GET/guardrails/usage/logsList the requests a guardrail or policy evaluated
GET/guardrails/usage/overviewSummarize how every guardrail behaved over a date range
POST/guardrails/validate_blocked_words_fileCheck a blocked words file before uploading it
GET/guardrails/{guardrail_id}Read one guardrail
PUT/guardrails/{guardrail_id}Replace a stored guardrail
PATCH/guardrails/{guardrail_id}Change some fields of a stored guardrail
DELETE/guardrails/{guardrail_id}Delete a stored guardrail
GET/guardrails/{guardrail_id}/infoRead one guardrail
GET/policies/usage/overviewSummarize how every policy behaved over a date range
GET/v2/guardrails/listList the stored guardrails with their ids

Endpoints​

POST /apply_guardrail​

Run one guardrail on a piece of text

Run the guardrail named guardrail_name on text without calling a model and return the text as the guardrail left it. A masking guardrail answers the rewritten text, an allowing guardrail answers the text unchanged, and a blocking guardrail answers the same 400 a model request would get. input_type picks the request or the response behaviour of the guardrail, and language and entities tune PII guardrails. The call is logged under the calling key and counts in the guardrail usage reports. Any key that may call models may call /guardrails/apply_guardrail, while the shorter /apply_guardrail path is for proxy admins.

Docs

Request body (application/json, schema ApplyGuardrailRequest):

FieldTypeRequiredDescription
entitiesarray of PiiEntityType or nullNoEntities
guardrail_namestringYesGuardrail Name
input_typestringNoInput Type
languagestring or nullNoLanguage
messagesarray of object or nullNoMessages
metadataobject or nullNoMetadata
textstringYesText

Example request:

curl -X POST "http://localhost:4000/apply_guardrail" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"guardrail_name": "pii-mask",
"language": "en",
"text": "Call me at 415-555-0100 or email jane.doe@example.com"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json ApplyGuardrailResponse
400The guardrail blocked the text. The message carries the guardrail's reason.application/json ProxyError
401No valid key was sent, or a key that is not a proxy admin called the short /apply_guardrail path, which is for proxy admins only. Any key that may call models may use /guardrails/apply_guardrail.application/json ProxyError
404No guardrail has this name.application/json ProxyError
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
response_textstringYesResponse Text

POST /guardrails​

Create a guardrail

Store a guardrail in the database and start running it at once, without a restart. spanway_params.guardrail names the integration, mode says when it runs and default_on makes it run on every request. The integration is initialized before the guardrail is kept, so a bad configuration (400) or a missing license (403) is refused and nothing is stored. Proxy admins only. The change is written to the audit log.

Docs

Request body (application/json, schema CreateGuardrailRequest):

FieldTypeRequiredDescription
guardrailGuardrailYes

Example request:

curl -X POST "http://localhost:4000/guardrails" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"guardrail": {
"guardrail_info": {
"description": "Masks personal data before the model sees it"
},
"guardrail_name": "pii-mask",
"spanway_params": {
"default_on": true,
"guardrail": "presidio",
"mode": "pre_call"
}
}
}'

Responses:

StatusDescriptionBody
200The guardrail as stored.application/json GuardrailInfoResponse
400The guardrail integration refused the parameters, so nothing was stored.application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin, or the guardrail needs an enterprise license this gateway does not have. Nothing was stored.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so stored guardrails cannot be read or changed.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
created_atstring or nullNoCreated At
guardrail_definition_locationGUARDRAIL_DEFINITION_LOCATIONNo
guardrail_idstring or nullNoGuardrail Id
guardrail_infoobject or nullNoGuardrail Info
guardrail_namestringYesGuardrail Name
spanway_paramsBaseSpanwayParams or nullNo
updated_atstring or nullNoUpdated At

POST /guardrails/apply_guardrail​

Run one guardrail on a piece of text

Run the guardrail named guardrail_name on text without calling a model and return the text as the guardrail left it. A masking guardrail answers the rewritten text, an allowing guardrail answers the text unchanged, and a blocking guardrail answers the same 400 a model request would get. input_type picks the request or the response behaviour of the guardrail, and language and entities tune PII guardrails. The call is logged under the calling key and counts in the guardrail usage reports. Any key that may call models may call /guardrails/apply_guardrail, while the shorter /apply_guardrail path is for proxy admins.

Docs

Request body (application/json, schema ApplyGuardrailRequest):

FieldTypeRequiredDescription
entitiesarray of PiiEntityType or nullNoEntities
guardrail_namestringYesGuardrail Name
input_typestringNoInput Type
languagestring or nullNoLanguage
messagesarray of object or nullNoMessages
metadataobject or nullNoMetadata
textstringYesText

Example request:

curl -X POST "http://localhost:4000/guardrails/apply_guardrail" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"guardrail_name": "pii-mask",
"language": "en",
"text": "Call me at 415-555-0100 or email jane.doe@example.com"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json ApplyGuardrailResponse
400The guardrail blocked the text. The message carries the guardrail's reason.application/json ProxyError
401No valid key was sent, or a key that is not a proxy admin called the short /apply_guardrail path, which is for proxy admins only. Any key that may call models may use /guardrails/apply_guardrail.application/json ProxyError
404No guardrail has this name.application/json ProxyError
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
response_textstringYesResponse Text

GET /guardrails/list​

List every guardrail the gateway knows

List the guardrails from the config file and the database, with the parameters each one takes. Use it to find the guardrail_name to put in a request body, a key, a team or a policy. A proxy admin, an admin viewer or an internal user may call it. Nothing is changed.

Docs

Example request:

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

Responses:

StatusDescriptionBody
200Successful Responseapplication/json ListGuardrailsResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
guardrailsarray of GuardrailInfoResponseYesGuardrails

POST /guardrails/register​

Submit a team guardrail for admin review

Let a team member submit a guardrail that points at the team's own service, in the generic guardrail API format. The submission is stored with status pending_review and runs nothing until a proxy admin approves it. team_id may come from the body or from a team scoped key, and the caller must be a member of that team.

Docs

Request body (application/json, schema RegisterGuardrailRequest):

FieldTypeRequiredDescription
guardrail_infoobject or nullNoGuardrail Info
guardrail_namestringYesGuardrail Name
spanway_paramsobjectYesSpanway Params
team_idstring or nullNoTeam Id

Example request:

curl -X POST "http://localhost:4000/guardrails/register" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"guardrail_info": {
"description": "In-house prompt injection classifier"
},
"guardrail_name": "research-classifier",
"spanway_params": {
"api_base": "https://classifier.research.internal.example.com",
"api_key": "os.environ/RESEARCH_CLASSIFIER_KEY",
"guardrail": "generic_guardrail_api",
"mode": "pre_call"
},
"team_id": "team-research"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json RegisterGuardrailResponse
400The body is not a generic guardrail API guardrail, for example api_base or mode is missing or the name is taken.application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller is not a member of the team named in the body.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so stored guardrails cannot be read or changed.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
guardrail_idstringYesGuardrail Id
guardrail_namestringYesGuardrail Name
statusstringYesStatus
submitted_atstring or nullNoSubmitted At

GET /guardrails/submissions​

List team guardrail submissions

List the guardrails teams submitted for review, each with its status: pending_review while it waits for a proxy admin, active once approved and rejected when turned down. Filter with status, team_id and search, which matches the name and the description.

A proxy admin or an admin viewer sees every submission. Any other user sees only the submissions of the teams they belong to, and asking for another team's team_id is refused with 403. Nothing is changed.

Docs

Parameters:

NameInTypeRequiredDescription
statusquerystring or nullNo
team_idquerystring or nullNo
searchquerystring or nullNo

Example request:

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

Responses:

StatusDescriptionBody
200Successful Responseapplication/json ListGuardrailSubmissionsResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The team_id filter names a team the caller is not a member of.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so stored guardrails cannot be read or changed.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
submissionsarray of GuardrailSubmissionItemYesSubmissions
summaryGuardrailSubmissionSummaryYes

GET /guardrails/submissions/{guardrail_id}​

Read one team guardrail submission

Read one team guardrail submission by id, with its status, the team that sent it and its configuration. A proxy admin or an admin viewer may read any submission, anyone else only the submissions of their own teams. Nothing is changed.

Docs

Parameters:

NameInTypeRequiredDescription
guardrail_idpathstringYes

Example request:

curl -X GET "http://localhost:4000/guardrails/submissions/guardrail_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json GuardrailSubmissionItem
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller is not a member of the team that owns the submission.application/json ErrorDetail
404No team submission has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so stored guardrails cannot be read or changed.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
created_atstring or nullNoCreated At
guardrail_idstringYesGuardrail Id
guardrail_infoobject or nullNoGuardrail Info
guardrail_namestringYesGuardrail Name
reviewed_atstring or nullNoReviewed At
spanway_paramsobject or nullNoSpanway Params
statusstringYesStatus
submitted_atstring or nullNoSubmitted At
submitted_by_emailstring or nullNoSubmitted By Email
submitted_by_user_idstring or nullNoSubmitted By User Id
team_guardrailbooleanNoTeam Guardrail
team_idstring or nullNoTeam Id
updated_atstring or nullNoUpdated At

POST /guardrails/submissions/{guardrail_id}/approve​

Approve a team guardrail submission

Mark a pending team submission active and start running it. When the row is updated but the guardrail fails to start, the answer carries a warning and the guardrail is picked up on the next sync. Proxy admins only. The change is written to the audit log.

Docs

Parameters:

NameInTypeRequiredDescription
guardrail_idpathstringYes

Request body (application/json, object):

Example request:

curl -X POST "http://localhost:4000/guardrails/submissions/guardrail_id-123/approve" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'

Responses:

StatusDescriptionBody
200The guardrail is active and running.application/json GuardrailSubmissionReviewResponse
400The submission was already approved or rejected.application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin.application/json ErrorDetail
404No team submission has this id.application/json ErrorDetail
409The stored parameters were encrypted with another master key, so the guardrail cannot start.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so stored guardrails cannot be read or changed.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
guardrail_idstringYesGuardrail Id
messagestringYesMessage
statusstringYesStatus
warningstring or nullNoWarning

POST /guardrails/submissions/{guardrail_id}/reject​

Reject a team guardrail submission

Mark a pending team submission rejected. The row stays visible to the team with its new status, and nothing runs. Proxy admins only. The change is written to the audit log.

Docs

Parameters:

NameInTypeRequiredDescription
guardrail_idpathstringYes

Request body (application/json, object):

Example request:

curl -X POST "http://localhost:4000/guardrails/submissions/guardrail_id-123/reject" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'

Responses:

StatusDescriptionBody
200The submission is marked rejected and never runs.application/json GuardrailSubmissionReviewResponse
400The submission was already approved or rejected.application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin.application/json ErrorDetail
404No team submission has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so stored guardrails cannot be read or changed.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
guardrail_idstringYesGuardrail Id
messagestringYesMessage
statusstringYesStatus
warningstring or nullNoWarning

POST /guardrails/test_custom_code​

Run custom guardrail code against a sample input

Compile custom_code in the sandbox and run its apply_guardrail function once against test_input, without saving anything. The answer says whether the code ran and what it decided, or carries the compilation or execution error. A test run always stops after 5 seconds, whatever timeout the guardrail is saved with. Proxy admins only.

Docs

Request body (application/json, schema TestCustomCodeGuardrailRequest):

FieldTypeRequiredDescription
custom_codestringYesCustom Code
input_typeenum: "request", "response"NoInput Type
request_dataobject or nullNoRequest Data
test_inputobjectYesTest Input

Example request:

curl -X POST "http://localhost:4000/guardrails/test_custom_code" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"custom_code": "def apply_guardrail(inputs, request_data, input_type):\n for text in inputs[\"texts\"]:\n if regex_match(text, r\"\\d{3}-\\d{2}-\\d{4}\"):\n return block(\"Social Security Number detected\")\n return allow()",
"input_type": "request",
"test_input": {
"texts": [
"My SSN is 123-45-6789"
]
}
}'

Responses:

StatusDescriptionBody
200Whether the code ran and what it decided, or why it could not run.application/json TestCustomCodeGuardrailResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
errorstring or nullNoError
error_typeenum: "compilation", "execution" or nullNoError Type
resultobject or nullNoResult
successbooleanYesSuccess

GET /guardrails/ui/add_guardrail_settings​

Read the choices the Create guardrail form offers

Return the entity types, actions, modes, PII categories and content filter choices that the Create guardrail dialog in the Admin UI offers, so the form matches what this gateway supports. A proxy admin or an admin viewer may call it. Nothing is changed.

Docs (https://docs.spanway.ai/docs/admin_ui/guardrails)

Example request:

curl -X GET "http://localhost:4000/guardrails/ui/add_guardrail_settings" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json GuardrailUIAddGuardrailSettings
401No valid key or Admin UI session was presentedapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
content_filter_settingsobject or nullNoContent Filter Settings
decision_model_providersarray of stringNoDecision Model Providers
pii_entity_categoriesarray of PiiEntityCategoryMapYesPii Entity Categories
providers_without_directional_logging_only_scopearray of stringYesProviders Without Directional Logging Only Scope
supported_actionsarray of stringYesSupported Actions
supported_entitiesarray of stringYesSupported Entities
supported_modesarray of stringYesSupported Modes
supported_modes_by_providerobjectYesSupported Modes By Provider

GET /guardrails/ui/category_yaml/{category_name}​

Read a content filter category definition

Return the YAML or JSON file behind one Spanway content filter category, such as bias_gender, so the Admin UI can show what the category matches before you turn it on. A name with no bundled file answers 404. A proxy admin or an admin viewer may call it. Nothing is changed.

Docs (https://docs.spanway.ai/docs/admin_ui/guardrails)

Parameters:

NameInTypeRequiredDescription
category_namepathstringYes

Example request:

curl -X GET "http://localhost:4000/guardrails/ui/category_yaml/category_name-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The category file as shipped.application/json ContentFilterCategoryFileResponse
400The name has characters other than letters, digits, hyphens and underscores.application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
404No category file has this name.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The file exists but could not be read.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
category_namestringYesCategory Name
file_typestringYesFile Type
yaml_contentstringYesYaml Content

GET /guardrails/ui/competitor_brands​

Read the competitor brand list

Return the brand list the airline competitor intent category matches against: the bundled fictional sample, or your own list when SPANWAY_COMPETITOR_BRANDS_FILE names a file in the same format. Each entry has an id, the match variants separated by |, and tags. A proxy admin or an admin viewer may call it. Nothing is changed.

Docs (https://docs.spanway.ai/docs/admin_ui/guardrails)

Example request:

curl -X GET "http://localhost:4000/guardrails/ui/competitor_brands" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The brand list in use.application/json CompetitorBrandsResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
404The configured brand file does not exist.application/json ErrorDetail
500The brand file is not valid JSON.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
airlinesarray of objectYesAirlines

GET /guardrails/ui/provider_specific_params​

Read the fields each guardrail provider takes

Return, for every guardrail provider, the fields its configuration takes with a description, whether each is required, and the input type or options the Admin UI should show for it. The Create guardrail form builds its provider settings from this answer, and a script can use it to check a configuration before sending it. A proxy admin or an admin viewer may call it. Nothing is changed.

Docs (https://docs.spanway.ai/docs/admin_ui/guardrails)

Example request:

curl -X GET "http://localhost:4000/guardrails/ui/provider_specific_params" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The fields of every provider, keyed by provider and then by field nameapplication/json object
401No valid key or Admin UI session was presentedapplication/json ProxyError

GET /guardrails/usage/detail/{guardrail_id}​

Read one guardrail's usage, cost and daily series

Return one guardrail's evaluations, fail rate, latency and daily series over the date range, with its provider usage units and priced cost broken down by counter, team and virtual key. Units with no known price are reported separately as untracked. The guardrail detail view of the Guardrails Monitor page reads this route. A proxy admin or an admin viewer may call it. Nothing is changed.

Docs (https://docs.spanway.ai/docs/admin_ui/guardrails_monitor)

Parameters:

NameInTypeRequiredDescription
guardrail_idpathstringYes
start_datequerystring or nullNoFirst day of the range, YYYY-MM-DD, counted in full. Defaults to 7 days before end_date. The range may span at most 366 days.
end_datequerystring or nullNoLast day of the range, YYYY-MM-DD, counted in full. Defaults to today (UTC).

Example request:

curl -X GET "http://localhost:4000/guardrails/usage/detail/guardrail_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json UsageDetailResponse
400The dates are not YYYY-MM-DD, the end is before the start, or the range is longer than 366 days.application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
404No guardrail has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
avgLatencynumber or nullYesAvglatency
avgScorenumber or nullYesAvgscore
costnumber or nullYesCost
cost_by_keyobjectYesCost By Key
cost_by_teamobjectYesCost By Team
cost_by_unitobjectYesCost By Unit
descriptionstring or nullYesDescription
failRatenumberYesFailrate
guardrail_idstringYesGuardrail Id
guardrail_namestringYesGuardrail Name
providerstringYesProvider
requestsEvaluatedintegerYesRequestsevaluated
statusstringYesStatus
time_seriesarray of UsageChartPointYesTime Series
trendstringYesTrend
typestringYesType
untracked_usage_unitsobjectYesUntracked Usage Units
untracked_usage_units_by_keyobjectYesUntracked Usage Units By Key
untracked_usage_units_by_teamobjectYesUntracked Usage Units By Team
usage_unitsobjectYesUsage Units
usage_units_by_keyobjectYesUsage Units By Key
usage_units_by_teamobjectYesUsage Units By Team
usage_units_dailyarray of UsageUnitsDailyPointYesUsage Units Daily

GET /guardrails/usage/logs​

List the requests a guardrail or policy evaluated

Page through the requests one guardrail, or one policy, evaluated in the date range, newest first, each with the outcome (blocked, passed, flagged or not_run), the latency, the model and the start of the input and output. action filters the returned page only, and total counts every outcome. The Logs tab of a guardrail in the Guardrails Monitor reads this route. A proxy admin or an admin viewer may call it. When the caller's custom role hides prompts, responses or tool call arguments, the snippets and the reason that quote them come back as [hidden by your role]. Nothing is changed.

Docs (https://docs.spanway.ai/docs/admin_ui/guardrails_monitor)

Parameters:

NameInTypeRequiredDescription
guardrail_idquerystring or nullNo
policy_idquerystring or nullNo
pagequeryintegerNo
page_sizequeryintegerNo
actionqueryenum: "blocked", "passed", "flagged", "not_run" or nullNoKeep only entries with this outcome. It filters the returned page only, so total still counts every outcome and a page can hold fewer entries than page_size.
start_datequerystring or nullNoEarliest request, YYYY-MM-DD or a full ISO timestamp
end_datequerystring or nullNoLatest request, YYYY-MM-DD (the whole day) or a full ISO timestamp

Example request:

curl -X GET "http://localhost:4000/guardrails/usage/logs" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json UsageLogsResponse
400The dates are not ISO dates, the end is before the start, or the range is longer than 366 days.application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
logsarray of UsageLogEntryYesLogs
pageintegerYesPage
page_sizeintegerYesPage Size
totalintegerYesTotal

GET /guardrails/usage/overview​

Summarize how every guardrail behaved over a date range

Return, for each guardrail, how many requests it evaluated, how many it blocked, the latency it added and the priced cost of its provider usage over the date range, plus a per day passed and blocked series. The range defaults to the last seven days and may cover at most 366 days. The Guardrails Monitor page reads this route. A proxy admin or an admin viewer may call it. Nothing is changed.

Docs (https://docs.spanway.ai/docs/admin_ui/guardrails_monitor)

Parameters:

NameInTypeRequiredDescription
start_datequerystring or nullNoFirst day of the range, YYYY-MM-DD, counted in full. Defaults to 7 days before end_date. The range may span at most 366 days.
end_datequerystring or nullNoLast day of the range, YYYY-MM-DD, counted in full. Defaults to today (UTC).

Example request:

curl -X GET "http://localhost:4000/guardrails/usage/overview" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json UsageOverviewResponse
400The dates are not YYYY-MM-DD, the end is before the start, or the range is longer than 366 days.application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
chartarray of UsageChartPointYesChart
passRatenumberYesPassrate
rowsarray of UsageOverviewRowYesRows
totalBlockedintegerYesTotalblocked
totalCostnumber or nullYesTotalcost
totalRequestsintegerYesTotalrequests
totalUntrackedUsageUnitsobjectYesTotaluntrackedusageunits
totalUsageUnitsobjectYesTotalusageunits

POST /guardrails/validate_blocked_words_file​

Check a blocked words file before uploading it

Parse a blocked words YAML file and report whether every entry has a keyword and an action of BLOCK or MASK. A file that does not parse answers 200 with valid false and the list of problems, so the Admin UI can show them next to the upload. A valid file answers with the parsed words so the form can add them. Only a proxy admin may call it, and nothing is stored.

Docs (https://docs.spanway.ai/docs/admin_ui/guardrails)

Request body (application/json, object):

Example request:

curl -X POST "http://localhost:4000/guardrails/validate_blocked_words_file" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"file_content": "blocked_words:\n - keyword: project-falcon\n action: BLOCK\n - keyword: acme\n action: MASK"
}'

Responses:

StatusDescriptionBody
200Whether the file parses. A bad file still answers 200 with valid false.application/json BlockedWordsValidationResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
blocked_wordsarray of BlockedWord or nullNoBlocked Words
errorstring or nullNoError
errorsarray of string or nullNoErrors
messagestring or nullNoMessage
validbooleanYesValid

GET /guardrails/{guardrail_id}​

Read one guardrail

Read one guardrail by id, from the database or the config file, with its parameters. Stored secrets come back masked. A proxy admin or an admin viewer may call it. Nothing is changed.

Docs

Parameters:

NameInTypeRequiredDescription
guardrail_idpathstringYes

Example request:

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

Responses:

StatusDescriptionBody
200The guardrail as stored.application/json GuardrailInfoResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
404No guardrail has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The database or the guardrail integration raised an error.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
created_atstring or nullNoCreated At
guardrail_definition_locationGUARDRAIL_DEFINITION_LOCATIONNo
guardrail_idstring or nullNoGuardrail Id
guardrail_infoobject or nullNoGuardrail Info
guardrail_namestringYesGuardrail Name
spanway_paramsBaseSpanwayParams or nullNo
updated_atstring or nullNoUpdated At

PUT /guardrails/{guardrail_id}​

Replace a stored guardrail

Replace the whole definition of a database guardrail and reload it. A masked secret sent back unchanged keeps the stored value, and a masked secret together with a new api_base is refused so a stored key never travels to a new host. Config file guardrails cannot be changed here. Proxy admins only. The change is written to the audit log.

Docs

Parameters:

NameInTypeRequiredDescription
guardrail_idpathstringYes

Request body (application/json, schema UpdateGuardrailRequest):

FieldTypeRequiredDescription
guardrailGuardrailYes

Example request:

curl -X PUT "http://localhost:4000/guardrails/guardrail_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"guardrail": {
"guardrail_info": {
"description": "Masks personal data before the model sees it"
},
"guardrail_name": "pii-mask",
"spanway_params": {
"default_on": true,
"guardrail": "presidio",
"mode": "pre_call"
}
}
}'

Responses:

StatusDescriptionBody
200The guardrail as stored.application/json GuardrailInfoResponse
400A destination field such as api_base changed while the stored secret was left out or sent back masked.application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin.application/json ErrorDetail
404No guardrail has this id.application/json ErrorDetail
422The new parameters do not initialize, so the stored guardrail keeps running unchanged.application/json ErrorDetail
500The gateway runs without a database, so stored guardrails cannot be read or changed.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
created_atstring or nullNoCreated At
guardrail_definition_locationGUARDRAIL_DEFINITION_LOCATIONNo
guardrail_idstring or nullNoGuardrail Id
guardrail_infoobject or nullNoGuardrail Info
guardrail_namestringYesGuardrail Name
spanway_paramsBaseSpanwayParams or nullNo
updated_atstring or nullNoUpdated At

PATCH /guardrails/{guardrail_id}​

Change some fields of a stored guardrail

Change only the fields you send on a database guardrail and keep the rest. spanway_params is merged into the stored parameters, so {"spanway_params": {"default_on": true}} turns a guardrail on for every request without repeating its other settings. The merged definition is initialized before it is stored. Proxy admins only. The change is written to the audit log.

Docs

Parameters:

NameInTypeRequiredDescription
guardrail_idpathstringYes

Request body (application/json, schema PatchGuardrailRequest):

FieldTypeRequiredDescription
guardrail_infoobject or nullNoGuardrail Info
guardrail_namestring or nullNoGuardrail Name
spanway_paramsBaseSpanwayParams or nullNo

Example request:

curl -X PATCH "http://localhost:4000/guardrails/guardrail_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"guardrail_info": {
"description": "Masks personal data before the model sees it"
},
"guardrail_name": "pii-mask",
"spanway_params": {
"default_on": true
}
}'

Responses:

StatusDescriptionBody
200The guardrail as stored.application/json GuardrailInfoResponse
400A destination field such as api_base changed while the stored secret was left out or sent back masked.application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin.application/json ErrorDetail
404No guardrail has this id.application/json ErrorDetail
422The merged parameters do not initialize, so the stored guardrail keeps running unchanged.application/json ErrorDetail
500The gateway runs without a database, so stored guardrails cannot be read or changed.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
created_atstring or nullNoCreated At
guardrail_definition_locationGUARDRAIL_DEFINITION_LOCATIONNo
guardrail_idstring or nullNoGuardrail Id
guardrail_infoobject or nullNoGuardrail Info
guardrail_namestringYesGuardrail Name
spanway_paramsBaseSpanwayParams or nullNo
updated_atstring or nullNoUpdated At

DELETE /guardrails/{guardrail_id}​

Delete a stored guardrail

Remove a database guardrail and stop running it. Keys, teams and policies that still name it by guardrail_name are not changed, so check them first. Config file guardrails cannot be deleted here. Proxy admins only. The change is written to the audit log.

Docs

Parameters:

NameInTypeRequiredDescription
guardrail_idpathstringYes

Example request:

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

Responses:

StatusDescriptionBody
200The guardrail is gone from the database and from the running gateway.application/json GuardrailDeletedResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The key is not a proxy admin.application/json ErrorDetail
404No guardrail has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway runs without a database, so stored guardrails cannot be read or changed.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
messagestringYesMessage

GET /guardrails/{guardrail_id}/info​

Read one guardrail

Read one guardrail by id, from the database or the config file, with its parameters. Stored secrets come back masked. A proxy admin or an admin viewer may call it. Nothing is changed.

Docs

Parameters:

NameInTypeRequiredDescription
guardrail_idpathstringYes

Example request:

curl -X GET "http://localhost:4000/guardrails/guardrail_id-123/info" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The guardrail as stored.application/json GuardrailInfoResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
404No guardrail has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The database or the guardrail integration raised an error.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
created_atstring or nullNoCreated At
guardrail_definition_locationGUARDRAIL_DEFINITION_LOCATIONNo
guardrail_idstring or nullNoGuardrail Id
guardrail_infoobject or nullNoGuardrail Info
guardrail_namestringYesGuardrail Name
spanway_paramsBaseSpanwayParams or nullNo
updated_atstring or nullNoUpdated At

GET /policies/usage/overview​

Summarize how every policy behaved over a date range

The same summary as the guardrail overview, with one row per policy: how many requests each policy's guardrails evaluated and blocked, the latency added and the priced cost, over a range of at most 366 days. The Policies page reads this route for its usage figures. A proxy admin or an admin viewer may call it. Nothing is changed.

Docs (https://docs.spanway.ai/docs/admin_ui/policies)

Parameters:

NameInTypeRequiredDescription
start_datequerystring or nullNoFirst day of the range, YYYY-MM-DD, counted in full. Defaults to 7 days before end_date. The range may span at most 366 days.
end_datequerystring or nullNoLast day of the range, YYYY-MM-DD, counted in full. Defaults to today (UTC).

Example request:

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

Responses:

StatusDescriptionBody
200Successful Responseapplication/json UsageOverviewResponse
400The dates are not YYYY-MM-DD, the end is before the start, or the range is longer than 366 days.application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
chartarray of UsageChartPointYesChart
passRatenumberYesPassrate
rowsarray of UsageOverviewRowYesRows
totalBlockedintegerYesTotalblocked
totalCostnumber or nullYesTotalcost
totalRequestsintegerYesTotalrequests
totalUntrackedUsageUnitsobjectYesTotaluntrackedusageunits
totalUsageUnitsobjectYesTotalusageunits

GET /v2/guardrails/list​

List the stored guardrails with their ids

List the guardrails stored in the database together with the config file guardrails, each with its guardrail_id, so the Admin UI and scripts can address one for an update or a delete. Stored secrets come back masked. A proxy admin, an admin viewer or an internal user may call it. Nothing is changed.

Docs

Example request:

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

Responses:

StatusDescriptionBody
200Successful Responseapplication/json ListGuardrailsResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
500The database could not be read.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
guardrailsarray of GuardrailInfoResponseYesGuardrails