Quota checks and metered usage recording, at tenant or API-key level. Bearer required.
import { GatekeeperCore, UsageService } from '@orkait/sdk';
const usage = new UsageService(core);Methods#
| Method | Returns | Notes |
|---|---|---|
check(tenantId, quantity?, apiKeyId?) | QuotaCheckResult | does not record |
record(input) | UsageEvent | input is RecordUsageInput |
checkAndRecord(input) | CheckAndRecordResult | atomic check + record |
summary(tenantId, period?) | UsageSummary | period: hour | day | month |
RecordUsageInput: { tenantId, service, action, apiKeyId?, quantity?, metadata?, idempotencyKey? }.
Example#
const decision = await usage.checkAndRecord({
tenantId: 't1', service: 'api', action: 'call', quantity: 1, idempotencyKey: 'req-42',
});
if (!decision.allowed) throw new Error('quota exceeded');
const month = await usage.summary('t1', 'month');