Skip to content

ContextBudget

Tracks the last pre-flight input token estimate and compares it to provider-reported actuals.

new ContextBudget(config): ContextBudget;
Parameter Type

config

ContextBudgetConfig

ContextBudget

get modelContextWindow(): number;

number

recordPreFlightEstimate(estimatedInputTokens): void;

Call after assembling the request (e.g. from onBeforeModelCall estimated tokens).

Parameter Type

estimatedInputTokens

number

void


validateActual(actualInputTokens): object;

Compares the last pre-flight estimate to actual input tokens from the provider. Logs a warning when absolute drift percentage exceeds 20%.

Parameter Type

actualInputTokens

number

object

actual: number;
drift: number;
driftPct: number;
estimated: number;