Skip to content
Agents tracked: 440 Downloads (7d): 202M down 19.5% GitHub stars: 10.4M Releases (7d): 607 Agent status: all upSince last limit reset: Claude 28d · Codex 0d Updated Oct 21, 2026

GPT Tokenizer

JavaScript BPE tokenizer with pricing and token counts for OpenAI models.

Prompts, structured output and evals npm MIT

Used in agent projects
14
0.3% of 4,818 JS/TS repos built with AI coding agents; 39 counting our dependency samples
Gid Score
44 /100
#2138 of 3,794 tools, #31 in prompts, structured output and evals · ranking
Rank in prompts, structured output and evals
#6 of 72
by use in those projects
Downloads
1.2M
npm, last 7 days, gpt-tokenizer
GitHub stars
855
63 forks · last push Oct 18, 2026

How GPT Tokenizer is used

GPT Tokenizer is a dependency in 14 of the 6,208 public GitHub projects set up for AI coding agents that we scanned, too few to describe it from them alone. Our scan also samples projects by dependency (Solana 2,661, Ethereum and EVM 1,496, 3D and games 2,818, agent frameworks and SDKs 10,983); counting those, it appears in 39 projects, and what it is used with below comes from all of them. The most used alternative in our scan is tiktoken (JavaScript) (10 projects). Projects that use it most often also use OpenAI (46.2%), Anthropic SDK (43.6%), Husky (43.6%).

GPT Tokenizer popularity over time

Top tools by Gid Score

GPT Tokenizer: downloads per weeknpm, gpt-tokenizer 1,160,391
GPT Tokenizer: GitHub starsniieani/gpt-tokenizer 855

Gid Score 44: downloads 65, use in agent projects 37, GitHub stars 9, downloads trend 66 (each 0-100). How it is calculated.

Often used with GPT Tokenizer

OpenAI46.2% of GPT Tokenizer projects · 10.1× more than average
Anthropic SDK43.6% of GPT Tokenizer projects · 11.7× more than average
Husky43.6% of GPT Tokenizer projects · 4.3× more than average
Google Generative AI35.9% of GPT Tokenizer projects · 13.2× more than average
lint-staged35.9% of GPT Tokenizer projects · 4.6× more than average
uuid35.9% of GPT Tokenizer projects · 7.6× more than average
tsx46.2% of GPT Tokenizer projects · 3.1× more than average
LangChain.js33.3% of GPT Tokenizer projects · 55.9× more than average

From all 39 projects in our scan that use GPT Tokenizer, including the dependency samples.

By coding agent

Claude Code0.3% of projects set up for it
Cursor0.4% of projects set up for it
GitHub Copilot0.3% of projects set up for it

Share of public repos configured for each agent that list GPT Tokenizer as a dependency.

What GPT Tokenizer projects add to it

Share of the 14 public projects built with AI coding agents that use GPT Tokenizer and also depend on each package. From our scan of 6,208 repos, updated Oct 20, 2026.

JavaScript linter eslint69.2%
Schema validation zod53.8%
OpenAI SDK openai46.2%
Git hooks husky43.6%
Lint staged files lint-staged35.9%
Vercel AI SDK ai30.8%

Using GPT Tokenizer with an AI coding agent

Rules to paste into AGENTS.md or CLAUDE.md

Our summary of the project's own guidance. [1][3] Which file does your agent read?

## GPT Tokenizer
- A bare `import ... from 'gpt-tokenizer'` uses `o200k_base` (GPT-5, GPT-4.1, GPT-4o, o-series). For other models import `gpt-tokenizer/model/<model>`; for an unlisted model with a known encoding import `gpt-tokenizer/encoding/<encoding>`.
- For limit checks use `isWithinTokenLimit(input, limit)`, not `encode(text).length`. It returns `false` when over the limit, otherwise the token count.
- When calling `encodeChat` from the default import, pass the model name. Otherwise import the model-specific module.
- Special tokens are disallowed by default. Pass `{ allowedSpecial: ALL_SPECIAL_TOKENS }` or a custom `Set` only when the input is meant to contain them.
- Use `countChatCompletionTokens` for requests with function definitions, only on models that support `function_calling`.
- `estimateCost` needs a model spec, from a model import or as the second argument. Treat fields like `main?.input` as possibly missing.
- In the browser, import the ES module (`https://unpkg.com/gpt-tokenizer/esm/main.js`) and pin a version. UMD bundles were removed in 4.0.0.
Minimal code example: count tokens for a function-calling request
import {
  countChatCompletionTokens,
  type ChatCompletionRequest,
} from 'gpt-tokenizer/model/gpt-4o'

