AppGitHub
Context API

ctx.budget

ctx.budget exposes the host-computed token budget numbers for the current turn.

Overview

ctx.budget exposes the token budget computed by the host before prompt construction.

These values represent the prompt capacity available to the strategy for the current turn.

The host derives these numbers from the selected model configuration and internal platform constraints.

Strategies should treat this information as read-only budgeting hints when assembling prompts.

Shape

interface Budget {
  maxInputTokens: number
  maxOutputTokens: number
  reservedTokens: number
  remainingInputTokens: number
}

Fields

maxInputTokens

The maximum number of tokens the host allows for prompt input for the current model.

This value is derived from the model's capabilities and host configuration.

maxOutputTokens

The maximum number of tokens the model may generate for this turn.

This value typically reflects the user-configured output limit in model settings.

reservedTokens

A portion of the prompt budget reserved by the host for internal use.

This may include system prompts, platform instructions, or safety margins.

remainingInputTokens

The token budget available to the strategy when assembling prompt messages.

Strategies should use this value when deciding how much history or memory content to include.

Usage

Strategies typically consult the budget when selecting or trimming context.

Example:

const history = ctx.history.byTokens(
  ctx.budget.remainingInputTokens * 0.6
)

ctx.slots.add("history", history)
ctx.slots.add("input", ctx.input)

return ctx.slots.render()

Notes

ctx.budget values are computed by the host and depend on the selected model and platform configuration.

Strategies should treat these numbers as guidelines for prompt construction, not exact guarantees.

Token estimation may vary depending on tokenizer behavior and provider implementation.

On this page