Skip to content

Events API

POST /api/events

Ingest a batch of events. Events are validated, assigned IDs, added to the session hash chain, and persisted atomically.

Request Body

json
{
  "events": [
    {
      "sessionId": "01HXYZ...",
      "agentId": "my-agent",
      "eventType": "tool_call",
      "severity": "info",
      "payload": {
        "toolName": "search",
        "callId": "c1",
        "arguments": { "query": "test" }
      },
      "metadata": {},
      "timestamp": "2026-02-08T10:00:00.000Z"
    }
  ]
}
FieldTypeRequiredDescription
eventsarrayArray of 1–1000 events
events[].sessionIdstringSession identifier
events[].agentIdstringAgent identifier
events[].eventTypestringOne of the 18 event types (see below)
events[].severitystringdebug / info / warn / error / critical (default: info)
events[].payloadobjectEvent-type-specific payload
events[].metadataobjectAdditional metadata (default: {})
events[].timestampstringISO 8601 timestamp (default: server time)

Event Types

TypePayload Fields
session_startedagentName?, agentVersion?, mcpClientInfo?, tags?
session_endedreason (completed/error/timeout/manual), summary?, totalToolCalls?, totalDurationMs?
tool_calltoolName, callId, arguments, serverName?
tool_responsecallId, toolName, result, durationMs
tool_errorcallId, toolName, error, errorCode?, durationMs
approval_requestedrequestId, action, params, urgency
approval_grantedrequestId, action, decidedBy, reason?
approval_deniedrequestId, action, decidedBy, reason?
approval_expiredrequestId, action, decidedBy, reason?
form_submittedsubmissionId, formId, formName?, fieldCount
form_completedsubmissionId, formId, completedBy, durationMs
form_expiredsubmissionId, formId, expiredAfterMs
llm_callcallId, provider, model, messages, systemPrompt?, parameters?, tools?, redacted?
llm_responsecallId, provider, model, completion, toolCalls?, finishReason, usage, costUsd, latencyMs, redacted?
cost_trackedprovider, model, inputTokens, outputTokens, totalTokens, costUsd, trigger?
alert_triggeredalertRuleId, alertName, condition, currentValue, threshold, message
alert_resolvedalertRuleId, alertName, resolvedBy?
customtype, data

Response (201)

json
{
  "ingested": 1,
  "events": [
    { "id": "01HXYZ...", "hash": "a1b2c3..." }
  ]
}

Errors

StatusCause
400Invalid JSON, validation error, or empty events array
500Storage error

curl Example

bash
curl -X POST http://localhost:3400/api/events \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer als_your_key" \
  -d '{
    "events": [{
      "sessionId": "sess_01",
      "agentId": "my-agent",
      "eventType": "tool_call",
      "payload": {
        "toolName": "search_database",
        "callId": "call_01",
        "arguments": { "query": "user records" }
      }
    }]
  }'

SDK Example

typescript
import { AgentLensClient } from '@agentlensai/sdk';

const client = new AgentLensClient({
  apiUrl: 'http://localhost:3400',
  apiKey: 'als_your_key',
});

await client.ingestEvents([{
  sessionId: 'sess_01',
  agentId: 'my-agent',
  eventType: 'tool_call',
  payload: {
    toolName: 'search_database',
    callId: 'call_01',
    arguments: { query: 'user records' },
  },
}]);

GET /api/events

Query events with flexible filters and pagination.

Query Parameters

ParameterTypeDescription
sessionIdstringFilter by session ID
agentIdstringFilter by agent ID
eventTypestringFilter by event type (comma-separated for multiple)
severitystringFilter by severity (comma-separated)
fromstringStart of time range (ISO 8601)
tostringEnd of time range (ISO 8601)
searchstringFull-text search in payloads
orderstringSort order: asc or desc (default: desc)
limitnumberResults per page (default: 50, max: 500)
offsetnumberPagination offset (default: 0)

Response (200)

json
{
  "events": [
    {
      "id": "01HXYZ...",
      "timestamp": "2026-02-08T10:00:00.000Z",
      "sessionId": "sess_01",
      "agentId": "my-agent",
      "eventType": "tool_call",
      "severity": "info",
      "payload": { "toolName": "search", "callId": "c1", "arguments": {} },
      "metadata": {},
      "prevHash": null,
      "hash": "a1b2c3..."
    }
  ],
  "total": 1234,
  "hasMore": true
}

curl Example

bash
# Get tool errors in the last 24 hours
curl "http://localhost:3400/api/events?eventType=tool_error&severity=error&from=2026-02-07T00:00:00Z" \
  -H "Authorization: Bearer als_your_key"

GET /api/events/:id

Get a single event by ID.

Response (200)

json
{
  "id": "01HXYZ...",
  "timestamp": "2026-02-08T10:00:00.000Z",
  "sessionId": "sess_01",
  "agentId": "my-agent",
  "eventType": "tool_call",
  "severity": "info",
  "payload": { "toolName": "search", "callId": "c1", "arguments": {} },
  "metadata": {},
  "prevHash": null,
  "hash": "a1b2c3..."
}

Errors

StatusCause
404Event not found

Released under the MIT License.