Audit & Compliance Reports
What Is the Audit Log?
Section titled “What Is the Audit Log?”Every AI request routed through AgentWatch is written to a durable audit log. The log captures who made the request, which model was used, what was sent and received (prompt + response), how many tokens were consumed, the cost, latency, DLP findings, and the final outcome. This creates a complete, queryable record for compliance audits (GDPR, HIPAA, SOX, PCI-DSS), security investigations, and cost chargebacks.
Audit records are stored in two complementary layers:
- Relational index — fast lookup by actor, organization, action type, and time range.
- Compressed NDJSON archives — full request/response payloads archived in
.ndjson.gzfiles; the relational row stores afilePath+lineOffsetpointer for O(1) retrieval.
Governance events (role, settings, SSO/SCIM, identity and policy events) are also written to a separate governance audit log, which from 2.0.412 is hash-chained — see Verifying the Audit Log Has Not Been Altered below. The request log (Usage Insights) is not chained.
What Each Audit Record Contains
Section titled “What Each Audit Record Contains”| Field | Description |
|---|---|
id |
Unique request identifier (UUID) |
timestamp |
UTC timestamp of the request |
tenantId |
API key / tenant that made the request |
tenantName |
Display name of the tenant |
tenantEmail |
Email of the user |
team |
Team the user belongs to |
model |
LLM model requested |
provider |
AI provider used (openai, anthropic, etc.) |
sessionId |
Conversation session identifier |
useCase |
Detected use-case category (e.g. code_assistance, code_review) |
promptTokens |
Input tokens consumed |
completionTokens |
Output tokens generated |
totalTokens |
Combined token count |
cost |
Calculated USD cost |
latencyMs |
End-to-end response time in milliseconds |
status |
completed, blocked, error, dlp_blocked |
source |
api, web-chat, or mcp |
dlpFindings |
Array of DLP detections (category, severity, score) |
ipAddress |
Client IP address |
Available Report Types
Section titled “Available Report Types”| Report | Description | Retention period (applied only when retention enforcement is enabled; off by default) |
|---|---|---|
| Request Audit Log | All AI requests with full field set above | 365 days |
| DLP Events | Requests where sensitive data was detected or blocked | 365 days |
| Cost Reports | Usage and cost aggregated by team, user, model, or provider | 180 days |
| Security Events | Authentication events, authorization failures, WAF blocks | 365 days |
Export Formats
Section titled “Export Formats”| Format | Use Case |
|---|---|
| JSON | Programmatic ingestion, SIEM integration |
| CSV | Spreadsheet analysis, finance chargebacks |
| An auditor’s report: cover (organization, period, filters, row counts, truncation), summary (requests by status, DLP findings by category, top users and models, governance events), then the record tables. Previews are the same scrubbed previews as JSON/CSV. Record tables list at most 10,000 rows per section; the summary counts every exported row. |
Audit Log Export Endpoint
Section titled “Audit Log Export Endpoint”GET /api/admin/audit/export
Query Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
format |
string | json |
json, csv or pdf |
days |
number | 30 |
Number of days back from today (1–365) |
provider |
string | all |
Filter by provider (openai, anthropic, etc.) |
source |
string | all |
Filter by source: api, web-chat, mcp, or all |
tagKey / tagValue |
string | — | Filter to requests carrying a usage tag with this key (and value) |
JSON export includes a records array plus a summary block:
{ "records": [ { ...audit fields... } ], "summary": { "totalRequests": 4821, "totalTokens": 12450000, "totalCost": 124.52, "byProvider": { "openai": { "requests": 3100, "cost": 89.11 }, "anthropic": { "requests": 1721, "cost": 35.41 } } }}CSV export columns: timestamp, tenant, team, provider, model, promptTokens, completionTokens, cost, latencyMs, status, source, dlpBlocked.
Response Headers: The server sets Content-Disposition: attachment; filename="agentwatch-audit-{days}d[-{source}]-YYYY-MM-DD.{json|csv|pdf}" so browsers download the file automatically.
Example:
# Export last 7 days of web chat audit logs as CSVcurl -H "Authorization: Bearer ak_admin_key" \ "https://agentwatch.yourcompany.com/api/admin/audit/export?format=csv&days=7&source=web-chat"
# Export the last 30 days as JSONcurl -H "Authorization: Bearer ak_admin_key" \ "https://agentwatch.yourcompany.com/api/admin/audit/export?format=json&days=30"
# The last 30 days as a PDF report for an auditorcurl -H "Authorization: Bearer ak_admin_key" -o audit-30d.pdf \ "https://agentwatch.yourcompany.com/api/admin/audit/export?format=pdf&days=30"Truncation: every format honours the 100,000-row export cap and says when it was reached (JSON complete: false, CSV banners, PDF cover notice and every page footer). The PDF additionally lists at most 10,000 record rows per section and states how many more the export holds.
Verifying the Audit Log Has Not Been Altered
Section titled “Verifying the Audit Log Has Not Been Altered”From 2.0.412 every governance audit entry stores prevHash (the hash of the previous entry in the same chain) and hash = SHA-256 over a canonical JSON of {id, timestamp, organizationId, actorId, actorEmail, action, targetType, targetId, ipAddress, metadata, prevHash} (keys sorted at every depth, no whitespace, UTF-8). Each organization has its own chain; entries with no organization form the platform chain.
GET /api/admin/audit/verify?organizationId=<org-id>
| Who | Scope |
|---|---|
| Organization admin | Their own organization (the parameter is ignored) |
| Super admin | Any organization, or organizationId=platform for the platform chain |
| Response field | Meaning |
|---|---|
ok |
Every chained entry was checked and held |
checked / chained |
Entries verified / entries carrying a hash |
legacyUnchained |
Entries written before chaining began (pre-2.0.412). Not tampered; not proven |
firstBreak |
{id, reason, expected, found} for the first failing entry, else null. Reasons include content_hash_mismatch (edited), missing_predecessor (deleted), fork, pointer_mismatch, record_missing, unchained_after_chain_start |
headHash / headId |
The newest entry. Record this outside the deployment |
prunedBoundary |
The chain starts after entries removed by a recorded retention sweep |
complete |
false if the chain was too long to load in one request (AW_AUDIT_VERIFY_MAX_ROWS); ok is then false |
What the chain proves: an entry that was edited, deleted from the middle, inserted or reordered is detected. What it does not prove: someone who controls the database and the audit files can recompute the entire chain, and deleting the newest entries leaves a valid shorter chain. Both are only detectable against a head hash recorded outside the deployment. Pass a recorded head back as ?expectHead=<hash>, or check it still appears in a later JSON export. AgentWatch also emits each chain’s head daily to the event pipeline (config.change with resource_name: "audit_chain_head") and the container log (audit-chain-anchor), and every JSON export carries auditChain.heads.
Retention: the sweep deletes audit entries oldest first and records the hash of the newest removed entry in its own chained retention.swept entry (metadata.auditChain.prunedThroughHashes). The verifier accepts a missing predecessor only when such an entry names it.
Offline verification: the JSON export carries id, actorId, actorEmail, prevHash and hash per governance record (details is the hashed metadata). The full algorithm and a reference Python implementation are on docs.iterate.ai → AgentWatch → Security & Compliance → Can I prove the audit log has not been altered?
Upgrade: 2.0.412 adds two nullable columns and a unique index on prev_hash at boot; no manual step. Existing entries stay unchained. With several replicas, the unique index makes a racing writer retry instead of forking the chain.
Step-by-Step: Running a Compliance Report
Section titled “Step-by-Step: Running a Compliance Report”- Navigate to Management → Audit Export.
- Set the Period (days) (up to 365 days back).
- Choose the Workspace and Source (All, API Only, Web Chat Only, MCP Only).
- Select Format (JSON for SIEM, CSV for spreadsheets, PDF report for an auditor).
- Click Download Export. The file downloads immediately.
- For scheduled exports, use the API endpoint with a cron job or SIEM connector.
API Reference
Section titled “API Reference”| Method | Endpoint | Description |
|---|---|---|
| GET | /api/admin/audit/export |
Download audit log export |
| GET | /api/admin/audit-logs |
Administrative audit log (settings changes, security events) |
| GET | /admin/audit/trail |
Paginated request audit trail |
| GET | /admin/audit/entry/:entryId |
One audit-trail entry in full |