Skip to main content

Data access governance

Request logs hold your customers' conversations, and usage reports show what every team spends. Data access governance answers three questions an auditor or a privacy officer will ask about that data. Who looked at it? Who was allowed to see the words of a conversation, and who only the numbers? Who took a copy out of the gateway? The gateway answers the first with read audit events, the second with field level access on custom roles and an audited reveal, and the third with the export ledger. Everything lands in the same tamper-evident audit log, so a reader cannot quietly remove the trace of their own reading.

These features need Spanway Enterprise: the audit log and the export ledger need the license, and hiding fields needs the custom_roles feature.

A real-world scenario​

A support team of twelve uses the Logs page to check cost, latency and errors for customer tickets. The privacy officer does not want all twelve reading customer prompts. A proxy admin gives the team a custom role that denies logs.prompts and logs.responses, and gives the two team leads a second role that also grants logs.reveal. Now an agent opening a request sees the timing, tokens and cost, with [hidden by your role] where the conversation would be. When ticket 4821 needs the actual answer, a team lead clicks Reveal, types "Customer ticket 4821 asks why the answer was cut" and sees the content. The audit log gets a revealed row with the lead's name, the reason, the request id, the address and the browser. At the quarterly review the privacy officer filters the audit log on Action = Revealed and reads every reason, then opens the Export Ledger tab to see who downloaded usage data that quarter.

Read audit events​

A read audit event is an audit row with the action viewed. It records who read data, never the data itself.

What was readWhen a row is writtenTableobject_id
The prompt and response of one request, as the Logs page drawer opens it (GET /spend/logs/ui/{request_id})Always, unless audit_log_content_reads is falseSpanway_SpendLogsThe request id
Spend log rows with prompts and responses from GET /spend/logsAlways, unless audit_log_content_reads is falseSpanway_SpendLogs/spend/logs
A page of the request list (GET /spend/logs/ui, GET /spend/logs/v2, GET /spend/logs/session/ui)Only when audit_log_list_reads is trueSpanway_SpendLogsThe route
A usage or spend report on the Usage page (the /daily/activity routes for teams, users, tags, organizations and agents)Only when audit_log_list_reads is trueSpanway_DailySpendThe route

Each row's after value holds read (request_content, request_logs or spend_report), the caller's role, ip and user_agent, and, where they apply, the filters of the read, the row_count returned and the hidden_fields the caller's role kept out of view. The address is taken from the forwarded header only when the request came through one of your trusted reverse proxies, and the user agent is cut to 256 characters with control characters removed, so a caller cannot forge audit lines. Rows are written in the background and never slow down or fail the read. Lists never carry prompts or responses, which is why only content reads are recorded by default.

Turn read auditing on or off​

  1. Make sure audit logging is on. Read events are audit rows, so nothing is recorded without it.
  2. In the Admin UI, open Settings > Admin Settings > Security Settings and find the Data access auditing card.
  3. Record every time someone opens a prompt or response is the audit_log_content_reads setting. It helps you prove who read customer conversations. When on, each opened request writes one viewed row. When off, those reads leave no trace, which many privacy reviews will not accept. It is on by default and costs one small audit row per opened request.
  4. Also record every list of logs and every usage report is the audit_log_list_reads setting. It gives a complete trail for organisations that must log every access to personal or financial data. When on, each page of the request list and each Usage report writes a viewed row. When off, only content reads, reveals and exports are recorded. It is off by default because these pages refresh often and can add many rows a day.
  5. Click Save. The change applies to new reads at once. Only proxy admins can change these settings, and each save writes its own updated row on Spanway_Config.

The same settings in config.yaml:

general_settings:
audit_log_content_reads: true
audit_log_list_reads: true

Or over the API, one call per setting:

curl -X POST "http://localhost:4000/config/field/update" \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"config_type": "general_settings", "field_name": "audit_log_list_reads", "field_value": true}'

