Skip to main content

Audit logging API

This page documents the 5 gateway endpoints tagged audit logging in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.

MethodPathSummary
GET/audit/verifyVerify the audit log hash chain
POST/spend/logs/ui/{request_id}/revealReveal hidden fields of one request log
GET/audit/exportsList every data export
GET/auditList audit log rows
GET/audit/{id}Read one audit log row

Endpoints​

GET /audit/verify​

Verify the audit log hash chain

Checks that nobody edited or deleted audit log rows behind the gateway's back. Each audit row carries a hash of itself and of the row before it, so changing one row breaks the chain. This route walks the chain between since and until and reports the first row that does not verify. Read only, nothing changes.

Rows written before the hash chain was introduced carry no hash and are skipped. unhashed_rows counts rows without a hash written after the first hashed row of the window: the gateway writes one only when it could not extend the chain, so any other unhashed row was inserted directly into the database. The first row of the window must point at the newest hashed row written before since. When no such row survives (the window starts the chain, or retention purged older rows), the first row's previous_hash is accepted as the anchor and returned as chain_anchor, with truncated_before set when that anchor is not the genesis hash. Every later row must point at the row before it and carry a digest that recomputes.

Proxy admins, admin viewers and custom roles holding audit.read may run it, and it needs an enterprise license.

Docs

Parameters:

NameInTypeRequiredDescription
sincequerystring or nullNo
untilquerystring or nullNo

Example request:

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

Responses:

StatusDescriptionBody
200The verdict for the window, with the first row that fails when there is one.application/json AuditChainVerifyResponse
400since is later than until.application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller is not a proxy admin, an admin viewer or a custom role holding audit.read, or the gateway has no enterprise license.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway has no database, so there is no audit log to walk.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
validbooleanYesValid
rows_checkedintegerYesRows Checked
sincestring or nullYesSince
untilstring or nullYesUntil
chain_head_idstring or nullYesChain Head Id
chain_tail_idstring or nullYesChain Tail Id
chain_anchorstring or nullYesChain Anchor
truncated_beforebooleanYesTruncated Before
unhashed_rowsintegerYesUnhashed Rows
first_breakAuditChainBreakResponse or nullYes

POST /spend/logs/ui/{request_id}/reveal​

Reveal hidden fields of one request log

Shows the prompt, the response or the tool call arguments of one request log that your custom role hides, for example to answer a support ticket. You give a reason, and the reveal is written to the audit log as a revealed row with the fields, the reason, your address and your browser, before the content is returned.

Only callers whose custom role holds the logs.reveal permission may reveal, and only on logs they could already open. The route refuses when audit logging is off, and answers 503 without the content when the audit row cannot be stored, so no reveal goes unrecorded. Fields you did not ask for stay hidden, and so do the copies of the content kept in the log's metadata. Nothing in the log changes.

Docs (https://docs.spanway.ai/docs/proxy/data_access_governance#reveal)

Parameters:

NameInTypeRequiredDescription
request_idpathstringYes
start_datequerystring or nullNoWhen the request started, YYYY-MM-DD HH:MM:SS in UTC. Payload stores that file logs by day need it to find the log, so send the value the log detail view uses.
end_datequerystring or nullNoOptional end of the search window, same format.

Request body (application/json, schema RevealRequest):

FieldTypeRequiredDescription
fieldsarray of enum: "prompts", "responses", "tool_arguments"YesThe hidden fields to show: prompts, responses or tool_arguments.
reasonstringYesWhy you need to see the content. Stored in the audit log.

Example request:

curl -X POST "http://localhost:4000/spend/logs/ui/request_id-123/reveal" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"fields": [
"prompts"
],
"reason": "Customer ticket 4821 asks why the answer was cut"
}'

Responses:

StatusDescriptionBody
200The log with the requested fields shown. Fields you did not ask for stay hidden.application/json RevealedLog
400None of the requested fields is hidden for the caller.application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller's role lacks the logs.reveal permission.application/json ErrorDetail
404No log with this id is visible to the caller.application/json ErrorDetail
409Audit logging is off, so a reveal cannot be recorded.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
503The audit row for the reveal could not be stored, so nothing is shown.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
messagesJsonValueYesThe prompt as stored, or the hidden marker when it stays hidden.
responseJsonValueYesThe model's answer as stored, or the hidden marker.
proxy_server_requestJsonValueYesThe request body as received, or the hidden marker.
hidden_fieldsarray of enum: "prompts", "responses", "tool_arguments"YesFields that are still hidden after this reveal.
can_revealbooleanYesWhether the caller may reveal the fields that are still hidden.
revealed_fieldsarray of enum: "prompts", "responses", "tool_arguments"YesFields shown by this reveal and written to the audit log.

