concept
Shared context token budget
Simplified shared-context accounting for an already tokenized decoder request. Separate provider output limits, formatting overhead and reasoning-token accounting must be checked independently.
Formal Syntax & Structure
artificial-intelligence syntaxartificial-intelligence
input_tokens + reserved_output_tokens <= context_windowWorking Example
Example Snippetartificial-intelligence
def budget_report(window, input_tokens, reserve): if any(type(n) is not int or n < 0 for n in (window, input_tokens, reserve)): raise ValueError("counts must be nonnegative integers") remaining = window - input_tokens - reserve return {"fits": remaining >= 0, "spare": max(0, remaining), "overflow": max(0, -remaining)}
print(budget_report(100, 70, 20))print(budget_report(100, 90, 20))