SidClaw

Trace Endpoints

Query, export, and verify the integrity of audit traces that record every governed agent action.

Trace Endpoints

Every call to /evaluate creates an audit trace -- a complete, immutable record of the governance decision lifecycle. Traces contain ordered events covering identity resolution, policy evaluation, approval decisions, and execution outcomes. Each event is integrity-hashed to form a tamper-evident chain.

Endpoint Summary

MethodPathDescriptionAuth
GET/api/v1/tracesList traces with filtersAny
GET/api/v1/traces/:idGet trace detail with eventsAny
POST/api/v1/traces/:traceId/outcomeRecord execution outcomeAny
GET/api/v1/traces/:traceId/verifyVerify trace integrityAny
GET/api/v1/traces/:traceId/exportExport single trace as JSONReviewer, Admin
GET/api/v1/traces/exportBulk export traces as CSVReviewer, Admin
GET/api/v1/audit/exportSIEM-ready audit event exportReviewer, Admin

GET /api/v1/traces

List audit traces with optional filters and pagination.

Auth: API key with traces:read scope, or any authenticated session.

Query Parameters

ParameterTypeDescription
agent_idstringFilter by agent UUID
outcomestringFilter by final outcome (pending, executed, blocked, denied, completed_with_approval, expired)
fromstringISO 8601 date -- only traces started at or after this time
tostringISO 8601 date -- only traces started at or before this time
limitintegerItems per page (default: 20, max: 100)
offsetintegerNumber of items to skip (default: 0)

Response

Status: 200 OK

{
  "data": [
    {
      "id": "550e8400-...",
      "agent_id": "550e8400-...",
      "agent_name": "deploy-agent",
      "authority_model": "delegated",
      "requested_operation": "deploy",
      "target_integration": "aws",
      "resource_scope": "production/*",
      "final_outcome": "completed_with_approval",
      "started_at": "2026-03-21T10:00:00.000Z",
      "completed_at": "2026-03-21T10:15:00.000Z",
      "duration_ms": 900000,
      "event_count": 8,
      "has_approval": true
    }
  ],
  "pagination": {
    "total": 42,
    "limit": 20,
    "offset": 0
  }
}

Response Fields (list item)

FieldTypeDescription
idstringTrace UUID
agent_idstringAgent UUID
agent_namestringAgent display name
authority_modelstringAgent authority model at time of evaluation
requested_operationstringThe operation that was evaluated
target_integrationstringThe integration that was accessed
resource_scopestringThe resource scope
final_outcomestringOne of: in_progress, executed, blocked, denied, completed_with_approval, expired
started_atstringISO 8601 timestamp
completed_atstring | nullISO 8601 timestamp, null if still in progress
duration_msnumber | nullDuration in milliseconds, null if not completed
event_countnumberNumber of events in this trace
has_approvalbooleanWhether this trace has an associated approval request

Example

curl "http://localhost:4000/api/v1/traces?agent_id=550e8400-...&outcome=blocked&from=2026-03-01T00:00:00Z&to=2026-03-21T23:59:59Z" \
  -H "Authorization: Bearer sk_live_abc123"

GET /api/v1/traces/:id

Get full trace detail including all ordered events and associated approval requests.

Auth: API key with traces:read scope, or any authenticated session.

Path Parameters

ParameterTypeDescription
idstringTrace UUID

Response

Status: 200 OK

{
  "id": "550e8400-...",
  "agent_id": "550e8400-...",
  "agent_name": "deploy-agent",
  "authority_model": "delegated",
  "requested_operation": "deploy",
  "target_integration": "aws",
  "resource_scope": "production/*",
  "parent_trace_id": null,
  "final_outcome": "completed_with_approval",
  "started_at": "2026-03-21T10:00:00.000Z",
  "completed_at": "2026-03-21T10:15:00.000Z",
  "duration_ms": 900000,
  "events": [
    {
      "id": "evt-001",
      "event_type": "trace_initiated",
      "actor_type": "agent",
      "actor_name": "deploy-agent",
      "description": "Agent initiated deploy operation on aws",
      "status": "started",
      "timestamp": "2026-03-21T10:00:00.000Z",
      "policy_version": null,
      "approval_request_id": null,
      "metadata": null,
      "integrity_hash": "sha256:abc123..."
    }
  ],
  "approval_requests": [
    {
      "id": "770e8400-...",
      "status": "approved",
      "approver_name": "Bob Smith",
      "decided_at": "2026-03-21T10:10:00.000Z"
    }
  ]
}

