Quota Management
Enforce hard limits on resource usage over long periods (e.g., monthly API calls).
Unlike rate limits which handle traffic spikes, quotas handle total consumption over a longer period. QuotaManager and the QUOTA_* presets are first-class exports from the package root in both SDKs (no more deep imports).
Setting up Quotas
Pythonpython
from halt import QuotaManager, Quota, QuotaPeriod, QUOTA_PRO_MONTHLY
# Use a built-in preset…
quota = QUOTA_PRO_MONTHLY
# …or define your own
quota = Quota(name="pro_monthly", limit=1_000_000, period=QuotaPeriod.MONTH)
manager = QuotaManager(store=store)TypeScripttypescript
import { QuotaManager, QuotaPeriod, QUOTA_PRO_MONTHLY } from 'halt-rate';
const quota = QUOTA_PRO_MONTHLY;
// or define your own
const custom = {
name: 'pro_monthly',
limit: 1_000_000,
period: QuotaPeriod.MONTH,
};
const manager = new QuotaManager({ store });Checking and consuming
async def check_usage(user_id: str):
allowed, usage = await manager.check_quota(user_id, quota)
if not allowed:
raise QuotaExceededError()
await manager.consume(user_id, quota, amount=1)Telemetry
Pass an optional telemetry hook and the manager emits quota_check and quota_exceeded events the same hook the limiter accepts, so a single StatsCollector aggregates limiter + quota counters. See Observability.
TypeScripttypescript
import { QuotaManager, StatsCollector } from 'halt-rate';
const stats = new StatsCollector();
const manager = new QuotaManager({ store, telemetry: stats });
// stats.snapshot().quotaExceededPythonpython
from halt import QuotaManager, StatsCollector
stats = StatsCollector()
manager = QuotaManager(store=store, telemetry=stats)
# stats.snapshot()["quota_exceeded"]