public class LLMContextUsage
Immutable accounting snapshot, safe to publish from a session's owner thread. Reported usage describes the last provider request; an estimate describes retained messages plus tools. Neither promises exact future tokenization.
print(session.contextUsage.tokens)
| Modifier and Type | Member | Description |
|---|---|---|
| public readonly | estimatedestimated as Boolean |
True when any component is estimated. |
| public readonly | estimatedToolTokensestimatedToolTokens as Int |
Estimated tool-schema budget, for restoring a gauge without rebuilding tools. |
| public readonly | tokenstokens as Int |
Occupied tokens, bounded to Int.MAX_VALUE. |
| Modifier and Type | Member | Description |
|---|---|---|
| public | LLMContextUsageLLMContextUsage(tokens as Int, estimated as Boolean, estimatedToolTokens as Int = 0) |
Captures accounting without retaining mutable messages. |
| Modifier and Type | Member | Description |
|---|---|---|
| public static | bound | Bounds an accumulated estimate without integer overflow. |
| public static | estimateContextestimateContext(messages as ArrayList<LLMThreadMessage>, toolTokens as Int = 0) as Int |
Estimates a restored context once, using its last known tool budget. |
| public static | estimateMessageestimateMessage(message as LLMThreadMessage, imageTokens as Int = 1024, includeAttachments as Boolean = true) as Int |
Estimates text at four characters per token, with message framing. |
| public static | messageCharactersmessageCharacters(message as LLMThreadMessage) as Long |
Estimates message text and structured calls, including null content. |