Event Fields

FieldTypeDescription
idstringEvent UUID
event_typestringType of event (see below)
actor_typestringOne of: agent, policy_engine, approval_service, human_reviewer, system
actor_namestringDisplay name of the actor
descriptionstringHuman-readable event description
statusstringEvent-specific status
timestampstringISO 8601 timestamp
policy_versionnumber | nullPolicy version at time of evaluation
approval_request_idstring | nullAssociated approval request, if any
metadataobject | nullEvent-specific metadata
integrity_hashstring | nullSHA-256 integrity hash (chained)

Event Types

Event TypeDescription
trace_initiatedAgent started an operation
identity_resolvedAgent identity was resolved
policy_evaluatedPolicy engine evaluated the request
sensitive_operation_detectedOperation flagged as sensitive
approval_requestedApproval request was created
approval_grantedApproval was granted by a reviewer
approval_deniedApproval was denied by a reviewer
operation_allowedOperation was allowed to proceed
operation_executedOperation completed successfully
operation_deniedOperation was blocked
operation_failedOperation execution failed
trace_closedTrace was finalized

Example

curl http://localhost:4000/api/v1/traces/550e8400-e29b-41d4-a716-446655440000 \
  -H "Authorization: Bearer sk_live_abc123"

Error Codes

StatusErrorDescription
404not_foundTrace does not exist

POST /api/v1/traces/:traceId/outcome

Record the execution outcome after an agent operation completes (or fails). This finalizes the trace.

Auth: API key with traces:write scope, or any authenticated session.

Path Parameters

ParameterTypeDescription
traceIdstringTrace UUID

Request Body

FieldTypeRequiredDescription
statusstringYesOne of: success, error
metadataobjectNoAdditional outcome metadata

Response

Status: 204 No Content

Side Effects

  • Creates an operation_executed or operation_failed audit event.
  • Creates a trace_closed event.
  • Updates the trace final_outcome to executed, completed_with_approval, or blocked depending on the status and whether an approval was involved.
  • Dispatches a webhook with event type trace.completed.

Example

curl -X POST http://localhost:4000/api/v1/traces/550e8400-e29b-41d4-a716-446655440000/outcome \
  -H "Authorization: Bearer sk_live_abc123" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "success",
    "metadata": {
      "deployment_id": "deploy-12345",
      "region": "us-east-1"
    }
  }'

Error Codes

StatusErrorDescription
400validation_errorInvalid status value
404not_foundTrace does not exist
409conflictTrace is already finalized (outcome already recorded)

GET /api/v1/traces/:traceId/verify

Verify the integrity of a trace's event hash chain. Each event contains a SHA-256 hash that chains to the previous event, forming a tamper-evident log.

Auth: API key with traces:read scope, or any authenticated session.

Path Parameters

ParameterTypeDescription
traceIdstringTrace UUID

Response

Status: 200 OK

{
  "trace_id": "550e8400-...",
  "valid": true,
  "event_count": 8,
  "verified_at": "2026-03-21T12:00:00.000Z"
}

If the chain is broken:

{
  "trace_id": "550e8400-...",
  "valid": false,
  "event_count": 8,
  "first_invalid_event": "evt-005",
  "verified_at": "2026-03-21T12:00:00.000Z"
}

Example

curl http://localhost:4000/api/v1/traces/550e8400-e29b-41d4-a716-446655440000/verify \
  -H "Authorization: Bearer sk_live_abc123"

GET /api/v1/traces/:traceId/export

Export a single trace as a JSON file with full event and approval data.

Auth: API key with admin scope, or session with reviewer or admin role.

Path Parameters

ParameterTypeDescription
traceIdstringTrace UUID

Response

Status: 200 OK

Content-Type: application/json

Content-Disposition: attachment; filename="trace-{traceId}.json"

