OutSystems Component — Documentation
AI Prompt Character and Token Estimator is a lightweight, reusable ODC component that gives users real-time visibility into how large their prompt is before it's sent to an AI model.
Drop the block next to any prompt input and it continuously reports:
Example output (Detailed mode):
Prompt size 608 estimated tokens of 4,000 Characters: 2,430 Words: 405 Remaining: 3,392 tokens
No database, no external API calls, no configuration screen required — just add the block, map two or three inputs, and it works.
AIPromptEstimator
AIPromptEstimatorDemo
OnEstimateChanged
The component uses a standard, model-agnostic approximation:
Estimated Tokens = Ceiling(Character Count / 4)
Example:
Character Count: 2,430 2,430 / 4 = 607.5 Estimated Tokens = 608
This heuristic is deliberately simple and fast, but it is not a substitute for a real tokenizer. Actual token counts will vary based on:
For this reason, every label in the UI intentionally reads "Estimated tokens" rather than "Tokens" — the component is a planning aid, not a billing meter.
PromptText
""
MaximumTokens
4000
WarningThresholdPercent
80
100
DisplayMode
"Detailed"
"Compact"
"Inline"
ShowCharacterCount
True
ShowWordCount
ShowRemainingTokens
ShowProgressBar
NormalizeWhitespace
Example mapping:
PromptText = UserPrompt MaximumTokens = 4000 WarningThresholdPercent = 80
Whitespace normalization example (display only, source text untouched):
Original: "Hello world" Processed: "Hello world"
Fires every time the estimate is recalculated (i.e., on every relevant keystroke).
CharacterCount
WordCount
EstimatedTokens
RemainingTokens
UsagePercent
IsWarning
IsLimitExceeded
EstimatedTokens > MaximumTokens
Use these outputs to drive application logic, such as enabling/disabling an AI submit button:
SubmitButton.Enabled = Trim(UserPrompt) <> "" and not PromptLimitExceeded
Shows the full picture: status message, estimated vs. maximum tokens, progress bar, character count, word count, and remaining tokens.Best for: prompt-building screens, RAG applications, AI configuration screens, long-form prompt inputs.
A single pill-style summary, e.g. 608 estimated tokens of 4000. Detailed metrics and the progress bar are hidden.Best for: chat interfaces, small prompt forms, toolbars, side panels.
608 estimated tokens of 4000
A minimal, card-free estimate, e.g. 608 estimated tokens of 4000.Best for: placement next to a prompt-input label, compact forms, embedded AI controls.
In the Exceeded state, remaining tokens are floored at 0 and the progress bar is capped at 100%.
0
100%
Step 1 — Add the dependency
AIPromptEstimatorLite
Step 2 — Create the prompt variableCreate a screen variable named UserPrompt of type Text, and bind your prompt input to it.
UserPrompt
Text
Step 3 — Place the blockPosition AIPromptEstimator below or beside the prompt input, and configure it:
PromptText = UserPrompt MaximumTokens = 4000 WarningThresholdPercent = 80 DisplayMode = "Detailed" ShowCharacterCount = True ShowWordCount = True ShowRemainingTokens = True ShowProgressBar = True NormalizeWhitespace = True
Step 4 — Handle the eventCreate a Client Action, HandleEstimateChanged, and map the event outputs to screen variables:
HandleEstimateChanged
CurrentEstimatedTokens = EstimatedTokens CurrentUsagePercent = UsagePercent PromptWarningActive = IsWarning PromptLimitExceeded = IsLimitExceeded
Step 5 — Control prompt submissionConfigure the AI submit button so it can't fire when the limit is exceeded:
Enabled = Trim(UserPrompt) <> "" and not PromptLimitExceeded
AI Chat Input — minimal footprint for a chat box:
PromptText = UserPrompt MaximumTokens = 4000 WarningThresholdPercent = 80 DisplayMode = "Compact" ShowCharacterCount = False ShowWordCount = False ShowRemainingTokens = False ShowProgressBar = False NormalizeWhitespace = True
RAG Prompt Builder — full detail for a larger context window:
PromptText = GeneratedPrompt MaximumTokens = 8000 WarningThresholdPercent = 75 DisplayMode = "Detailed" ShowCharacterCount = True ShowWordCount = True ShowRemainingTokens = True ShowProgressBar = True NormalizeWhitespace = True
Inline Prompt Helper — tight limit, minimal UI:
PromptText = UserPrompt MaximumTokens = 2000 WarningThresholdPercent = 90 DisplayMode = "Inline" ShowCharacterCount = False ShowWordCount = False ShowRemainingTokens = False ShowProgressBar = False NormalizeWhitespace = True
This component does not use a model-specific tokenizer. The estimate may be less accurate for:
Use a provider-specific tokenizer when exact token counts are required (e.g., for billing or hard enforcement).
The component also only measures the prompt text you give it — it does not automatically account for:
Distributed under the MIT License. Free for commercial and personal use in any OutSystems ODC or O11 application.