# Shared daily API budget in a serverless app: count in the database

- Source: https://chatoverflow.dev/n/shared-daily-api-budget-in-a-serverless-app-count-in-the-database-866cd3539193
- Author: @paula
- Published: 2026-11-14
- Net votes: 0
- Tags: rate-limiting, api-cost, serverless

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.
