Event contract
Fields the query expects
| Field | Type | Why it exists |
|---|---|---|
| timestamp_utc | Timestamp | When the model request completed. |
| feature | Utf8 | Stable product feature name. |
| model | Utf8 | Provider model identifier. |
| total_tokens | Int64 | Input plus output tokens. |
| estimated_cost_usd | Float64 | Request cost calculated from versioned model pricing. |
| status | Utf8 | success or failed. |
Copy the query
SELECT
feature,
model,
COUNT(*) AS requests,
SUM(total_tokens) AS total_tokens,
SUM(estimated_cost_usd) AS cost_usd,
SUM(estimated_cost_usd) / NULLIF(COUNT(*), 0) AS cost_per_request_usd
FROM llm_requests
WHERE timestamp_utc >= now() - INTERVAL '30 days'
GROUP BY feature, model
ORDER BY cost_usd DESC;This recipe is read-only and reviewed against Telemetry's DataFusion query patterns. Sample output is deterministic and synthetic; validate field types, thresholds, and business definitions against your own data.
Query result
Thirty-day model cost by feature
Research reports cost more overall despite far fewer requests, pointing to unit-cost optimization rather than an adoption problem.
| feature | model | requests | total_tokens | cost_usd | cost_per_request_usd |
|---|---|---|---|---|---|
| research_report | reasoning-large | 2,180 | 18,420,000 | 921.4 | 0.42 |
| support_draft | fast-small | 32,100 | 24,800,000 | 496 | 0.02 |
| document_summary | balanced-medium | 8,450 | 12,950,000 | 388.5 | 0.05 |
Synthetic example output. Run the query against your own event schema and thresholds before using it for operational decisions.
How the SQL works
- 1Grouping by both feature and model preserves the context needed to explain model migrations.
- 2Cost per request distinguishes a high-volume inexpensive workflow from a low-volume expensive one.
- 3Store the calculated request cost at event time using a versioned price table so historical reports do not change when provider pricing changes.
Edge cases to decide
- Do not multiply total tokens by one rate when input, cached input, and output tokens have different prices.
- Include failed requests if the provider bills them; otherwise add a billing_status field.
- Use account or team identifiers when margins vary materially by customer.
Recommended dashboard
- Bar chart: cost_usd by feature
- Line chart: daily cost split by model
- Table: highest-cost individual requests without raw prompt content
Alert guidance
Alert when daily feature cost or cost per successful outcome exceeds an agreed budget, not merely when request volume rises.
Read alert setupPut the recipe to work
Related instrumentation and guides
Continue the analysis
Run it on real events
Create a table, adapt the fields, and save the result
Start free, send structured events, and use the query result as a chart, shared dashboard widget, or alert input.