Skip to content
1 min read · 155 words

Function: resolveBudget()

ts
function resolveBudget(
  contextWindow: number,
  outputReserve?: number,
  reserveFraction?: number,
): number;

Defined in: src/batteries/context/thrift/subtractive_pass.ts:338

Resolve the per-dispatch INPUT token budget from the ACTIVE model's window: the window minus the room held back for the model's own output. The same call works for a 4K model and a 1M model.

Parameters

ParameterTypeDefault valueDescription
contextWindownumberundefinedThe active model's context window (input + output share it).
outputReserve?numberundefinedThe EXACT number of tokens to hold back for output — pass the generation maxTokens the model is configured with. When omitted, falls back to reserveFraction of the window (a guess, for callers that don't know the cap). Clamped so the reserve never exceeds the window.
reserveFraction?numberDEFAULT_RESERVE_FRACTIONThe fallback fraction used when outputReserve is omitted. Default: DEFAULT_RESERVE_FRACTION.

Returns

number