Skip to main content

io.enterpriseai.ContextBudget

Source: sdks/java/enterprise-ai-java/src/main/java/io/enterpriseai/ContextBudget.java. Back to the Java SDK reference index.

note

This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.

Model ContextBudget​

Token budget of one model call: B_context = W_model - B_output - B_reasoning - B_safety (Context Contract v1, field budget).

Fields:

NameTypeRequiredDescription
windowintyesContext window of the model in tokens (window), zero or more.
outputReservedintyesTokens reserved for the output (output_reserved).
reasoningReservedintyesTokens reserved for reasoning (reasoning_reserved).
safetyMarginintyesSafety margin in tokens (safety_margin); of takes 5 percent of the window, at least 256.

ContextBudget.contextBudget​

int contextBudget()

Tokens left for the assembled context; negative when reservations exceed the window.

This element takes no parameter.

Returns: int. window - outputReserved - reasoningReserved - safetyMargin, in tokens.

ContextBudget.fits​

boolean fits(int tokens)

True when tokens fit in the context budget.

NameTypeDefaultRequiredDescription
tokensintyesSize of the context in tokens.

Returns: boolean. True when tokens is lower than or equal to contextBudget().

ContextBudget.overflow​

int overflow(int tokens)

Tokens to remove from a context of tokens to fit, 0 when it fits.

NameTypeDefaultRequiredDescription
tokensintyesSize of the context in tokens.

Returns: int. The number of tokens in excess, never negative.