Expected result: the call answers 200, and the next time anyone opens the Logs page a viewed row with read request_logs appears in Logs > Audit Logs.

Find who read a request​

  1. Open Logs, then Audit Logs, click Filters, choose Action = Viewed and enter the request id as Object ID.

  2. Or call the audit log API:

    curl "http://localhost:4000/audit?action=viewed&object_id=chatcmpl-7f2d1c" \
    -H "Authorization: Bearer $SPANWAY_API_KEY"

    Expected result, one row per read:

    {
    "audit_logs": [
    {
    "action": "viewed",
    "table_name": "Spanway_SpendLogs",
    "object_id": "chatcmpl-7f2d1c",
    "changed_by": "maria@example.com",
    "updated_values": {"read": "request_content", "hidden_fields": ["prompts", "responses"], "role": "internal_user", "ip": "203.0.113.24", "user_agent": "Mozilla/5.0"}
    }
    ],
    "total": 1,
    "page": 1,
    "page_size": 50,
    "total_pages": 1
    }

Hide prompts, responses and tool arguments by role​

A custom role can keep the sensitive parts of a request log out of view while the rest of the log stays readable. Deny one or more of these permissions on the role:

PermissionWhat it hides when denied
logs.promptsThe prompt (messages), the request body as received (proxy_server_request), and every copy of the prompt kept in the log's metadata: what a guardrail checked (guardrail_request) and what it said about it, the vector store search query, prompt template variables, the routing words quoted from the prompt, and the error message and traceback, which can repeat the input.
logs.responsesThe model's answer (response), the result an MCP tool returned, the vector store search results and what a guardrail said about the answer.
logs.tool_argumentsOnly the arguments of tool calls, inside the prompt, the answer, the request body and the guardrail copies: chat arguments, Responses function_call arguments, Messages tool_use input and the arguments of every MCP tool call the gateway ran. Use it when tools carry account numbers or other personal data but the conversation itself may be read.

A hidden field reads [hidden by your role]. Cost, tokens, timing, model, status, guardrail names and outcomes, and the rest of the metadata are never hidden. The response of GET /spend/logs/ui/{request_id} then also carries hidden_fields, the list of fields kept out, and can_reveal, whether the caller may reveal them. Every other route that returns log content masks the same fields: GET /spend/logs, the request list (GET /spend/logs/ui and GET /spend/logs/v2), the session view (GET /spend/logs/session/ui) and the guardrail Logs tab (GET /guardrails/usage/logs), whose input and output snippets and reason read [hidden by your role] when they would quote hidden content. Callers without a custom role, and every role on a gateway without the custom_roles license feature, see the logs as before. When the gateway cannot read the caller's role, for example because the database is briefly unreachable, it hides all three fields rather than show them, and logs a warning.

Lens follows the same role. Agent run steps (GET /v1/traces, GET /v1/traces/{trace_id}, GET /v1/traces/{trace_id}/spans/{span_id} and its error page) show [hidden by your role] in place of hidden inputs, outputs, previews, error text and the span attributes that can quote them. A trace step does not say which part of its input is a tool argument, so denying logs.tool_arguments hides step inputs too. Trace search never looks inside hidden content, a session thread returns hidden inputs and outputs as null, and trace SQL (POST /v1/traces/query) is refused for such a role, see trace search and sessions. The audited reveal covers request logs only, so a role that must read run content needs that content allowed.

Set it up​

  1. Open Roles under ACCESS CONTROL in the left nav and click Create Role, or edit an existing role.
  2. Pick the base role, for example internal_user, which can already open the Logs page for its own keys and teams.
  3. In the permission list, set logs.prompts and logs.responses to Deny (and logs.tool_arguments if you want). Each permission's help text explains what denying it does.
  4. For the people who may look at content when a ticket needs it, create a second role with the same denials that also sets logs.reveal to Grant.
  5. Click Save and assign the roles to users on the Internal Users page.

