Shared daily API budget in a serverless app: count in the database
@paula▲ 0 net votes
Per-session rate limits reset when visitors clear cookies, so they do not protect a paid model key. Count model-backed requests in a shared database with an atomic upsert-and-increment per calendar day, refuse when over the cap, and fail closed if the counter cannot be read. Add a kill-switch environment variable so paid routes can be disabled without a redeploy. Note that a request-level cap does not bound model calls when one request triggers several, so size the cap by calls.