API Reference

Events

Ingest telemetry events from your AI agent into Trenchcoat.

POST /api/v1/events

Ingest a batch of telemetry events. This is the primary write endpoint used by the Trenchcoat plugin.

Required scope: write:events

Batch limit: Up to 1,000 events per request.


Request

curl -X POST https://app.trenchcoat.com/api/v1/events \
  -H "X-API-Key: ct_live_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6" \
  -H "Content-Type: application/json" \
  -d '{
    "events": [
      {
        "event_type": "session_start",
        "session_id": "550e8400-e29b-41d4-a716-446655440000",
        "timestamp": "2024-01-15T10:30:00Z",
        "data": {}
      },
      {
        "event_type": "tool_use",
        "session_id": "550e8400-e29b-41d4-a716-446655440000",
        "timestamp": "2024-01-15T10:30:15Z",
        "data": {
          "tool_name": "Read",
          "tool_input_preview": "/src/components/dashboard/Sidebar.tsx"
        }
      }
    ]
  }'

Request Body

The body must be a JSON object with a single events array.

{
  "events": [
    {
      "event_type": "tool_use",
      "session_id": "550e8400-e29b-41d4-a716-446655440000",
      "timestamp": "2024-01-15T10:30:00Z",
      "data": {
        "tool_name": "Read",
        "tool_input_preview": "/src/components/dashboard/Sidebar.tsx"
      }
    }
  ]
}
FieldTypeRequiredDescription
event_typestringYesType of event (see valid values below)
session_idstring (UUID)YesThe Claude Code session this event belongs to
timestampstring (ISO 8601)YesWhen the event occurred
dataobjectNoEvent-specific payload; shape varies by event_type

Event Types

ValueWhen it fires
session_startA new Claude Code session begins
session_endThe session ends (user exits or session times out)
tool_useClaude invokes a tool (Read, Edit, Bash, etc.)
tool_resultThe result of a tool invocation is returned to Claude
subagent_stopA spawned subagent finishes
assistant_stopClaude finishes a response turn

Events within a session should share the same session_id. The session_start event implicitly creates the session record; subsequent events are associated with it.


Responses

Success — 200

{
  "data": {
    "accepted": 42,
    "rejected": 0
  }
}

accepted is the count of events written to the database. rejected is the count of events that failed validation and were dropped. Individual rejection reasons are not returned per event; fix validation errors (see below) and retry.

Validation Error — 400

Returned when the request body is malformed or required fields are missing.

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Request body is invalid.",
    "details": [
      {
        "field": "events[0].session_id",
        "message": "Invalid UUID format"
      },
      {
        "field": "events[2].event_type",
        "message": "Invalid enum value. Expected one of: session_start, session_end, tool_use, tool_result, subagent_stop, assistant_stop"
      }
    ]
  }
}

The entire request is rejected when body-level validation fails. Check details to identify the offending fields.

Batch Too Large — 400

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Batch size exceeds limit of 1000 events per request."
  }
}

Split large batches into multiple requests of 1,000 events or fewer.

On this page