REST API Reference

The AgentLens REST API is used by the SDKs to ingest and retrieve traces. You can also call it directly for custom integrations.

Base URL: https://agentlens.vectry.tech

Authentication

All write endpoints require a Bearer token in the Authorization header:

Authorization: Bearer your-api-key

POST/api/traces

Batch ingest one or more traces with their spans, decision points, and events.

Request body

request_body.json
{
  "traces": [
    {
      "id": "trace-uuid-v4",
      "name": "my-agent-run",
      "sessionId": "session-abc",
      "status": "COMPLETED",
      "tags": ["production", "v2"],
      "metadata": { "user_id": "u-123" },
      "totalCost": 0.045,
      "totalTokens": 1500,
      "totalDuration": 3200,
      "startedAt": "2026-01-15T10:00:00.000Z",
      "endedAt": "2026-01-15T10:00:03.200Z",
      "spans": [ ... ],
      "decisionPoints": [ ... ],
      "events": [ ... ]
    }
  ]
}

TracePayload

FieldTypeRequiredDescription
idstringYesUUID v4 unique identifier
namestringYesHuman-readable trace name
sessionIdstringNoGroup traces into a session
statusenumYesRUNNING | COMPLETED | ERROR
tagsstring[]YesArray of tag strings
metadataobjectNoArbitrary JSON metadata
totalCostnumberNoTotal cost in USD
totalTokensnumberNoTotal token count
totalDurationnumberNoTotal duration in milliseconds
startedAtstringYesISO 8601 datetime
endedAtstringNoISO 8601 datetime (null if RUNNING)
spansSpanPayload[]YesArray of spans (can be empty)
decisionPointsDecisionPointPayload[]YesArray of decision points (can be empty)
eventsEventPayload[]YesArray of events (can be empty)

SpanPayload

FieldTypeRequiredDescription
idstringYesUUID v4
parentSpanIdstringNoParent span ID for nesting
namestringYesSpan name
typeenumYesLLM_CALL | TOOL_CALL | MEMORY_OP | CHAIN | AGENT | CUSTOM
inputobjectNoJSON input payload
outputobjectNoJSON output payload
tokenCountnumberNoTotal tokens
costUsdnumberNoCost in USD
durationMsnumberNoDuration in milliseconds
statusenumYesRUNNING | COMPLETED | ERROR
statusMessagestringNoError message or status description
startedAtstringYesISO 8601 datetime
endedAtstringNoISO 8601 datetime
metadataobjectNoArbitrary JSON metadata

DecisionPointPayload

FieldTypeRequiredDescription
idstringYesUUID v4
typeenumYesTOOL_SELECTION | ROUTING | RETRY | ESCALATION | MEMORY_RETRIEVAL | PLANNING | CUSTOM
reasoningstringNoWhy this choice was made
chosenobjectYesJSON value representing the choice made
alternativesobject[]YesArray of alternatives considered
contextSnapshotobjectNoContext at decision time
durationMsnumberNoDecision time in milliseconds
costUsdnumberNoCost of this decision
parentSpanIdstringNoSpan this decision belongs to
timestampstringYesISO 8601 datetime

EventPayload

FieldTypeRequiredDescription
idstringYesUUID v4
spanIdstringNoSpan this event is associated with
typeenumYesERROR | RETRY | FALLBACK | CONTEXT_OVERFLOW | USER_FEEDBACK | CUSTOM
namestringYesHuman-readable event name
metadataobjectNoArbitrary JSON metadata
timestampstringYesISO 8601 datetime

Responses

200

Success

{ "success": true, "count": 1 }
400

Bad Request

{ "error": "Request body must contain a 'traces' array" }
401

Unauthorized

{ "error": "Missing or invalid Authorization header" }
409

Conflict

{ "error": "Duplicate trace ID detected" }
500

Internal Server Error

{ "error": "Internal server error" }

cURL example

terminal
curl -X POST https://agentlens.vectry.tech/api/traces \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key" \
  -d '{
    "traces": [{
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "test-trace",
      "status": "COMPLETED",
      "tags": ["test"],
      "startedAt": "2026-01-15T10:00:00.000Z",
      "endedAt": "2026-01-15T10:00:01.000Z",
      "spans": [],
      "decisionPoints": [],
      "events": []
    }]
  }'

GET/api/traces

List traces with pagination, filtering, and sorting.

Query parameters

ParamTypeDefaultDescription
pageinteger1Page number (1-based)
limitinteger20Results per page (1-100)
statusstring-Filter by status: RUNNING, COMPLETED, ERROR
searchstring-Case-insensitive search on trace name
sessionIdstring-Filter by session ID
tagsstring-Comma-separated tags (matches any)
sortstringnewestnewest, oldest, longest, shortest, costliest
dateFromstring-ISO 8601 lower bound
dateTostring-ISO 8601 upper bound

Response shape

response.json
{
  "traces": [
    {
      "id": "...",
      "name": "my-agent",
      "status": "COMPLETED",
      "tags": ["production"],
      "startedAt": "2026-01-15T10:00:00.000Z",
      "endedAt": "2026-01-15T10:00:03.200Z",
      "totalCost": 0.045,
      "totalTokens": 1500,
      "totalDuration": 3200,
      "_count": {
        "decisionPoints": 3,
        "spans": 7,
        "events": 1
      }
    }
  ],
  "total": 142,
  "page": 1,
  "limit": 20,
  "totalPages": 8
}