Skip to main content

Events API

POST /v1/audit

Ingest a new audit event.

Auth: X-API-Key header required.

POST http://localhost:8081/v1/audit
X-API-Key: bat_your_api_key
Content-Type: application/json

Request body:

{
"path": "/api/users/42",
"method": "PUT",
"status_code": 200,
"response_time": 87,
"identifier": "user-123",
"user_email": "alice@acme.com",
"user_name": "Alice Silva",
"user_roles": ["admin"],
"service_name": "users-api",
"environment": "production",
"tenant_id": "org-456",
"ip": "203.0.113.10",
"request_body": { "name": "Alice S." }
}

Responses:

CodeDescription
202Event accepted and queued
400Validation error — check response body for details
401Invalid or missing API key

GET /v1/audit

List audit events with optional filters.

Auth: JWT Bearer token required.

GET http://localhost:8082/v1/audit?service_name=users-api&status_code=500&limit=50
Authorization: Bearer <jwt>

Query parameters:

ParamTypeDescription
pageintPage number (default: 1)
limitintItems per page (default: 20, max: 100)
project_idstringFilter by project
service_namestringFilter by service
methodstringFilter by HTTP method
status_codeintFilter by status code
environmentstringFilter by environment
identifierstringFilter by user/client ID
start_dateISO 8601Events from this date
end_dateISO 8601Events until this date
sort_bystringField to sort by (default: timestamp)
sort_orderstringasc or desc (default: desc)
event_typestringhttp or system.alert

Response:

{
"data": [
{
"id": "uuid",
"event_type": "http",
"method": "PUT",
"path": "/api/users/42",
"status_code": 200,
"response_time": 87,
"identifier": "user-123",
"user_email": "alice@acme.com",
"service_name": "users-api",
"environment": "production",
"timestamp": "2024-01-15T14:32:00Z"
}
],
"pagination": {
"page": 1,
"limit": 20,
"totalItems": 1432,
"totalPage": 72
}
}

GET /v1/audit/:id

Get the full detail of a single event, including request_body, query_params, path_params, user_agent, and all metadata.

Auth: JWT Bearer token required.

GET http://localhost:8082/v1/audit/550e8400-e29b-41d4-a716-446655440000
Authorization: Bearer <jwt>

GET /v1/audit/stats

Returns aggregate metrics for the current project.

Auth: JWT Bearer token required.

Response:

{
"total": 14320,
"errors_4xx": 423,
"errors_5xx": 12,
"avg_response_time": 94.3,
"p95_response_time": 412.0,
"active_services": 4,
"last_event_at": "2024-01-15T14:32:00Z",
"by_service": [...],
"by_status_class": { "2xx": 13885, "4xx": 423, "5xx": 12 },
"by_method": { "GET": 9200, "POST": 3100, "PUT": 1800, "DELETE": 220 },
"timeline": [...]
}

GET /v1/audit/orphans

Returns browser-side events with no matching backend response. Requires the Browser SDK.

Auth: JWT Bearer token required.