UsageTracker
Defined in: core/src/usage.ts:109
Accumulates usage and cost across the calls of one run, pricing each with the rate in effect for the model that served it, so a run that switches to a backup model, or spans a time-of-day price boundary, still bills correctly. A call that carries a reported cost is billed that, with or without a rate.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new UsageTracker(): UsageTracker;Returns
Section titled “Returns”UsageTracker
Accessors
Section titled “Accessors”cacheSavingsUsd
Section titled “cacheSavingsUsd”Get Signature
Section titled “Get Signature”get cacheSavingsUsd(): number;Defined in: core/src/usage.ts:140
Returns
Section titled “Returns”number
costUsd
Section titled “costUsd”Get Signature
Section titled “Get Signature”get costUsd(): number;Defined in: core/src/usage.ts:136
Returns
Section titled “Returns”number
totals
Section titled “totals”Get Signature
Section titled “Get Signature”get totals(): TokenUsage;Defined in: core/src/usage.ts:132
Returns
Section titled “Returns”Methods
Section titled “Methods”add(usage, rate?): void;Defined in: core/src/usage.ts:116
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
usage |
TokenUsage |
rate? |
ModelRate |
Returns
Section titled “Returns”void
isOverBudget()
Section titled “isOverBudget()”isOverBudget(maxUsd): boolean;Defined in: core/src/usage.ts:147
A generous runaway guard, not a quality cap: the loop’s step budget is the real bound, and a run that trips this should finalize rather than fail, so set it well above any legitimate run.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
maxUsd |
number |
Returns
Section titled “Returns”boolean
reset()
Section titled “reset()”reset(): void;Defined in: core/src/usage.ts:151
Returns
Section titled “Returns”void
subtract()
Section titled “subtract()”subtract(usage, rate?): void;Defined in: core/src/usage.ts:124
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
usage |
TokenUsage |
rate? |
ModelRate |
Returns
Section titled “Returns”void