Open source · Prompt & Agent Workflows

Token Budget Estimator

Estimate input and output tokens before a workflow spends a model budget.

v0.1.0 · Node.js 22+ · MIT

Browse the public repository · View releases

You have a request about to be sent: a few messages, a handful of tool definitions, a model with a context window. Will it fit, and with room for the reply?

This walkthrough uses the tool's public README and checked-in example files. Run the command from a repository checkout with Node.js 22+; inspect the source before using it on your own files.

Run the checked-in example

# a multilingual request with two tool schemas, counted exactly: exits 0
node bin/token-budget-estimator.mjs --root examples/fits

# the same request against a 768-token window: exits 1
node bin/token-budget-estimator.mjs --root examples/over-budget

# the same request estimated for a tokenizer this tool does not count,
# where the band straddles the allowance: exits 2, "cannot tell"
node bin/token-budget-estimator.mjs --root examples/undetermined

# machine-readable report only
node bin/token-budget-estimator.mjs --root examples/fits --json | jq .summary

Read the result

A consumer piping stdout must handle the empty case. A configuration error never had a subject, so there is nothing to report about.

Where this check stops

Exceeding one is an incomplete result with a finding naming the limit — even when the part that was counted fits, because a total that omits an unknown tail is not a total. An unknown limit key is a configuration error.

Before adapting the command to your own workflow, review the accepted inputs, exit codes and safety boundaries in the README.

Compiled with AI assistance from checked-in public documentation and example scripts. Run the example and review the repository's current documentation before relying on its result.