LLM Cost Tracker: implementation to decision
Treat the prompt as an implementation brief. The useful artifact is not copied code alone, but a reviewed event contract that produces a trustworthy answer.
- 1
Select the boundary
Instrument the point where llm_request_completed becomes final.
- 2
Create the contract
Start with llm_request_completed, llm_request_failed, llm_stream_completed and keep every field typed, bounded, and privacy-reviewed.
- 3
Run a fixture
Exercise known success, failure, retry, and empty-result cases before relying on aggregate results.
- 4
Answer the question
Which features cost the most per retained account?
Template versus use case
This page is the implementation brief
Copy this template when the measurement goal is already clear. Use the matching use-case guide to review event boundaries, success definitions, and the decisions the resulting SQL should support.
Template
Paste this into your coding agent
Replace YOUR_API_KEY, run the flow locally, then verify the generated events and dashboards.
LLM Cost Tracker
Instrument LLM usage and cost with Telemetry.
Use /skill.md and this Telemetry API key: YOUR_API_KEY
Log each model request with:
provider, model, route, feature, user_id, team_id, input_tokens, output_tokens, total_tokens, estimated_cost_usd, latency_ms, status, retry_count, and error_type.
Connect outcome events such as copied, saved, accepted, retried, regenerated, or discarded.
Create dashboards for daily spend, cost by feature, cost by account, failures by model, p95 latency, and accepted-output rate.
Do not store raw prompts or completions by default.Events to capture
Verification checklist
What a complete instrumentation pass leaves behind
Events
Synthetic events reach the intended table with stable names and field types.
Queries
The first SQL queries return plausible rows with an explicit time window.
Views
A dashboard uses the real fields and includes enough context to explain a change.
Safety
Prompts, bodies, credentials, signatures, and private content were checked for redaction.
Event schema starting points
Event contracts for this workflow
Review the row grain, emit boundary, required types, privacy classes, example payload, and validation checklist before adapting a query or snippet to production.
Related product capability
Continue this workflow in AI agent monitoring
Connect agent runs, tool use, model cost, quality, and product outcomes with reviewable SQL.
Related SQL recipes
Answer the next question with SQL
Run the query against the structured fields from this workflow, inspect the example result, and turn a useful answer into a dashboard or alert.
Calculate LLM Cost by Feature and Model
Which product features and models are driving LLM spend?
Open recipeMeasure Accepted AI Outputs per Dollar
Which model and feature combination produces the most accepted outputs per dollar?
Open recipeMeasure LLM Cache Savings and Retry Cost
How much model cost is associated with retries and cache misses?
Open recipeMeasure LLM Time to First Token
Which model and feature combinations feel slow before output begins?
Open recipeMore templates