klyn.llm.LLMContextUsage.estimateMessage
method
public static estimateMessage(message as LLMThreadMessage, imageTokens as Int = 1024, includeAttachments as Boolean = true) as Int
Description

Estimates text at four characters per token, with message framing. Images use a configurable heuristic, not their Base64 byte length. Actual image tokenization depends on the model and must be reconciled with usage. This method never reads an image file.

Parameters
ParameterDescription
imageTokensEstimated budget per image; default 1024, not a hard bound.
includeAttachmentsWhether local attachment names are part of the wire message.
Example

tokens = LLMContextUsage.estimateMessage(message, 2048)