Interface: IUsageAdapter
Defined in: internal/usage-guard/types.ts:80
The seam between the gateway and the app's usage rules: asked before every model call, told after it.
Implemented by the app (plans, limits, ledgers, per-model access, credits — whatever it wants) and by
InMemoryUsageAdapter for tests. The UsageGuard is its only caller; the LLMClient goes through the guard.
Methods
addUsage()
addUsage(
args):Promise<void>
Defined in: internal/usage-guard/types.ts:110
addUsage -- what the call used
About
Told once after every approved
check, also for a failed or aborted call.
Then with zero usage, so an adapter that reserves in check can always settle by traceId. A throw is logged; the call's
answer is still returned.
Who needs it
UsageGuard.addUsage, after every provider call.
Parameters
args
Returns
Promise<void>
check()
check(
args):Promise<IUsageCheckResult>
Defined in: internal/usage-guard/types.ts:95
check -- may this model call run?
About
The app's answer, before every model call the gateway makes.
Asked for the answer, every run step, every guardrail judge, query rewrite, memory update and embedding, with the call's factors and its rough size. A throw is treated as a denial (fail closed) and logged.
Who needs it
UsageGuard.check, right before the provider is called.
Parameters
args
Returns
Promise<IUsageCheckResult>