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.
| Method | Path | Summary |
|---|---|---|
| GET | /audit/verify | Verify the audit log hash chain |
| POST | /spend/logs/ui/{request_id}/reveal | Reveal hidden fields of one request log |
| GET | /audit/exports | List every data export |
| GET | /audit | List 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.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
since | query | string or null | No | |
until | query | string or null | No |
Example request:
curl -X GET "http://localhost:4000/audit/verify" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The verdict for the window, with the first row that fails when there is one. | application/json AuditChainVerifyResponse |
| 400 | since is later than until. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The 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 |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway has no database, so there is no audit log to walk. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
valid | boolean | Yes | Valid |
rows_checked | integer | Yes | Rows Checked |
since | string or null | Yes | Since |
until | string or null | Yes | Until |
chain_head_id | string or null | Yes | Chain Head Id |
chain_tail_id | string or null | Yes | Chain Tail Id |
chain_anchor | string or null | Yes | Chain Anchor |
truncated_before | boolean | Yes | Truncated Before |
unhashed_rows | integer | Yes | Unhashed Rows |
first_break | AuditChainBreakResponse or null | Yes |
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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
request_id | path | string | Yes | |
start_date | query | string or null | No | When 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_date | query | string or null | No | Optional end of the search window, same format. |
Request body (application/json, schema RevealRequest):
| Field | Type | Required | Description |
|---|---|---|---|
fields | array of enum: "prompts", "responses", "tool_arguments" | Yes | The hidden fields to show: prompts, responses or tool_arguments. |
reason | string | Yes | Why 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:
| Status | Description | Body |
|---|---|---|
| 200 | The log with the requested fields shown. Fields you did not ask for stay hidden. | application/json RevealedLog |
| 400 | None of the requested fields is hidden for the caller. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The caller's role lacks the logs.reveal permission. | application/json ErrorDetail |
| 404 | No log with this id is visible to the caller. | application/json ErrorDetail |
| 409 | Audit logging is off, so a reveal cannot be recorded. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 503 | The audit row for the reveal could not be stored, so nothing is shown. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
messages | JsonValue | Yes | The prompt as stored, or the hidden marker when it stays hidden. |
response | JsonValue | Yes | The model's answer as stored, or the hidden marker. |
proxy_server_request | JsonValue | Yes | The request body as received, or the hidden marker. |
hidden_fields | array of enum: "prompts", "responses", "tool_arguments" | Yes | Fields that are still hidden after this reveal. |
can_reveal | boolean | Yes | Whether the caller may reveal the fields that are still hidden. |
revealed_fields | array of enum: "prompts", "responses", "tool_arguments" | Yes | Fields 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:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
since | query | string or null | No | Only exports at or after this time. |
until | query | string or null | No | Only exports at or before this time. |
exported_by | query | string or null | No | Only exports by this user id. |
page | query | integer | No | |
page_size | query | integer | No |
Example request:
curl -X GET "http://localhost:4000/audit/exports" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | One page of exports, newest first. | application/json ExportLedgerPage |
| 400 | since is later than until. | application/json ErrorDetail |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The 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 |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway has no database, so there is no ledger to read. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
exports | array of ExportLedgerEntry | Yes | Exports |
total | integer | Yes | Total |
page | integer | Yes | Page |
page_size | integer | Yes | Page 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.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
page | query | integer | No | |
page_size | query | integer | No | |
changed_by | query | string or null | No | Filter by user or system that performed the action |
changed_by_api_key | query | string or null | No | Filter by API key hash that performed the action |
action | query | enum: "created", "updated", "deleted", "blocked", "unblocked", "rotated", "kill_switch_fired", "exported", ... or null | No | Filter by action, such as created, updated or viewed |
table_name | query | string or null | No | Filter by table name that was modified |
object_id | query | string or null | No | Filter by ID of the object that was modified |
start_date | query | string or null | No | Filter logs after this date |
end_date | query | string or null | No | Filter logs before this date |
object_team_id | query | string or null | No | Filter by team_id present in before_value or updated_values JSON (PostgreSQL only) |
object_key_hash | query | string or null | No | Filter by token (key hash) present in before_value or updated_values JSON (PostgreSQL only) |
search | query | string or null | No | Match a row whose id, object_id, changed_by, or changed_by_api_key equals this value |
sort_by | query | enum: "updated_at", "action", "table_name", "object_id", "changed_by" | No | Column to sort by |
sort_order | query | enum: "asc", "desc" | No | Sort order ('asc' or 'desc') |
Example request:
curl -X GET "http://localhost:4000/audit" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | One page of audit rows, newest first by default. | application/json PaginatedAuditLogResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The 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 |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway has no database, so there is no audit log to read. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
audit_logs | array of AuditLogResponse | Yes | Audit Logs |
total | integer | Yes | Total number of audit logs matching the filters |
page | integer | Yes | Current page number |
page_size | integer | Yes | Number of items per page |
total_pages | integer | Yes | Total 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.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
id | path | string | Yes |
Example request:
curl -X GET "http://localhost:4000/audit/id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The audit row. | application/json AuditLogResponse |
| 401 | No valid key or Admin UI session was presented | application/json ProxyError |
| 403 | The 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 |
| 404 | No audit row has this id. | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | The gateway has no database, so there is no audit log to read. | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Id |
updated_at | string | Yes | Updated At |
changed_by | string | Yes | Changed By |
changed_by_api_key | string | Yes | Changed By Api Key |
action | string | Yes | Action |
table_name | string | Yes | Table Name |
object_id | string | Yes | Object Id |
before_value | object or null | No | Before Value |
updated_values | object or null | No | Updated Values |
previous_hash | string or null | No | Previous Hash |
entry_hash | string or null | No | Entry Hash |