Skip to main content
In this lesson we walk through a concrete example to see what actually drives the token cost of an LLM-powered feature. We run a troubleshooting assistant against a real ticket + log excerpt, capture the model usage (input and output tokens), and convert that into a dollar cost so you can estimate monthly spend for production. Overview
  • Build a small agent that receives a system prompt (the runbook and instructions) plus a ticket and log excerpt.
  • Call the model once, inspect the model’s token usage (input_tokens and output_tokens), and compute the cost.
  • Scale that single-call cost to a monthly estimate using expected traffic.
Why this matters: provider pricing pages give per-token rates (for example, dollars per million tokens) but not your workload. The only reliable way to estimate cost is to measure the tokens your inputs and outputs produce for representative requests. Environment prompt (terminal)
Model pricing example Many providers separate input and output pricing. Output tokens are often more expensive. For this lesson we’ll use these example rates from Anthropic’s Sonnet 4.5 pricing page:
Input vs output pricing matters because even modest increases in output length can dominate costs. Measure both.
What we’ll do
  1. Send a single, representative request (system prompt + ticket + logs) to the model.
  2. Inspect exactly what the provider counts (input & output tokens) in the response usage metadata.
  3. Compute the cost for that single call, then scale to monthly volume.
Agent code (streaming demo) Below is the Python streaming code used to call Anthropic. The key parts are model selection, the system prompt, the user message (ticket + logs), streaming the response to the console, and printing response usage (token counts).
System prompt (the assistant’s instructions and runbook)
Ticket and log excerpt (the user-facing input) Ticket summary and user description:
Log excerpt (vpn-gw-01)
Run the demo and inspect usage When the demo is executed, the model returns the formatted troubleshooting output and the response usage report. Example console output from the demo run:
Token counts and cost calculation For this single run:
  • Input tokens: 9,333
  • Output tokens: 600
Using the Sonnet 4.5 example pricing (input = 2/1,000,000;output=2 / 1,000,000; output = 5 / 1,000,000): This matches the earlier statement that this Sonnet call costs roughly two cents. If you pick a higher-tier model with higher rates, the same token counts can cost several times more (for example, ~11 cents with a pricier frontier model in a comparative example). Estimator UI (example) Use a token/cost calculator or a dashboard to experiment with different input/output mixes and providers. For projection you might assume output tokens are a percentage of input tokens (e.g., 20%). The screenshot below shows an input total of 9,333 tokens and an estimated output of ~1,867 tokens (20% of input).
A screenshot of a token/cost calculator webpage showing an "Input Total Tokens" of 9,333 and an expected "Output Tokens" of 1,867 (20% of input). The lower part of the page displays cost-by-provider cards for models like OpenAI, Anthropic, Google Gemini, and Perplexity.
Model & provider comparisons Dashboards that compare provider pricing side-by-side are useful when choosing a model for cost-sensitive features. They let you plug in measured input/output token counts to see provider-level costs and tradeoffs.
A screenshot of a web dashboard comparing AI provider costs, showing cards for OpenAI, Anthropic (Claude Sonnet 5), Perplexity, DeepSeek and Grok with input/output pricing and estimated totals. A dropdown menu in the center lists various Gemini model options.
Key takeaways
  • Measure token usage on representative requests (input + output) — it’s the only reliable way to forecast costs for your workload.
  • Output tokens often cost more than input tokens. Small differences in output size or model selection can change costs materially.
  • Average over many tickets to produce a stable per-request estimate, then multiply by monthly call volume to get a monthly spend projection.
  • Don’t default to the most expensive frontier model — cheaper models may meet accuracy requirements at a fraction of the cost.
Pricing and token accounting vary by provider and model. Always verify the provider’s usage metadata (the response usage fields) and pricing page before projecting monthly costs.
Links and references Further reading
  • Best practices for measuring model usage and reducing token costs
  • Designing prompts and outputs to minimize expensive output tokens
  • Building dashboards to track per-feature LLM costs and budget forecasts

Watch Video