Traces API
Ingest traces from your AI agents and query historical data.
Ingest Traces (OTLP)
ThinkHive supports OpenTelemetry Protocol (OTLP) for trace ingestion.
POST /v1/tracesHeaders:
Content-Type: application/json
Authorization: Bearer thk_your_api_keyRequest Body (OTLP Format):
{
"resourceSpans": [
{
"resource": {
"attributes": [
{ "key": "service.name", "value": { "stringValue": "my-agent" } }
]
},
"scopeSpans": [
{
"spans": [
{
"traceId": "abc123...",
"spanId": "def456...",
"name": "llm-call",
"kind": 1,
"startTimeUnixNano": "1704067200000000000",
"endTimeUnixNano": "1704067201000000000",
"attributes": [
{ "key": "llm.model", "value": { "stringValue": "gpt-4" } },
{ "key": "llm.input_tokens", "value": { "intValue": "150" } }
]
}
]
}
]
}
]
}Ingest Traces (Simple Format)
POST /api/tracesRequest Body:
{
"agentId": "agent_abc123",
"spans": [
{
"name": "customer-chat",
"type": "llm",
"startTime": "2024-01-15T10:00:00Z",
"endTime": "2024-01-15T10:00:02Z",
"input": "How do I reset my password?",
"output": "To reset your password, go to Settings...",
"model": "gpt-4",
"tokens": {
"input": 25,
"output": 150,
"total": 175
},
"metadata": {
"customerId": "cust_123",
"channel": "chat"
}
}
],
"outcome": "success"
}Response:
{
"success": true,
"data": {
"traceId": "tr_xyz789",
"spanCount": 1,
"ingested": true
}
}List Traces
GET /api/tracesQuery Parameters:
| Parameter | Type | Description |
|---|---|---|
agentId | string | Filter by agent |
outcome | string | Filter by outcome (success, failure) |
startDate | string | Start date (ISO 8601) |
endDate | string | End date (ISO 8601) |
page | number | Page number |
limit | number | Items per page (max 100) |
Example:
GET /api/traces?agentId=agent_abc123&outcome=failure&limit=20Response:
{
"success": true,
"data": [
{
"id": "tr_xyz789",
"agentId": "agent_abc123",
"outcome": "failure",
"userMessage": "How do I...",
"agentResponse": "I apologize...",
"latencyMs": 1500,
"tokenCount": 200,
"createdAt": "2024-01-15T10:00:00Z"
}
],
"pagination": {
"page": 1,
"limit": 20,
"total": 150,
"hasMore": true
}
}Get Trace
GET /api/traces/:idResponse:
{
"success": true,
"data": {
"id": "tr_xyz789",
"agentId": "agent_abc123",
"outcome": "failure",
"spans": [
{
"id": "span_1",
"name": "retrieval",
"type": "retrieval",
"query": "password reset",
"documents": [
{ "id": "doc_1", "content": "...", "score": 0.85 }
],
"latencyMs": 200
},
{
"id": "span_2",
"name": "llm-response",
"type": "llm",
"input": "Context: ... Question: How do I...",
"output": "To reset your password...",
"model": "gpt-4",
"tokens": { "input": 150, "output": 100 },
"latencyMs": 1200
}
],
"metadata": {
"customerId": "cust_123",
"sessionId": "sess_abc"
},
"createdAt": "2024-01-15T10:00:00Z"
}
}Get Trace Spans
GET /api/traces/:id/spansResponse:
{
"success": true,
"data": [
{
"id": "span_1",
"traceId": "tr_xyz789",
"parentSpanId": null,
"name": "rag-pipeline",
"type": "chain",
"startTime": "2024-01-15T10:00:00Z",
"endTime": "2024-01-15T10:00:02Z",
"children": ["span_2", "span_3"]
},
{
"id": "span_2",
"traceId": "tr_xyz789",
"parentSpanId": "span_1",
"name": "retrieval",
"type": "retrieval",
...
}
]
}Delete Trace
DELETE /api/traces/:idResponse:
{
"success": true,
"message": "Trace deleted successfully"
}Trace Statistics
GET /api/traces/statsQuery Parameters:
| Parameter | Type | Description |
|---|---|---|
agentId | string | Agent ID |
period | string | Time period (24h, 7d, 30d) |
Response:
{
"success": true,
"data": {
"totalTraces": 15000,
"successRate": 0.85,
"failureRate": 0.15,
"avgLatencyMs": 1200,
"p50LatencyMs": 1000,
"p95LatencyMs": 2500,
"p99LatencyMs": 4000,
"tokenUsage": {
"total": 2500000,
"avgPerTrace": 166
},
"byOutcome": {
"success": 12750,
"failure": 2250
}
}
}Supported Trace Formats
ThinkHive can ingest traces from multiple formats:
Native ThinkHive format (shown above)
Auto-Detection: ThinkHive automatically detects the trace format when using the /api/explainer/analyze endpoint.
Trace Sessions
Manage trace sessions to group related traces.
GET /api/sessions
POST /api/sessions
PATCH /api/sessions/:idTrace Evaluation Link
Connect traces to evaluation runs for quality tracking.
GET /api/trace-evaluation?traceId=tr_xyz789
POST /api/trace-evaluationNext Steps
- Explainability & Analysis — Analyze trace quality
- Issues & Fixes — View failure clusters
- Evaluation & Grading — Run evaluations