🛡️Gatekeeper/ SDKs

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#

MethodReturnsNotes
check(tenantId, quantity?, apiKeyId?)QuotaCheckResultdoes not record
record(input)UsageEventinput is RecordUsageInput
checkAndRecord(input)CheckAndRecordResultatomic check + record
summary(tenantId, period?)UsageSummaryperiod: 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');