{
  "trace": {
    "id": "550e8400-...",
    "agent_id": "550e8400-...",
    "agent_name": "deploy-agent",
    "authority_model": "delegated",
    "requested_operation": "deploy",
    "target_integration": "aws",
    "resource_scope": "production/*",
    "parent_trace_id": null,
    "final_outcome": "completed_with_approval",
    "started_at": "2026-03-21T10:00:00.000Z",
    "completed_at": "2026-03-21T10:15:00.000Z",
    "duration_ms": 900000
  },
  "events": [ ... ],
  "approval_requests": [
    {
      "id": "770e8400-...",
      "status": "approved",
      "flag_reason": "Confidential data access",
      "approver_name": "Bob Smith",
      "decision_note": "Approved for Q4 deployment",
      "decided_at": "2026-03-21T10:10:00.000Z"
    }
  ],
  "exported_at": "2026-03-21T12:00:00.000Z"
}

Example

curl http://localhost:4000/api/v1/traces/550e8400-e29b-41d4-a716-446655440000/export \
  -H "Authorization: Bearer sk_live_abc123" \
  -o trace-export.json

Error Codes

StatusErrorDescription
403forbiddenReviewer or admin role/scope required
404not_foundTrace does not exist

GET /api/v1/traces/export

Bulk export traces as CSV for a given date range.

Auth: API key with admin scope, or session with reviewer or admin role.

Query Parameters

ParameterTypeRequiredDescription
fromstringYesISO 8601 start date
tostringYesISO 8601 end date
formatstringYesMust be csv
agent_idstringNoFilter by agent UUID

Response

Status: 200 OK

Content-Type: text/csv

Content-Disposition: attachment; filename="audit-{from}-to-{to}.csv"

X-Total-Count: Total number of exported rows.

CSV columns:

trace_id,agent_id,agent_name,operation,target_integration,resource_scope,
data_classification,final_outcome,started_at,completed_at,duration_ms,
approval_required,approver_name,approval_decision,approval_decided_at,
policy_rule_id,policy_version

Example

curl "http://localhost:4000/api/v1/traces/export?from=2026-03-01T00:00:00Z&to=2026-03-21T23:59:59Z&format=csv" \
  -H "Authorization: Bearer sk_live_abc123" \
  -o audit-export.csv

Error Codes

StatusErrorDescription
400validation_errorMissing from/to params, invalid date format, or unsupported format
403forbiddenReviewer or admin role/scope required
413export_too_largeExport exceeds 100,000 traces -- narrow the date range

GET /api/v1/audit/export

SIEM-ready export of individual audit events (not traces). Supports both JSON and CSV formats.

Auth: API key with admin scope, or session with reviewer or admin role.

Query Parameters

ParameterTypeRequiredDescription
fromstringYesISO 8601 start date
tostringYesISO 8601 end date
formatstringNojson (default) or csv

Response (JSON format)

Status: 200 OK

Content-Type: application/json

X-Total-Count: Total number of exported events.

[
  {
    "event_id": "evt-001",
    "trace_id": "550e8400-...",
    "agent_id": "550e8400-...",
    "event_type": "trace_initiated",
    "actor_type": "agent",
    "actor_name": "deploy-agent",
    "description": "Agent initiated deploy operation on aws",
    "status": "started",
    "timestamp": "2026-03-21T10:00:00.000Z",
    "policy_version": null,
    "integrity_hash": "sha256:abc123..."
  }
]

Response (CSV format)

Content-Type: text/csv

CSV columns:

event_id,trace_id,agent_id,event_type,actor_type,actor_name,description,
status,timestamp,policy_version,integrity_hash

Example

# JSON format
curl "http://localhost:4000/api/v1/audit/export?from=2026-03-21T00:00:00Z&to=2026-03-21T23:59:59Z&format=json" \
  -H "Authorization: Bearer sk_live_abc123" \
  -o audit-events.json

# CSV format
curl "http://localhost:4000/api/v1/audit/export?from=2026-03-21T00:00:00Z&to=2026-03-21T23:59:59Z&format=csv" \
  -H "Authorization: Bearer sk_live_abc123" \
  -o audit-events.csv

Error Codes

StatusErrorDescription
400validation_errorMissing from/to params, invalid date format, or unsupported format
403forbiddenReviewer or admin role/scope required
413export_too_largeExport exceeds 100,000 events -- narrow the date range