LLM Usage API
Prefix: /api/llm-usage | Tag: llm-usage
LLM token and cost monitoring. Superadmin only -- returns 403 for other roles. Aggregates data from alerts.llm_usage (chat) and alerts.agent_investigations (autonomous agent).
Endpoints
| Method | Path | Description |
|---|---|---|
| GET | /api/llm-usage/summary | Daily usage summary with cost breakdown |
| GET | /api/llm-usage/by-model | Usage breakdown by model |
| GET | /api/llm-usage/pricing | Pricing reference table |
GET /api/llm-usage/summary
Query params: days (int, default 30, range 1-365)
Response:
{
"period_days": 30,
"daily_usage": [
{
"day": "2026-03-25",
"source": "chat",
"model": "claude-sonnet-4-5-20250929",
"runs": 15,
"input_tokens": 45000,
"output_tokens": 12000,
"total_tokens": 57000,
"cost_usd": 0.315,
"avg_duration_s": 8.5,
"errors": 0
}
],
"totals": {
"runs": 450,
"input_tokens": 1350000,
"output_tokens": 360000,
"total_tokens": 1710000,
"cost_usd": 9.45,
"avg_cost_per_run": 0.021
},
"monthly_projection_usd": 9.45,
"source": "live",
"generated_at": "..."
}
GET /api/llm-usage/by-model
Query params: days (int, default 30, range 1-365)
Response:
{
"by_model": [
{
"model": "claude-sonnet-4-5-20250929",
"runs": 400,
"input_tokens": 1200000,
"output_tokens": 320000,
"total_tokens": 1520000,
"cost_usd": 8.40,
"avg_duration_s": 12.3
}
],
"source": "live",
"generated_at": "..."
}
GET /api/llm-usage/pricing
Returns the pricing table used for cost calculations.
Response:
{
"pricing": [
{"model": "claude-sonnet-4-5-20250929", "input_per_mtok": 3.0, "output_per_mtok": 15.0},
{"model": "gpt-4o", "input_per_mtok": 2.50, "output_per_mtok": 10.0},
{"model": "gpt-4o-mini", "input_per_mtok": 0.15, "output_per_mtok": 0.60}
]
}