GET /audit/exports​

List every data export

Lists every export of usage, spend, run ledger or personal data that left the gateway, newest first: who ran it, when, from which address, with which filters, how many rows went out and whether the download finished. Use it to answer "who took a copy of this data" during an audit or after an incident. The ledger is read from the exported rows of the tamper-evident audit log, so it cannot be edited on its own. Read only.

Proxy admins, admin viewers and custom roles holding audit.read may call it, and it needs an enterprise license.

Docs (https://docs.spanway.ai/docs/proxy/data_access_governance#export-ledger)

Parameters:

NameInTypeRequiredDescription
sincequerystring or nullNoOnly exports at or after this time.
untilquerystring or nullNoOnly exports at or before this time.
exported_byquerystring or nullNoOnly exports by this user id.
pagequeryintegerNo
page_sizequeryintegerNo

Example request:

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

Responses:

StatusDescriptionBody
200One page of exports, newest first.application/json ExportLedgerPage
400since is later than until.application/json ErrorDetail
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller is not a proxy admin, an admin viewer or a custom role holding audit.read, or the gateway has no enterprise license.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway has no database, so there is no ledger to read.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
exportsarray of ExportLedgerEntryYesExports
totalintegerYesTotal
pageintegerYesPage
page_sizeintegerYesPage Size

GET /audit​

List audit log rows

Return one page of the management audit log, filtered by who changed what and when.

Every row says which object changed (table_name and object_id), the action, who made the change (changed_by and the hash of the key they used), the value before and after, and the hash chain fields previous_hash and entry_hash. Secrets are redacted before a row is written. Proxy admins and admin viewers may read the log, and so may a custom role holding audit.read. It needs an enterprise license. Billing fields of Cloud tenant rows are shown only to proxy admins.

Docs

Parameters:

NameInTypeRequiredDescription
pagequeryintegerNo
page_sizequeryintegerNo
changed_byquerystring or nullNoFilter by user or system that performed the action
changed_by_api_keyquerystring or nullNoFilter by API key hash that performed the action
actionqueryenum: "created", "updated", "deleted", "blocked", "unblocked", "rotated", "kill_switch_fired", "exported", ... or nullNoFilter by action, such as created, updated or viewed
table_namequerystring or nullNoFilter by table name that was modified
object_idquerystring or nullNoFilter by ID of the object that was modified
start_datequerystring or nullNoFilter logs after this date
end_datequerystring or nullNoFilter logs before this date
object_team_idquerystring or nullNoFilter by team_id present in before_value or updated_values JSON (PostgreSQL only)
object_key_hashquerystring or nullNoFilter by token (key hash) present in before_value or updated_values JSON (PostgreSQL only)
searchquerystring or nullNoMatch a row whose id, object_id, changed_by, or changed_by_api_key equals this value
sort_byqueryenum: "updated_at", "action", "table_name", "object_id", "changed_by"NoColumn to sort by
sort_orderqueryenum: "asc", "desc"NoSort order ('asc' or 'desc')

Example request:

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

Responses:

StatusDescriptionBody
200One page of audit rows, newest first by default.application/json PaginatedAuditLogResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller is not a proxy admin, an admin viewer or a custom role holding audit.read, or the gateway has no enterprise license.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway has no database, so there is no audit log to read.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
audit_logsarray of AuditLogResponseYesAudit Logs
totalintegerYesTotal number of audit logs matching the filters
pageintegerYesCurrent page number
page_sizeintegerYesNumber of items per page
total_pagesintegerYesTotal number of pages

GET /audit/{id}​

Read one audit log row

Return one audit row by its id, with the same fields and redaction rules as the list route.

Proxy admins, admin viewers and custom roles holding audit.read may read it, and it needs an enterprise license.

Docs

Parameters:

NameInTypeRequiredDescription
idpathstringYes

Example request:

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

Responses:

StatusDescriptionBody
200The audit row.application/json AuditLogResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The caller is not a proxy admin, an admin viewer or a custom role holding audit.read, or the gateway has no enterprise license.application/json ErrorDetail
404No audit row has this id.application/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError
500The gateway has no database, so there is no audit log to read.application/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
idstringYesId
updated_atstringYesUpdated At
changed_bystringYesChanged By
changed_by_api_keystringYesChanged By Api Key
actionstringYesAction
table_namestringYesTable Name
object_idstringYesObject Id
before_valueobject or nullNoBefore Value
updated_valuesobject or nullNoUpdated Values
previous_hashstring or nullNoPrevious Hash
entry_hashstring or nullNoEntry Hash