Since T2.4, the Kladde counts every call to a model, with tokens and costs per AI feature. The meter lives in memory, though: after every restart it begins at zero, and if two instances of the Kladde run, each one counts for itself. That isn't enough for a cap. In this lesson, the meter becomes a monthly cap: the cost of every call lands in the database, at 80 percent the Kladde warns, and at 100 percent it stops what runs on its own.
Why a cap of our own when Azure has budgets? Because an Azure budget only sends mails, and with a delay: the costs reach Cost Management only after hours. A loop that, because of a bug, assesses the same tender every minute uses up whatever it wants in that time. According to Microsoft, Foundry doesn't offer a hard limit that rejects calls above an amount. So the cap that really stops is built by the application itself. The Azure budget joins it as a second guard.
| Package | Version | What it is for |
|---|---|---|
Microsoft.Extensions.Options.ConfigurationExtensions |
10.0.14 (since T3.3) | the cap's settings with validation at startup |
Microsoft.Extensions.Hosting.Abstractions |
10.0.14 | BackgroundService for the assessment in the background, in Kladde.Ai |
Microsoft.Extensions.TimeProvider.Testing |
10.11.0 | FakeTimeProvider in the test project |
Microsoft.EntityFrameworkCore.SqlServer |
10.0.14 (since K2 in the web application) | the month's totals in the database |
Who may do what when money runs short
A cap that simply stops everything would be wrong. The Kladde distinguishes three kinds of work:
| Kind | Example | At 100 percent |
|---|---|---|
Background |
assessing imported tenders | pauses and goes on by itself next month |
Visitor |
a visitor's question to the support chat | no model call; the chat shows the support form |
Staff |
someone in the office clicks "Assess this tender" | runs and is counted |
The idea behind it: the cap protects against work that nobody watches, that is, against loops, bugs and floods from outside. A person from the office who clicks on purpose decides for themselves; they see the warning, but they aren't stopped. Visitors, by contrast, are many and unknown. Whoever floods the chat with a thousand questions shouldn't drain the office's budget; they get the form, which needs no model.