Skip to content
Telemetry
Event tracking template

LLM cost tracker

Measure model spend, token usage, latency, failures, and accepted outputs by feature, user, and account.

Reviewed by the Telemetry product team on . We checked the event names, suggested fields, questions to query, and data to exclude. Who reviews this page

Questions you can answer
  • Which features cost the most per retained account?
  • Which models have the best accepted-output rate per dollar?
  • How much do retries and timeouts add to model costs?
How to test this template

Set up LLM cost tracker and check the results

Use the prompt to add events, then check the stored fields and query results. Review the event definitions before relying on the numbers.

  1. 1

    Choose when to log

    Instrument the point where llm_request_completed becomes final.

  2. 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. 3

    Run a fixture

    Exercise known success, failure, retry, and empty-result cases before relying on aggregate results.

  4. 4

    Answer the question

    Which features cost the most per retained account?

Template versus use case

Use this template to add events

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.

Read OpenAI cost monitoring

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

LLM cost tracker

text
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

llm_request_completedllm_request_failedllm_stream_completedllm_output_savedllm_output_discarded

Verification checklist

Check the events, queries, and dashboard

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

You checked that events exclude prompts, bodies, credentials, signatures, and private content.

Example event schemas

Check what each event records, when to send it, and which field types it needs. Review the example payload and privacy checklist before using it in production.

Use these queries in Telemetry

Learn about AI agent monitoring

Query agent events to compare tool use, model costs, and outcomes for each run.

Related SQL recipes

More SQL recipes

Run the query using this workflow's event fields and check the example result. Save the result to a dashboard or set up an alert.

Browse all recipes
Recipe collectionsAI and LLM SQL

More templates