By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
A monthly provider invoice is an outcome, not a measurement. To operate an LLM feature you need the cost of each request, tagged with the feature, tenant and prompt version that produced it, so you can answer questions like "why did Northline's spend double on Tuesday?" and "which prompt version is the expensive one?"
The arithmetic is simple: input tokens and output tokens are priced separately, per million tokens, and the model alias determines the price. The discipline is in recording the usage the provider reports, not the usage you estimated, and in checking a budget before the request rather than after the invoice.
# USD per 1,000,000 tokens. Real deployments load this from config, not code.
PRICES = {
"waypoint-standard": {"input": 1.00, "output": 2.00},
"waypoint-lite": {"input": 0.25, "output": 0.50},
}
def cost_usd(model_alias: str, input_tokens: int, output_tokens: int) -> float:
price = PRICES[model_alias]
return (input_tokens * price["input"] + output_tokens * price["output"]) / 1_000_000
def within_budget(spent_usd: float, request_cost: float, cap_usd: float) -> bool:
return spent_usd + request_cost <= cap_usd
usage = {
"model_alias": "waypoint-standard",
"input_tokens": 1200,
"output_tokens": 300,
}
request_cost = cost_usd(**usage)
print(f"request cost: ${request_cost:.6f}")
print("under $0.01 cap:", within_budget(0.0040, request_cost, 0.01))
print("under $0.005 cap:", within_budget(0.0040, request_cost, 0.005))customer_update, reroute_proposal, policy_qa. One shared model bill serves several products.| Line item | Measured where | Used for |
|---|---|---|
| Input tokens | Provider response usage object | Base cost, context growth |
| Output tokens | Provider response usage object | Base cost, verbosity |
| Cached input tokens | Provider response usage object | Cache discount, cache hit rate |
| Retry tokens | Sum of failed attempts' usage | Wasted spend, retry ladder tuning |
| Tool call cost | Carrier or internal API pricing | Chargeable action budget |
| Human review time | Approval queue timestamps | Approval SLA and staffing |
budget_exceeded error before spending.Retry-After and let the caller decide when to retry.Key takeaways
Cost is measured per request and tagged by feature, tenant, prompt version, route and outcome.
Compute from input and output tokens at the alias's price; record provider-reported usage.
Guard budgets before the call: per-request cap and per-tenant daily cap with a structured 429.
Alert on burn rate and reconcile estimates against invoices weekly.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.