npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@trazum/tokenizer-openai

v2.4.1

Published

OpenAI's own tokenizer as an optional counter for Trazum: exact counts for the models it knows, and a refusal for every model it does not.

Readme

@trazum/tokenizer-openai

OpenAI's own tokenizer, as an optional counter for Trazum.

Install it and Trazum counts OpenAI prompts exactly instead of estimating them. Do not install it and nothing changes: @trazum/core declares no dependencies, and every figure goes on saying which counter produced it.

npm install @trazum/tokenizer-openai

Why it is a separate package

The rank tables are twenty-two megabytes. The zero-dependency promise in @trazum/core is load-bearing for the CI case this product is built around -- a gate that pulls a twenty-megabyte table into every build is a gate teams turn off -- so the only shape that improves the absolute figures without spending that promise is a package somebody installs on purpose.

Nothing in @trazum/core imports this. The counter is passed in through the TokenCounter seam that has been there since the beginning.

What it is worth

The heuristic in @trazum/core is published under a ±33% band measured against Anthropic's counter, and against OpenAI's it has been measured at 112.4% out at worst -- more than twice, on German prose. The estimator is not broken; it is calibrated for a tokenizer that packs Latin text far less densely than o200k_base does. This package removes the question.

Against the 47-sample corpus in this repository, measured through OpenAI's own API with a real key, this package reproduces every count exactly: 47 of 47, to the token.

What it refuses

A model it does not have the encoding for. Not a nearby encoding, not the newest one, not a default. gpt-5-codex and any model shipped since the rank tables were written are refused, because a count produced by guessing which table to use would go out labelled exact, and exact is the strongest word this tool uses about a number.

To claim it knows whose a model is. A Claude model refuses here as unknown-encoding rather than as wrong family. This package holds encodings, not a catalogue.

What the number is

The token count of the text. It is not the token count of a chat request: an API call wraps each message in role markers and primes the reply, and those tokens belong to the envelope rather than the prompt.

Usage

import { openaiCounter } from '@trazum/tokenizer-openai';

const counter = openaiCounter('gpt-5');
if (counter.ok) {
  console.log(counter.encoding);        // 'o200k_base'
  console.log(counter.count('hello'));  // 1
} else {
  console.log(counter.refusal.reason);  // 'unknown-encoding'
}

canCount(model) answers the same question without parsing a two-hundred-thousand-rank table, for a caller deciding what to say before it decides what to do.

Licence

MIT. Wraps js-tiktoken, also MIT.