By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Waypoint's daily model budget for one small tenant is $0.02. You need to accumulate per-request cost, emit an alert once the tenant crosses 80% of the cap, and report whether the budget is still available at the end of the batch. The prices are input $1.00 per million tokens and output $2.00 per million.
PRICE_INPUT_PER_MILLION = 1.00
PRICE_OUTPUT_PER_MILLION = 2.00
DAILY_CAP_USD = 0.02
ALERT_AT = 0.8
requests = [
(1200, 300),
(900, 250),
(1800, 400),
(2400, 600),
(3000, 800),
(4000, 1200),
]
def request_cost(input_tokens: int, output_tokens: int) -> float:
input_cost = input_tokens * PRICE_INPUT_PER_MILLION / 1_000_000
output_cost = output_tokens * PRICE_OUTPUT_PER_MILLION / 1_000_000
return input_cost + output_cost
spent = 0.0
for index, (input_tokens, output_tokens) in enumerate(requests, start=1):
spent += request_cost(input_tokens, output_tokens)
status = "ALERT" if spent >= ALERT_AT * DAILY_CAP_USD else "ok"
print(f"request {index}: spent=${spent:.6f} status={status}")
print("budget available:", spent < DAILY_CAP_USD)budget_exceeded error instead of silently spending more.Key takeaways
Cost accounting is token arithmetic at the price of the alias, per request.
Alert at 80% of the cap so there is room to act before the hard stop.
Tag spend with tenant and feature, and make the hard cap return a structured error.
Every budget alert needs an owner and a documented response.
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.