The same role over the API:

curl -X POST "http://localhost:4000/role/new" \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" \
-H "Content-Type: application/json" \
-d '{"role_name": "support_lead", "base_role": "internal_user", "permissions": ["logs.reveal"], "denied_permissions": ["logs.prompts", "logs.responses"]}'

Expected result: a user with the role who opens a request on the Logs page sees a notice "Your role hides the prompts, responses of this request" above the request, and [hidden by your role] in the Request & Response section.

Reveal a hidden field​

A reveal shows the hidden content of one request to a person whose role grants logs.reveal, after they give a reason, and records it. It is meant for the moments the job really needs the words, such as a support ticket or an incident.

  1. Open Logs and click a request. The notice above the request says which fields your role hides.
  2. Click Reveal, tick the fields you need (fields you leave unticked stay hidden), and type the reason, at least 10 characters.
  3. Click Reveal and record. The content appears in the drawer for this request only. Opening another request, or the same one later, shows it hidden again. A reveal shows the prompt, the answer and the request body. The copies kept in the metadata, such as guardrail inputs and MCP tool arguments, stay hidden.

Over the API:

curl -X POST "http://localhost:4000/spend/logs/ui/chatcmpl-7f2d1c/reveal?start_date=2026-11-21%2009:00:00" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"fields": ["prompts"], "reason": "Customer ticket 4821 asks why the answer was cut"}'

Expected result:

{
"messages": [{"role": "user", "content": "Where is my order 48213?"}],
"response": "[hidden by your role]",
"proxy_server_request": {"model": "claude-sonnet-5-5"},
"hidden_fields": ["responses"],
"can_reveal": true,
"revealed_fields": ["prompts"]
}

start_date is when the request started, as YYYY-MM-DD HH:MM:SS in UTC. It is optional, but a payload store that files logs by day, such as a GCS bucket, needs it to find the request, so the Admin UI always sends it.

Before the content is returned, the gateway writes a revealed audit row on Spanway_SpendLogs with the request id as object_id and read, revealed_fields, reason, role, ip and user_agent in the after value. The row is written even when audit_log_content_reads is off, and the route refuses to reveal anything when audit logging is off. The row is written while you wait, and if the database cannot store it the route answers 503 and shows nothing, so no reveal goes unrecorded. A reveal only works on a request the caller could already open, and nothing in the stored log changes.

Export ledger​

The export ledger lists every copy of data that left the gateway, newest first: who took it, when, from which address and browser, with which filters, how many rows went out and whether the download finished. It is read from the exported rows of the audit log, so it is as tamper-evident as the log itself and needs no table of its own.

These exports write a ledger line:

ExportexportRows countedWhere it starts
Usage download for a team, user, tag, organization or agentteam_daily_activity, user_daily_activity and so onEvery row streamed, and completed is false when the download stopped early, for example because the browser closedUsage page Export Data, GET /team/daily/activity/export and the other entities
Run ledger JSONrun_ledgerLedger entriesRun Ledger page Export JSON, GET /run_ledger/{run_id}/export
Data subject access exportdata_subjectRecords in the bundle, such as keys and spend logsCompliance > Data Subject Requests, POST /compliance/data_subject/export
Invoice CSVbilling_invoiceInvoice line itemsBilling page invoice download, GET /billing/invoice/export
CloudZero and Vantage manual exports, workflow history reads with content, environment exports, compliance evidence bundles, Cloud tenant exports and review exportsThe table nameNot recordedTheir own pages, see audit logs

For the last group the ledger shows the values the row already stored as filters, for example the time window and destination of a Vantage export.

Read the ledger​

  1. Sign in as a proxy admin or admin viewer, open Logs and click the Export Ledger tab.
  2. Read the table: When, Who, Export, Destination, Rows, Finished (Yes, No, stopped early or Not recorded), Filters and Address.
  3. Type a user id into Filter by user id to see one person's exports, and use Previous and Next to page.

