Estimate tokens without calling an API
Token counts drive cost, context limits, and truncation. You can ballpark them with arithmetic.
For English text, one token is roughly four characters, or about three quarters of a word. That is close enough to answer the only question that usually matters before you send a request: will this fit?
const estTokens = (s) => Math.ceil(s.length / 4);
Use it to guard a request, trim context, or warn a user before they paste a novel. When you need the exact number, run the model's real tokenizer, which our Token Counter does in your browser.