Telemetry Endpoints
Usage metrics, logging, and performance monitoring endpoints.
All telemetry endpoints require JWT authentication and x-tenant-id header.
Headers:
Authorization: Bearer <jwt-token>
x-tenant-id: <uuid>
GET /api/telemetry/health
Health check for the telemetry service.
Authentication: Not required
Response:
{
"status": "healthy",
"version": "v2",
"timestamp": "2025-12-19T02:53:28.063Z",
"endpoints": [
"/metrics",
"/logs",
"/graph",
"/sessions",
"/usage-by-hour",
"/dashboard",
"/loopgraph",
"/cache",
"/call-sources"
]
}
GET /api/telemetry/metrics
Get aggregated telemetry metrics for a specific period.
Authentication: JWT + x-tenant-id required
Query Parameters:
| Param | Type | Required | Description |
|---|---|---|---|
start_date | ISO date | Yes | Start date |
end_date | ISO date | Yes | End date |
agent_id | UUID | No | Filter by agent |
provider | string | No | Filter by provider |
model | string | No | Filter by model |
status | string | No | success or error |
Example:
curl "http://localhost:3001/api/telemetry/metrics?start_date=2025-12-01T00:00:00Z&end_date=2025-12-31T23:59:59Z" \
-H "Authorization: Bearer $TOKEN" \
-H "x-tenant-id: $TENANT_ID"
Response:
{
"data": {
"totalRequests": 118,
"totalTokens": 166225,
"averageLatency": 3488,
"successRate": 96.6,
"successCount": 114,
"errorCount": 4,
"topModels": [
{
"model": "claude-3-5-haiku-20241022",
"requests": 113,
"tokens": 161861
}
],
"topAgents": [
{
"agent_id": "72bfe7d2-cc41-48c7-9ec3-52863cee2f9f",
"requests": 118,
"tokens": 166225
}
]
}
}
GET /api/telemetry/logs
Get paginated log entries.
Authentication: JWT + x-tenant-id required
Query Parameters:
| Param | Type | Default | Description |
|---|---|---|---|
page | number | 1 | Page number |
limit | number | 50 | Records per page (max: 100) |
start_date | ISO date | - | Start date |
end_date | ISO date | - | End date |
agent_id | UUID | - | Filter by agent |
provider | string | - | Filter by provider |
model | string | - | Filter by model |
status | string | - | success or error |
order_by | string | timestamp | Field to order by |
order_dir | string | desc | asc or desc |
Response:
{
"data": [
{
"id": "353843ef-0d2b-4a29-bba6-6da920c74d86",
"user_id": "469c99dc-6021-4aa8-9a88-d0e18a481545",
"agent_id": "72bfe7d2-cc41-48c7-9ec3-52863cee2f9f",
"provider": "anthropic",
"model": "claude-3-5-haiku-20241022",
"input_tokens": 1495,
"output_tokens": 770,
"total_tokens": 2265,
"response_time_ms": 13161,
"timestamp": "2025-12-19T01:27:31.736694+00:00",
"call_source": "agent.tool-loop",
"metadata": {
"source": "api_response",
"input_preview": "# Assistente Financeiro...",
"output_preview": "Vou realizar uma análise..."
}
}
],
"total": 118,
"pagination": {
"page": 1,
"limit": 50,
"pages": 24
}
}
GET /api/telemetry/usage-by-hour
Get usage aggregated by hour.
Authentication: JWT + x-tenant-id required
Query Parameters:
| Param | Type | Default | Description |
|---|---|---|---|
hours | number | 24 | Number of hours (max: 168) |
agent_id | UUID | - | Filter by agent |
Example:
curl "http://localhost:3001/api/telemetry/usage-by-hour?hours=24" \
-H "Authorization: Bearer $TOKEN" \
-H "x-tenant-id: $TENANT_ID"
Response:
{
"data": [
{
"hour": "2025-12-18 19:00",
"requests": 59,
"tokens": 98094
},
{
"hour": "2025-12-18 20:00",
"requests": 29,
"tokens": 28609
}
]
}
GET /api/telemetry/sessions
Get metrics aggregated by session.
Authentication: JWT + x-tenant-id required
Query Parameters:
| Param | Type | Default | Description |
|---|---|---|---|
limit | number | 50 | Number of sessions (max: 100) |
start_date | ISO date | - | Start date |
end_date | ISO date | - | End date |
agent_id | UUID | - | Filter by agent |
Response:
{
"data": [
{
"session_id": "abc123",
"agent_id": "72bfe7d2-cc41-48c7-9ec3-52863cee2f9f",
"first_interaction": "2025-12-18T22:08:17.949555+00:00",
"last_interaction": "2025-12-19T01:27:31.736694+00:00",
"total_calls": 118,
"total_tokens": 166225,
"total_latency_ms": 411561,
"errors": 4,
"avg_latency_ms": 3488,
"duration_ms": 11953787
}
],
"total": 1
}
GET /api/telemetry/dashboard
Get a complete dashboard with all aggregated metrics.
Authentication: JWT + x-tenant-id required
Query Parameters:
| Param | Type | Default | Description |
|---|---|---|---|
start_date | ISO date | 7 days ago | Start date |
end_date | ISO date | now | End date |
Example:
curl "http://localhost:3001/api/telemetry/dashboard" \
-H "Authorization: Bearer $TOKEN" \
-H "x-tenant-id: $TENANT_ID"
Response:
{
"data": {
"summary": {
"period_days": 7,
"total_calls": 118,
"total_tokens": 166225,
"avg_latency_ms": 3487.81,
"success_rate_pct": 96.61
},
"cache": {
"calls_with_cache": 74,
"cache_hit_rate_pct": 151.83,
"total_cached_tokens": 222215
},
"fallback": {
"total_errors": 4,
"total_fallbacks": 0,
"fallback_rate_pct": 0
},
"top_models": [
{
"model": "claude-3-5-haiku-20241022",
"provider": "anthropic",
"calls": 113,
"avg_latency_ms": 3554.64
}
],
"by_provider": [
{
"provider": "anthropic",
"calls": 114
}
],
"hourly_usage": [
{
"hour": "2025-12-18T22:00:00+00:00",
"calls": 59,
"tokens": 98094
}
],
"by_call_source": [
{
"call_source": "agent.tool-loop",
"calls": 77,
"avg_latency_ms": 3888.31
}
]
}
}
GET /api/telemetry/cache
Get detailed cache performance report (Prompt Caching).
Authentication: JWT + x-tenant-id required
Query Parameters:
| Param | Type | Default | Description |
|---|---|---|---|
start_date | ISO date | 30 days ago | Start date |
end_date | ISO date | now | End date |
Response:
{
"data": {
"summary": {
"total_calls": 118,
"calls_with_cache_hit": 74,
"total_cached_tokens": 222215,
"total_cache_creation_tokens": 40894,
"cache_hit_rate_pct": 151.83
},
"by_day": [
{
"day": "2025-12-19",
"cache_hits": 11,
"cached_tokens": 28876
}
],
"by_model": [
{
"model": "claude-3-5-haiku-20241022",
"provider": "anthropic",
"total_calls": 113,
"cache_hits": 74,
"cached_tokens": 222215
}
]
}
}
Prompt Caching allows reusing tokens from previous prompts, significantly reducing latency in subsequent calls. The cache hit rate indicates cache efficiency for your workload.
GET /api/telemetry/loopgraph
Get detailed metrics from the agent execution system (LoopGraph).
Authentication: JWT + x-tenant-id required
Query Parameters:
| Param | Type | Description |
|---|---|---|
start_date | ISO date | Start date |
end_date | ISO date | End date |
agent_id | UUID | Filter by agent |
Response:
{
"data": {
"summary": {
"total_executions": 118,
"avg_latency_ms": 3487.81,
"total_tokens": 166225,
"unique_sessions": 0
},
"nodes": [
{
"node": "agent",
"executions": 99,
"total_tokens": 141297,
"avg_latency_ms": 3416.75,
"error_rate_pct": 0
}
],
"edges": []
}
}
GET /api/telemetry/call-sources
Get metrics aggregated by call source.
Authentication: JWT + x-tenant-id required
Response:
{
"data": [
{
"call_source": "agent.tool-loop",
"total_calls": 77,
"total_tokens": 135007,
"avg_latency_ms": 3888.31,
"success_rate_pct": 100
},
{
"call_source": "agent.intent-check",
"total_calls": 16,
"total_tokens": 4286,
"avg_latency_ms": 1398.75,
"success_rate_pct": 100
},
{
"call_source": "agent.light-response",
"total_calls": 6,
"total_tokens": 2004,
"avg_latency_ms": 2746.33,
"success_rate_pct": 100
}
]
}
Call Sources:
| Source | Description |
|---|---|
agent.tool-loop | Tool execution in agent loop |
agent.intent-check | User intent classification |
agent.light-response | Light responses (greetings, help) |
Central.LLM.Controller | Direct controller calls |
GET /api/telemetry/graph
Get execution graph metrics.
Authentication: JWT + x-tenant-id required
Query Parameters:
| Param | Type | Description |
|---|---|---|
start_date | ISO date | Start date |
end_date | ISO date | End date |
agent_id | UUID | Filter by agent |
Response:
{
"data": {
"nodes": [],
"edges": [],
"summary": {
"total_executions": 118,
"unique_nodes": 0,
"unique_edges": 0
}
}
}
Error Codes
| Code | Description |
|---|---|
TELEMETRY_MISSING_DATE_RANGE | start_date and end_date are required |
INTERNAL_ERROR | Internal server error |
UNAUTHORIZED | Invalid or missing JWT token |
TENANT_NOT_FOUND | Tenant ID not found |
Error Response:
{
"error": {
"code": "TELEMETRY_MISSING_DATE_RANGE",
"message": "start_date e end_date são obrigatórios"
}
}
Caching Recommendations
| Endpoint | Recommended TTL |
|---|---|
/dashboard | 5 minutes |
/cache | 5 minutes |
/loopgraph | 5 minutes |
/usage-by-hour | 1 minute |
/logs | 30 seconds |