New Tool Radar

AI Agents & Automation

How to Set a Token and Cost Budget for One Agent Task

Set a token cap before an agent task runs, and stop the run when it is reached.

Schematic with three numbered boxes: check past use, set the budget, stop at the cap.

An agent task can use many tokens, and a looping agent can use far more than the task is worth. A token budget set before the run, with a stop when it is reached, keeps the cost bounded. Open WebUI 0.12.5 added a Sessions view that shows administrators where tokens go, which makes it easier to set realistic budgets from real usage.

Checked on 2026-11-29. We did not run any tool for this guide. Every result below is an expected result, marked UNTESTED, for you to confirm on your own files.

Prerequisites

  • The price per token for your model, or the token counts from past runs
  • A token limit setting in your agent or a manual check
  • A record of tokens used by similar tasks

Steps

1. Look at past token use

Check the token counts of three similar past tasks and take the highest as a guide.

Expected result: Three past token counts are recorded, for example 4,200, 5,100 and 6,800.

2. Set the budget with margin

Set the budget above the highest past count, for example 10,000 tokens for a task that used 6,800.

Expected result: A budget number is written down and set.

3. Run and watch the count

Run the task and check the token count as it goes, or read it from the session log after.

Expected result: The run token count is recorded.

4. Stop at the budget and review

If the run hits the budget, stop it and read the log to see where the tokens went.

Expected result: The run stops at the budget, or finishes under it with the count recorded.

Worked example

A practice research task used 6,800 tokens last time. The budget was set to 10,000 tokens.

Past task Tokens used Under budget?
Task A 4200 Yes
Task B 5100 Yes
Task C 6800 Yes
Totals 16100

Expected result: Past tasks total 16,100 tokens and each stays under the 10,000 budget, so the budget is kept (UNTESTED – confirm it yourself.)

Verdict table

Check Expected result Pass?
Look at past token use Three past token counts are recorded, for example 4,200, 5,100 and 6,800. –
Set the budget with margin A budget number is written down and set. –
Run and watch the count The run token count is recorded. –
Stop at the budget and review The run stops at the budget, or finishes under it with the count recorded. –

Limits

  • Token counts do not include the cost of tool calls or search; check the full bill too.
  • A budget that is too low stops good work; base it on real past runs.

Sources

See all