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.
| Method | Path | Summary |
|---|---|---|
| POST | /apply_guardrail | Run one guardrail on a piece of text |
| POST | /guardrails | Create a guardrail |
| POST | /guardrails/apply_guardrail | Run one guardrail on a piece of text |
| GET | /guardrails/list | List every guardrail the gateway knows |
| POST | /guardrails/register | Submit a team guardrail for admin review |
| GET | /guardrails/submissions | List team guardrail submissions |
| GET | /guardrails/submissions/{guardrail_id} | Read one team guardrail submission |
| POST | /guardrails/submissions/{guardrail_id}/approve | Approve a team guardrail submission |
| POST | /guardrails/submissions/{guardrail_id}/reject | Reject a team guardrail submission |
| POST | /guardrails/test_custom_code | Run custom guardrail code against a sample input |
| GET | /guardrails/ui/add_guardrail_settings | Read the choices the Create guardrail form offers |
| GET | /guardrails/ui/category_yaml/{category_name} | Read a content filter category definition |
| GET | /guardrails/ui/competitor_brands | Read the competitor brand list |
| GET | /guardrails/ui/provider_specific_params | Read the fields each guardrail provider takes |
| GET | /guardrails/usage/detail/{guardrail_id} | Read one guardrail's usage, cost and daily series |
| GET | /guardrails/usage/logs | List the requests a guardrail or policy evaluated |
| GET | /guardrails/usage/overview | Summarize how every guardrail behaved over a date range |
| POST | /guardrails/validate_blocked_words_file | Check 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}/info | Read one guardrail |
| GET | /policies/usage/overview | Summarize how every policy behaved over a date range |
| GET | /v2/guardrails/list | List 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.
Request body (application/json, schema ApplyGuardrailRequest):
| Field | Type | Required | Description |
|---|---|---|---|
entities | array of PiiEntityType or null | No | Entities |
guardrail_name | string | Yes | Guardrail Name |
input_type | string | No | Input Type |
language | string or null | No | Language |
messages | array of object or null | No | Messages |
metadata | object or null | No | Metadata |
text | string | Yes | Text |
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:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json ApplyGuardrailResponse |
| 400 | The guardrail blocked the text. The message carries the guardrail's reason. | application/json ProxyError |
| 401 | No 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 |
| 404 | No guardrail has this name. | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
response_text | string | Yes | Response 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.
Request body (application/json, schema CreateGuardrailRequest):
| Field | Type | Required | Description |
|---|---|---|---|
guardrail | Guardrail | Yes |
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:
| Status | Description | Body |
|---|---|---|
| 200 | The guardrail as stored. | application/json GuardrailInfoResponse |
| 400 | The guardrail integration refused the parameters, so nothing was stored. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key is not a proxy admin, or the guardrail needs an enterprise license this gateway does not have. Nothing was stored. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway runs without a database, so stored guardrails cannot be read or changed. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
created_at | string or null | No | Created At |
guardrail_definition_location | GUARDRAIL_DEFINITION_LOCATION | No | |
guardrail_id | string or null | No | Guardrail Id |
guardrail_info | object or null | No | Guardrail Info |
guardrail_name | string | Yes | Guardrail Name |
spanway_params | BaseSpanwayParams or null | No | |
updated_at | string or null | No | Updated 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.
Request body (application/json, schema ApplyGuardrailRequest):
| Field | Type | Required | Description |
|---|---|---|---|
entities | array of PiiEntityType or null | No | Entities |
guardrail_name | string | Yes | Guardrail Name |
input_type | string | No | Input Type |
language | string or null | No | Language |
messages | array of object or null | No | Messages |
metadata | object or null | No | Metadata |
text | string | Yes | Text |
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:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json ApplyGuardrailResponse |
| 400 | The guardrail blocked the text. The message carries the guardrail's reason. | application/json ProxyError |
| 401 | No 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 |
| 404 | No guardrail has this name. | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
response_text | string | Yes | Response 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.
Example request:
curl -X GET "http://localhost:4000/guardrails/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json ListGuardrailsResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
guardrails | array of GuardrailInfoResponse | Yes | Guardrails |
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.
Request body (application/json, schema RegisterGuardrailRequest):
| Field | Type | Required | Description |
|---|---|---|---|
guardrail_info | object or null | No | Guardrail Info |
guardrail_name | string | Yes | Guardrail Name |
spanway_params | object | Yes | Spanway Params |
team_id | string or null | No | Team 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:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json RegisterGuardrailResponse |
| 400 | The body is not a generic guardrail API guardrail, for example api_base or mode is missing or the name is taken. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The caller is not a member of the team named in the body. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway runs without a database, so stored guardrails cannot be read or changed. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
guardrail_id | string | Yes | Guardrail Id |
guardrail_name | string | Yes | Guardrail Name |
status | string | Yes | Status |
submitted_at | string or null | No | Submitted 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.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
status | query | string or null | No | |
team_id | query | string or null | No | |
search | query | string or null | No |
Example request:
curl -X GET "http://localhost:4000/guardrails/submissions" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json ListGuardrailSubmissionsResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The team_id filter names a team the caller is not a member of. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway runs without a database, so stored guardrails cannot be read or changed. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
submissions | array of GuardrailSubmissionItem | Yes | Submissions |
summary | GuardrailSubmissionSummary | Yes |
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.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
guardrail_id | path | string | Yes |
Example request:
curl -X GET "http://localhost:4000/guardrails/submissions/guardrail_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json GuardrailSubmissionItem |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The caller is not a member of the team that owns the submission. | application/json ErrorDetail |
| 404 | No team submission has this id. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway runs without a database, so stored guardrails cannot be read or changed. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
created_at | string or null | No | Created At |
guardrail_id | string | Yes | Guardrail Id |
guardrail_info | object or null | No | Guardrail Info |
guardrail_name | string | Yes | Guardrail Name |
reviewed_at | string or null | No | Reviewed At |
spanway_params | object or null | No | Spanway Params |
status | string | Yes | Status |
submitted_at | string or null | No | Submitted At |
submitted_by_email | string or null | No | Submitted By Email |
submitted_by_user_id | string or null | No | Submitted By User Id |
team_guardrail | boolean | No | Team Guardrail |
team_id | string or null | No | Team Id |
updated_at | string or null | No | Updated 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.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
guardrail_id | path | string | Yes |
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:
| Status | Description | Body |
|---|---|---|
| 200 | The guardrail is active and running. | application/json GuardrailSubmissionReviewResponse |
| 400 | The submission was already approved or rejected. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key is not a proxy admin. | application/json ErrorDetail |
| 404 | No team submission has this id. | application/json ErrorDetail |
| 409 | The stored parameters were encrypted with another master key, so the guardrail cannot start. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway runs without a database, so stored guardrails cannot be read or changed. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
guardrail_id | string | Yes | Guardrail Id |
message | string | Yes | Message |
status | string | Yes | Status |
warning | string or null | No | Warning |
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.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
guardrail_id | path | string | Yes |
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:
| Status | Description | Body |
|---|---|---|
| 200 | The submission is marked rejected and never runs. | application/json GuardrailSubmissionReviewResponse |
| 400 | The submission was already approved or rejected. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key is not a proxy admin. | application/json ErrorDetail |
| 404 | No team submission has this id. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway runs without a database, so stored guardrails cannot be read or changed. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
guardrail_id | string | Yes | Guardrail Id |
message | string | Yes | Message |
status | string | Yes | Status |
warning | string or null | No | Warning |
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.
Request body (application/json, schema TestCustomCodeGuardrailRequest):
| Field | Type | Required | Description |
|---|---|---|---|
custom_code | string | Yes | Custom Code |
input_type | enum: "request", "response" | No | Input Type |
request_data | object or null | No | Request Data |
test_input | object | Yes | Test 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:
| Status | Description | Body |
|---|---|---|
| 200 | Whether the code ran and what it decided, or why it could not run. | application/json TestCustomCodeGuardrailResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key is not a proxy admin. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
error | string or null | No | Error |
error_type | enum: "compilation", "execution" or null | No | Error Type |
result | object or null | No | Result |
success | boolean | Yes | Success |
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:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json GuardrailUIAddGuardrailSettings |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
content_filter_settings | object or null | No | Content Filter Settings |
decision_model_providers | array of string | No | Decision Model Providers |
pii_entity_categories | array of PiiEntityCategoryMap | Yes | Pii Entity Categories |
providers_without_directional_logging_only_scope | array of string | Yes | Providers Without Directional Logging Only Scope |
supported_actions | array of string | Yes | Supported Actions |
supported_entities | array of string | Yes | Supported Entities |
supported_modes | array of string | Yes | Supported Modes |
supported_modes_by_provider | object | Yes | Supported 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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
category_name | path | string | Yes |
Example request:
curl -X GET "http://localhost:4000/guardrails/ui/category_yaml/category_name-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The category file as shipped. | application/json ContentFilterCategoryFileResponse |
| 400 | The name has characters other than letters, digits, hyphens and underscores. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 404 | No category file has this name. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The file exists but could not be read. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
category_name | string | Yes | Category Name |
file_type | string | Yes | File Type |
yaml_content | string | Yes | Yaml 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:
| Status | Description | Body |
|---|---|---|
| 200 | The brand list in use. | application/json CompetitorBrandsResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 404 | The configured brand file does not exist. | application/json ErrorDetail |
| 500 | The brand file is not valid JSON. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
airlines | array of object | Yes | Airlines |
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:
| Status | Description | Body |
|---|---|---|
| 200 | The fields of every provider, keyed by provider and then by field name | application/json object |
| 401 | No valid key or Admin UI session was presented | application/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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
guardrail_id | path | string | Yes | |
start_date | query | string or null | No | First 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_date | query | string or null | No | Last 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:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json UsageDetailResponse |
| 400 | The dates are not YYYY-MM-DD, the end is before the start, or the range is longer than 366 days. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 404 | No guardrail has this id. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway runs without a database. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
avgLatency | number or null | Yes | Avglatency |
avgScore | number or null | Yes | Avgscore |
cost | number or null | Yes | Cost |
cost_by_key | object | Yes | Cost By Key |
cost_by_team | object | Yes | Cost By Team |
cost_by_unit | object | Yes | Cost By Unit |
description | string or null | Yes | Description |
failRate | number | Yes | Failrate |
guardrail_id | string | Yes | Guardrail Id |
guardrail_name | string | Yes | Guardrail Name |
provider | string | Yes | Provider |
requestsEvaluated | integer | Yes | Requestsevaluated |
status | string | Yes | Status |
time_series | array of UsageChartPoint | Yes | Time Series |
trend | string | Yes | Trend |
type | string | Yes | Type |
untracked_usage_units | object | Yes | Untracked Usage Units |
untracked_usage_units_by_key | object | Yes | Untracked Usage Units By Key |
untracked_usage_units_by_team | object | Yes | Untracked Usage Units By Team |
usage_units | object | Yes | Usage Units |
usage_units_by_key | object | Yes | Usage Units By Key |
usage_units_by_team | object | Yes | Usage Units By Team |
usage_units_daily | array of UsageUnitsDailyPoint | Yes | Usage 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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
guardrail_id | query | string or null | No | |
policy_id | query | string or null | No | |
page | query | integer | No | |
page_size | query | integer | No | |
action | query | enum: "blocked", "passed", "flagged", "not_run" or null | No | Keep 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_date | query | string or null | No | Earliest request, YYYY-MM-DD or a full ISO timestamp |
end_date | query | string or null | No | Latest 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:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json UsageLogsResponse |
| 400 | The dates are not ISO dates, the end is before the start, or the range is longer than 366 days. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
logs | array of UsageLogEntry | Yes | Logs |
page | integer | Yes | Page |
page_size | integer | Yes | Page Size |
total | integer | Yes | Total |
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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
start_date | query | string or null | No | First 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_date | query | string or null | No | Last 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:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json UsageOverviewResponse |
| 400 | The dates are not YYYY-MM-DD, the end is before the start, or the range is longer than 366 days. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
chart | array of UsageChartPoint | Yes | Chart |
passRate | number | Yes | Passrate |
rows | array of UsageOverviewRow | Yes | Rows |
totalBlocked | integer | Yes | Totalblocked |
totalCost | number or null | Yes | Totalcost |
totalRequests | integer | Yes | Totalrequests |
totalUntrackedUsageUnits | object | Yes | Totaluntrackedusageunits |
totalUsageUnits | object | Yes | Totalusageunits |
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:
| Status | Description | Body |
|---|---|---|
| 200 | Whether the file parses. A bad file still answers 200 with valid false. | application/json BlockedWordsValidationResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
blocked_words | array of BlockedWord or null | No | Blocked Words |
error | string or null | No | Error |
errors | array of string or null | No | Errors |
message | string or null | No | Message |
valid | boolean | Yes | Valid |
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.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
guardrail_id | path | string | Yes |
Example request:
curl -X GET "http://localhost:4000/guardrails/guardrail_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The guardrail as stored. | application/json GuardrailInfoResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 404 | No guardrail has this id. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The database or the guardrail integration raised an error. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
created_at | string or null | No | Created At |
guardrail_definition_location | GUARDRAIL_DEFINITION_LOCATION | No | |
guardrail_id | string or null | No | Guardrail Id |
guardrail_info | object or null | No | Guardrail Info |
guardrail_name | string | Yes | Guardrail Name |
spanway_params | BaseSpanwayParams or null | No | |
updated_at | string or null | No | Updated 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.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
guardrail_id | path | string | Yes |
Request body (application/json, schema UpdateGuardrailRequest):
| Field | Type | Required | Description |
|---|---|---|---|
guardrail | Guardrail | Yes |
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:
| Status | Description | Body |
|---|---|---|
| 200 | The guardrail as stored. | application/json GuardrailInfoResponse |
| 400 | A destination field such as api_base changed while the stored secret was left out or sent back masked. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key is not a proxy admin. | application/json ErrorDetail |
| 404 | No guardrail has this id. | application/json ErrorDetail |
| 422 | The new parameters do not initialize, so the stored guardrail keeps running unchanged. | application/json ErrorDetail |
| 500 | The gateway runs without a database, so stored guardrails cannot be read or changed. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
created_at | string or null | No | Created At |
guardrail_definition_location | GUARDRAIL_DEFINITION_LOCATION | No | |
guardrail_id | string or null | No | Guardrail Id |
guardrail_info | object or null | No | Guardrail Info |
guardrail_name | string | Yes | Guardrail Name |
spanway_params | BaseSpanwayParams or null | No | |
updated_at | string or null | No | Updated 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.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
guardrail_id | path | string | Yes |
Request body (application/json, schema PatchGuardrailRequest):
| Field | Type | Required | Description |
|---|---|---|---|
guardrail_info | object or null | No | Guardrail Info |
guardrail_name | string or null | No | Guardrail Name |
spanway_params | BaseSpanwayParams or null | No |
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:
| Status | Description | Body |
|---|---|---|
| 200 | The guardrail as stored. | application/json GuardrailInfoResponse |
| 400 | A destination field such as api_base changed while the stored secret was left out or sent back masked. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key is not a proxy admin. | application/json ErrorDetail |
| 404 | No guardrail has this id. | application/json ErrorDetail |
| 422 | The merged parameters do not initialize, so the stored guardrail keeps running unchanged. | application/json ErrorDetail |
| 500 | The gateway runs without a database, so stored guardrails cannot be read or changed. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
created_at | string or null | No | Created At |
guardrail_definition_location | GUARDRAIL_DEFINITION_LOCATION | No | |
guardrail_id | string or null | No | Guardrail Id |
guardrail_info | object or null | No | Guardrail Info |
guardrail_name | string | Yes | Guardrail Name |
spanway_params | BaseSpanwayParams or null | No | |
updated_at | string or null | No | Updated 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.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
guardrail_id | path | string | Yes |
Example request:
curl -X DELETE "http://localhost:4000/guardrails/guardrail_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The guardrail is gone from the database and from the running gateway. | application/json GuardrailDeletedResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The key is not a proxy admin. | application/json ErrorDetail |
| 404 | No guardrail has this id. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway runs without a database, so stored guardrails cannot be read or changed. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Message |
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.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
guardrail_id | path | string | Yes |
Example request:
curl -X GET "http://localhost:4000/guardrails/guardrail_id-123/info" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The guardrail as stored. | application/json GuardrailInfoResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 404 | No guardrail has this id. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The database or the guardrail integration raised an error. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
created_at | string or null | No | Created At |
guardrail_definition_location | GUARDRAIL_DEFINITION_LOCATION | No | |
guardrail_id | string or null | No | Guardrail Id |
guardrail_info | object or null | No | Guardrail Info |
guardrail_name | string | Yes | Guardrail Name |
spanway_params | BaseSpanwayParams or null | No | |
updated_at | string or null | No | Updated 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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
start_date | query | string or null | No | First 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_date | query | string or null | No | Last 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:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json UsageOverviewResponse |
| 400 | The dates are not YYYY-MM-DD, the end is before the start, or the range is longer than 366 days. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
chart | array of UsageChartPoint | Yes | Chart |
passRate | number | Yes | Passrate |
rows | array of UsageOverviewRow | Yes | Rows |
totalBlocked | integer | Yes | Totalblocked |
totalCost | number or null | Yes | Totalcost |
totalRequests | integer | Yes | Totalrequests |
totalUntrackedUsageUnits | object | Yes | Totaluntrackedusageunits |
totalUsageUnits | object | Yes | Totalusageunits |
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.
Example request:
curl -X GET "http://localhost:4000/v2/guardrails/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json ListGuardrailsResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 500 | The database could not be read. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
guardrails | array of GuardrailInfoResponse | Yes | Guardrails |