Per-request cost estimation is computed and available for monitoring
Why it matters
Raw token counts are an abstraction that most product decisions do not operate on. Knowing a request consumed 1,200 tokens tells you nothing actionable; knowing it cost $0.014 does. Dollar cost estimation unlocks concrete decisions: which feature is too expensive to offer on the free plan, which user is consuming 10x the cohort average, whether a model swap will save $300/month, and at what traffic level a cost-per-user budget is breached. NIST AI RMF MEASURE 2.5 requires quantitative monitoring of AI operational costs; dollar estimates are that quantification.
Severity rationale
Low because the absence of cost estimation leaves token counts abstract, delaying cost-driven product decisions — but does not cause operational failure on its own.
Remediation
Add a cost calculator utility in src/lib/ai/cost-calculator.ts that converts token counts to dollar amounts using model pricing constants, then call it immediately after logging token usage.
// src/lib/ai/cost-calculator.ts
const PRICE_PER_1M_TOKENS = {
"gpt-4o": { input: 2.50, output: 10.00 },
"gpt-4o-mini": { input: 0.15, output: 0.60 },
"claude-3-5-sonnet-20241022": { input: 3.00, output: 15.00 },
} as const;
export function estimateCost(
model: keyof typeof PRICE_PER_1M_TOKENS,
promptTokens: number,
completionTokens: number
): number {
const p = PRICE_PER_1M_TOKENS[model];
return (promptTokens * p.input + completionTokens * p.output) / 1_000_000;
}
Store cost_usd alongside token counts in ai_request_logs. Verify by querying the table and confirming the values are plausible for the model used.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the AI Token Optimization Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- nist-ai-rmf:1.0 · MEASURE 2.5 — AI risk metrics are monitored
- iso-25010:2011 · reliability.maturity — Maturity — per-request cost estimation supports operational monitoring
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ai-token-optimization·automated