Recipes Cost Tracking

Per-User AI Cost Tracking & Budgets

Every LLM call gets logged with input tokens, output tokens, and the price-per-million snapshot from the moment it ran. A user blasting through your free tier? You can see it in real time and shut them off.

This is the pattern Petal Pro ships with. The Req plugin attaches to your LLM client and writes an ai_call_logs row on every response. Pricing is snapshotted per-call, so an OpenAI price drop next month doesn’t retroactively rewrite last week’s history.

Pair this with a daily budget check before kicking off any expensive job.

Why snapshot pricing per-call?

  • Providers cut prices regularly. If you derive cost from a current price table, your historical revenue/margin numbers change every time OpenAI does a price drop. You don't want that.
  • Storing input_cost_per_million_cents alongside input_tokens means yesterday's row is correct forever.
  • Pair with a per-user daily cap to stop one abusive user from emptying your AI budget overnight.