Example
Input
Model: GPT-4o · Text: "Hello, nice to meet you."
Output
7 tokens · 24 characters · 0.01% of the 128K context · estimated input cost
Note
The same sentence tokenizes differently per model because vocabularies differ. GPT models are exact (tiktoken is public); Claude and Gemini are estimates because their tokenizers are not published.
Usage / FAQ
When to use
- Check a prompt fits the model's context window before sending it
- Size chunks by tokens when splitting a long document
- Get a rough cost figure for an API call before budgeting
- Compare how many tokens the same content costs in different languages
- Decide how many documents fit in the context of a RAG pipeline
FAQ
- Q.Why does the token count differ per model?
- A.Because each tokenizer has its own vocabulary. Even within OpenAI, GPT-4 uses cl100k_base while GPT-4o uses o200k_base — and a larger vocabulary splits the same sentence into fewer tokens.
- Q.What is the difference between "exact" and "estimate"?
- A.OpenAI publishes tiktoken, so the browser can compute exactly what the API will charge. Claude and Gemini keep their tokenizers private, so the number shown is the GPT count with a correction factor applied — use each vendor's token-count API when you need the exact figure.
- Q.The count doesn't match my actual bill.
- A.The number here reflects the raw text you typed. A real API call adds message-format overhead (roles, system prompt, tool definitions), and output tokens are billed separately, so real usage runs higher.
- Q.Do non-English languages cost more tokens?
- A.Usually yes. Mainstream tokenizer vocabularies are trained mostly on English text, so an English word often maps to a single token while other scripts get split into several pieces. The same meaning then costs more money and more of the context window.
Fun facts
BPE (Byte Pair Encoding), the basis of today's LLM tokenizers, started life as a data compression algorithm in 1994. Sennrich et al. borrowed it in 2016 to handle rare and unseen words in machine translation, and it became the NLP default from there.
arXiv — Neural Machine Translation of Rare Words with Subword UnitsThe same content costs wildly different token counts across languages. A 2023 study found gaps of up to 15× between languages in mainstream commercial tokenizers — and on APIs billed per token, that gap is a price difference.
arXiv — Language Model Tokenizers Introduce Unfairness Between LanguagesOpenAI's tiktoken ships a different vocabulary per model family — roughly 100k entries in cl100k_base (GPT-3.5/4) and about 200k in o200k_base (GPT-4o onward). A bigger vocabulary means fewer tokens for the same sentence, so switching models means redoing your prompt-length math.
GitHub — openai/tiktoken
Related tools
- JSON Formatter / Validator
Format, validate, and minify JSON strings. Adjust indent and optionally sort keys. Runs entirely in your browser.
- String Case Converter
Convert strings between camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE, and Title Case — all six cases shown side-by-side.
- Regex Tester
Test JavaScript regular expressions with live match results. Supports g/i/m/s/u/y flags and capture groups.
- Markdown Preview
Render Markdown to HTML side-by-side. Supports CommonMark + GFM (tables, fenced code, task lists). Everything runs in your browser.
- HTML → Markdown
Convert HTML into Markdown. Headings, lists, links, code, tables, blockquotes. Uses the browser's DOMParser — accurate, 0 dependency.
- YAML ↔ JSON
Convert between YAML and JSON. Tolerates comments and multiline strings on the YAML side. Everything runs in your browser.
- Text Diff
Compare two texts and highlight added/removed lines, words, or characters.
- JSON Diff
Compare two JSON values, with optional key sorting and JSON-aware error messages.
- CSV ↔ JSON
Convert between CSV and JSON. Handles quoted fields, custom delimiters, and header rows.
- SQL Formatter
Format SQL queries with proper indentation and keyword casing. Supports PostgreSQL, MySQL, SQLite, and standard dialects.
- XML Formatter
Pretty-print or minify XML with attribute preservation. Handles SOAP, sitemaps, and config files.
- XML ↔ JSON
Convert between XML and JSON with attribute and element handling.
- Smart Paste
Paste any text and get tool recommendations — JSON, JWT, Base64, URL, UUID, Cron, and 9 more types auto-detected.
- Lorem Ipsum
Generate placeholder text in words, sentences, or paragraphs. Classic Lorem Ipsum or randomized.
- JSON Path
Query JSON with JSONPath expressions ($.store.book[*].author etc.) and inspect matches.
- JSON Schema Validator
Validate JSON data against a JSON Schema (Draft 2020-12). Powered by Ajv with format support.
- JSON Schema Generator
Generate a JSON Schema (Draft 2020-12) from a sample JSON. Infer types, required fields, and nested structures automatically.
- HTML Formatter
Beautify or minify HTML with proper indentation. Preserves pre/textarea whitespace.
- CSS Formatter
Beautify or minify CSS with proper indentation. Configurable selector and property style.
- JavaScript Formatter
Beautify or minify JavaScript with indent options. Powered by js-beautify.
- TOML ↔ JSON
Convert between TOML (Tom's Obvious Minimal Language) and JSON. Used in Cargo.toml, pyproject.toml, etc.
- INI ↔ JSON
Convert INI configuration to JSON and back. Supports sections, comments (; or #), and key=value.
- JSON → TypeScript
Generate TypeScript interfaces from a JSON sample. Nested objects become separate interfaces.
- JS Object → JSON
Convert a JavaScript object literal (unquoted keys, single quotes, trailing commas, comments) into standard JSON. Lenient parser, strict output.
- Slug Generator
Convert text into a URL-safe slug. Configurable separator, lowercase, and accent stripping.
- ASCII Tree
Convert indented text or path list into a box-drawing tree (├── │ └──).
- Diff Patch
Generate a unified diff (-u) patch from two text inputs. Compatible with `git apply` / `patch -p0`.
- Mock Data
Generate fake JSON records and SQL INSERT seed data — names, emails, custom fields, UUIDs, dates, and more. 0 dependency.
- MongoDB Extended JSON
Convert MongoDB Extended JSON (EJSON) between Canonical and Relaxed forms, or strip BSON wrappers to plain JSON. Recognizes 16 wrapper types ($oid/$date/$numberLong/$numberDecimal/$binary/...).
- Kubernetes YAML Visualizer
Paste Kubernetes manifests and see the resource graph — Deployments, Services, Ingresses, ConfigMaps, Secrets, PVCs, and how they connect. Everything runs in your browser.
- Docker Compose Visualizer
Paste docker-compose.yml and see services, networks, volumes, and depends_on as an interactive graph. Everything runs in your browser.
- PDF Text Extractor
Extract text from a PDF file — page by page or as a single document. Markdown-friendly output, all client-side.
- PPTX Text Extractor
Extract slide text from a .pptx file — plain / markdown / per-slide. Great for converting decks to markdown. All client-side.
- Regex Railroad Diagram
Visualize your regex as a railroad diagram — trace branches, groups, and quantifiers at a glance, in your browser.
- Word & Character Counter
Count characters (with/without spaces), words, sentences, paragraphs, lines, and bytes in real time — free, in your browser.