const request: ChatCompletionRequest = {
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: 'Find the weather for San Francisco.' },
  ],
  functions: [
    {
      name: 'get_weather',
      description: 'Look up the weather for a city.',
      parameters: {
        type: 'object',
        required: ['city'],
        properties: {
          city: { type: 'string' },
          unit: { type: 'string', enum: ['celsius', 'fahrenheit'] },
        },
      },
    },
  ],
}

const promptTokenEstimate = countChatCompletionTokens(request)

Code: MIT, © niieani, from the project README [1] · Open the playground

What GPT Tokenizer is

gpt-tokenizer is a TypeScript Byte Pair Encoding encoder and decoder for OpenAI models, published on npm as gpt-tokenizer under the MIT license. The repository describes it as a "Port of OpenAI's tiktoken with additional features". It was created on 2023-03-22. The latest release is 4.0.0, published 2026-08-16.

It turns text into token integers and back. A plain import uses o200k_base, the encoding the README gives for GPT-5, GPT-4.1, GPT-4o and the o-series. Other models get their own import path, such as gpt-tokenizer/model/gpt-3.5-turbo, and any encoding can be loaded directly, such as gpt-tokenizer/encoding/cl100k_base. Beyond encode and decode, there are helpers for chats, token limits, function-calling requests, streaming generators and cost estimates.

It is for JavaScript and TypeScript developers who need token counts for OpenAI models in Node or in the browser. The builders cited below used it for browser-based token counters and for an n8n node that counts tokens and cost before calling OpenAI. [1][2]

Why teams pick it

  • Limit checks that stop early. isWithinTokenLimit takes a string or a chat and returns false once the limit is exceeded, or the token count if it fits. The README says it does this without encoding the entire input. [1]
  • Counts function-calling requests, not just text. countChatCompletionTokens takes a whole chat completion request and counts message overhead, function definitions and pinned function calls. It is only available on models that support function_calling. [1]
  • Prices and limits bundled in. The package carries an OpenAI model catalog with context limits, capabilities and pricing. estimateCost returns USD figures for the main and batch APIs, including cached tokens where data exists. [1]
  • Synchronous and streaming. The README says it can be loaded and used without async/await. It also has generator versions of the encoder and decoder, including decodeAsyncGenerator for async token streams. [1]
  • No global cache. The maintainers point out that the package keeps no global cache. They contrast this with the memory leaks of the original GPT-3-Encoder implementation. [1]
  • Runs client-side in a Web Worker. LaunchBoosts runs the library in a Web Worker in the browser to count pasted text, so long pastes do not block the page. [6]

Know before you start

  • Exact only for OpenAI encodings. The package implements OpenAI's encodings. LaunchBoosts applies the o200k count to Claude and Gemini only as an estimate, and tells users to check with each provider's own counting API. [6]
  • 4.0.0 dropped UMD bundles. Release 4.0.0 is a breaking change for script-tag users. Browser use now goes through the ES modules, and the README says to pin a version in production. [3]
  • Special tokens are refused by default. Text containing special tokens is not encoded as such unless you allow them through EncodeOptions. The README also notes that not every model supports every special token. [1]
  • Chat encoding needs a model. encodeChat from the default import needs the model name passed in. Otherwise you must import the model-specific module. [1]
  • Cost data can be missing. estimateCost needs a model spec, either from a model import or as an argument. Even then, the README warns that pricing may not exist for every model. [1]

Built with GPT Tokenizer

Real uses, from the builders' own posts

Free GPT-4 and GPT-3.5 token counter

Koala (koala.sh)

Free online GPT-4/GPT-3.5 token counter

The question
Koala writes that OpenAI's own tokenizer tool is for legacy models and is not accurate for GPT-4 or GPT-3.5.
What they built
A free web token counter and a POST API at <code>https://koala.sh/api/tokens/</code>, built on gpt-tokenizer with the <code>cl100k_base</code> encoder.

gpt-tokenizer Source [4]

n8n Community Node: GPT-Tokenizer

geckse (Marcel), n8n community