Over the API:

curl "http://localhost:4000/audit/exports?since=2026-11-01T00:00:00Z&exported_by=maria@example.com" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Expected result:

{
"exports": [
{
"audit_id": "6c1e0d6a-1f0b-4c55-9f2e-0b9d4a7e3c11",
"exported_at": "2026-11-21T09:14:02.118Z",
"exported_by": "maria@example.com",
"api_key_hash": "88dc28d0f030c55ed4ab77ed8faf098196cb1c05df778539800c9f1243fe6b4b",
"export": "team_daily_activity",
"object_id": "spanway_dailyteamspend",
"destination": "download",
"filters": {"entity": "team", "entity_ids": ["team-support"], "start_date": "2026-11-01"},
"row_count": 30,
"completed": true,
"ip": "203.0.113.24",
"user_agent": "Mozilla/5.0"
}
],
"total": 1,
"page": 1,
"page_size": 50
}

GET /audit/exports takes since, until, exported_by, page and page_size (up to 100). Erasing a person's data with a data subject request does not reach copies that were already exported, which is exactly what the ledger helps you follow up: it tells you who holds a copy, so you can ask them to delete it.

Errors​

StatusWhereMessageMeaningFix
400POST /spend/logs/ui/{request_id}/revealNone of the requested fields are hidden for your role, so there is nothing to revealYour role already shows the fields you asked for.Open the request normally.
403POST /spend/logs/ui/{request_id}/revealYour role may not reveal hidden log fields. Ask an admin for the logs.reveal permissionYour role hides the field but does not grant logs.reveal.Ask a proxy admin to add logs.reveal to your role.
404POST /spend/logs/ui/{request_id}/revealNo request log with this id is visible to youThe request does not exist, or it belongs to a key or team you may not read.Check the request id on the Logs page.
409POST /spend/logs/ui/{request_id}/revealRevealing a hidden field needs audit logging turned on, so the reveal can be recordedAudit logging is off, so a reveal could not be recorded.Turn on store_audit_logs, see audit logs.
422POST /spend/logs/ui/{request_id}/revealreason must not contain control characters, reason must be at least 10 characters besides spaces, or a reason over 500 charactersThe reason is missing, too short, too long (over 500) or has control characters, fields names something other than prompts, responses or tool_arguments, or start_date is not YYYY-MM-DD HH:MM:SS.Send a plain sentence as the reason, only those field names and the start time in that format.
503POST /spend/logs/ui/{request_id}/revealThe reveal could not be written to the audit log, so the content stays hidden. Try again in a momentThe database did not store the revealed row, for example because it timed out, so the gateway kept the content hidden.Try again. If it keeps failing, check the database connection and the Failed Creating audit log lines in the gateway log.
400GET /audit/exportssince must not be later than untilThe time window is inverted.Swap the two values.
403GET /audit/exportsAdmin-only endpoint. Not allowed to access this.The caller is not a proxy admin or admin viewer.Use an admin key. The tab is hidden from other roles.
403GET /audit/exportsThe export ledger needs a Spanway enterprise license. ...The gateway has no valid license.Add a license.
500GET /audit/exportsDB not connected. ...The gateway runs without a database.Set DATABASE_URL.

Logs​

LevelLineMeaning
WARNINGCould not read the custom role of <user id>, hiding log content: <error>The gateway could not load the caller's custom role, so it hid prompts, responses and tool arguments for that read instead of showing them. Rare and harmless once. If it repeats, check the database connection.
ERRORFailed Creating audit log <error>A viewed, revealed or exported row could not be written to the hash chain. The gateway then tries to store it without a hash. A view or export is still served. A reveal is refused with a 503 when neither write worked. Check the database.
ERRORFailed Creating unchained audit log <error>The fallback write failed too, so the row is lost. A reveal was refused. Check the database.