Skip to content

tokcost

An instant, offline token + cost counter for LLM text. Point it at a file, pipe text in, or pass a handful of files — tokcost counts the tokens locally and, on request, estimates what that input would cost.

Token counts drive both your context budget and your bill, but they’re easy to lose track of while iterating on a prompt. tokcost is a daily-use tool for anyone building with LLMs: a fast, deterministic counter that runs entirely on your machine — no network round-trip, no API key — and always tells you exactly which encoding it used.

Terminal window
$ tokcost --cost -m gpt-4o prompt.md
[1m42[0m tokens [2m(prompt.md)[0m
[2mmodel: gpt-4o encoding: o200k_base[0m
[2m≈[0m [1m$0.0001[0m (input)[2m — approximate, editable pricing[0m

Offline & deterministic

Token counts come from gpt-tokenizer — pure JS, no network, no API key. Same input, same number, every time.

Files or stdin

Count a single file, pipe text in over stdin, or pass multiple files for per-file counts plus a combined total.

Cost estimates

The optional --cost flag estimates input dollars from a small built-in pricing table for common models.

Library too

Import countTokens and estimateCost into your own code — the CLI is a thin wrapper over the same functions.

tokcost resolves the model you pass (default gpt-4o) to a tiktoken encoding, runs the text through gpt-tokenizer locally, and prints the count. Add --cost and it multiplies that count by an approximate per-million-token input price from a small built-in table. Add --json and the whole result comes back as a structured object you can pipe into other tooling.

Counts are exact for OpenAI models. For claude-* and gemini-* there is no public local tokenizer, so tokcost approximates with the closest OpenAI encoding (o200k_base) — and it always prints the encoding it used, so the number is never a black box. See Models & pricing for the full mapping and caveats.


MIT   github.com/abdulmunimjemal/tokcost