n8n node for token counts and costs

The question
The author found it hard to know how many tokens a prompt would take before sending it to OpenAI, and says estimating with textLength/4 was not good enough.
What they built
A community node, <code>n8n-nodes-gpt-tokenizer</code>. It encodes and decodes BPE tokens, measures token length, calculates cost before an OpenAI call, and splits text into chunks that match a set token limit. It uses gpt-tokenizer under the hood.

gpt-tokenizer n8n Source [5]

Token Counter for GPT, Claude & Gemini Prompts

LaunchBoosts

Browser token counter with per-model cost table

What they built
A free counter that encodes text with <code>o200k_base</code> using gpt-tokenizer in a Web Worker. It shows context-window use and cost per call across GPT, Claude and Gemini models.
Result
The page says the count is exact for OpenAI's <code>o200k_base</code> models, and that nothing pasted is uploaded or stored. Claude and Gemini rows are marked as estimates.

gpt-tokenizer Source [6]

Free AI Tokens Counter

Mahmoud Zalt (zalt.me)

Private in-browser AI token counter

What they built
A free token counter that runs gpt-tokenizer in the browser. It shows token counts, token IDs and decoded strings.
Result
The page says text never leaves the user's device, and that the tool works offline after the first page load.

gpt-tokenizer Source [7]

See it running

GPT Tokenizer Playground ↗

Official in-browser playground for trying the tokenizer.

playground browser Source

Official live demos by the maintainers; they open on the project's site and run WebGL in your browser. [1]

Who uses it, as listed by the maintainers

Microsoft (Teams, GenAIScript) Elastic (Kibana) Effect TS CodeRabbit Rivet by Ironclad

As listed by the source; we have not checked each one. [1]

Project facts

Latest version4.0.0, August 16, 2026 [3]
On GitHub sinceMarch 2023 [2]
LicenseMIT [2]

On AgentGid: All prompts, structured output and evals Husky Anthropic SDK Testing Library

How GPT Tokenizer is funded

Most funded tools

GitHub Sponsors

@niieani0 current sponsors

GitHub shows how many people and companies sponsor an account, not how much they pay. Sponsors of a person back all of their work.

Ways to fund GPT Tokenizer

GitHub Sponsors

As the maintainers list them in FUNDING.yml on GitHub. Checked Oct 20, 2026.

Install

Packagenpm install gpt-tokenizer
Main stacksTypeScript / JavaScript (22), Next.js (15), Python (1), Rust (1)
Example projectsyamadashy/repomix, HoangNguyen0403/agent-skills-standard, Doist/todoist-mcp, n-WN/SubgroupX, vual/lobe-chat-pro

Alternatives to GPT Tokenizer

All prompts, structured output and evals

Tools that do the same job, so a project picks one or the other. Add-ons and libraries used alongside GPT Tokenizer are not listed here; they are in "Often used with".

Tool Gid Score Used in agent projectsDownloads / wk GitHub starsLicense
tiktoken (JavaScript) npm
JavaScript/WASM bindings for OpenAI's tokenizer for token counting.
43 10 (0.2%) 806K 1,073 MIT
js-tiktoken npm
JavaScript implementation of OpenAI's tiktoken for counting and encoding tokens.
51 5 (0.1%) 5.7M 1,073 MIT
tokenx npm · new in the catalog
Fast token count estimates for LLM prompts in a 2 kB bundle.
37 2 (0.0%) 1.5M 185 MIT

More in Prompts, structured output and evals: Ultracite tiktoken (Python) tokenizers LangSmith Langfuse (Python) TokenLens @graphql-codegen/typescript-operations partial-json

Sources

  1. GPT Tokenizer README (GitHub)
  2. GitHub repository
  3. GitHub releases
  4. Koala (koala.sh): Free online GPT-4/GPT-3.5 token counter powered by gpt-tokenizer
  5. n8n community node author: n8n community node counting tokens and costs via gpt-tokenizer
  6. LaunchBoosts: Free browser token counter for GPT, Claude and Gemini prompts
  7. Zalt: Free in-browser AI token counter built on gpt-tokenizer

Description written by AgentGid from these official pages, checked Oct 13, 2026. Usage numbers come from our own scan. Claims by the maintainers are quoted, not tested by us.

Is GPT Tokenizer right for your project? Ask AgentGid →