coder

AI Tokenizer — AI skill for Claude Code

AI community

A faster than tiktoken tokenizer with first-class support for Vercel's AI SDK.

How to install AI Tokenizer

This entry records only its repository, not the path inside it, so there is no exact command to give. Open coder/ai-tokenizer and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

What AI Tokenizer does

A faster than tiktoken tokenizer with first-class support for Vercel's AI SDK.

Alternatives in AI

  • Cumora — Where agent teams gather 3.2k ★
  • Anthropic SDK TypeScript — Access to Anthropic's safety-first language model APIs in TypeScript 2.1k ★
  • Observal — Observal is an AI agent registry with first in class observabilty and eval framework 679 ★

README

ai-tokenizer

[![CI](https://github.com/coder/ai-tokenizer/actions/workflows/ci.yml/badge.svg)](https://github.com/coder/ai-tokenizer/actions/workflows/ci.yml) [![npm version](https://img.shields.io/npm/v/ai-tokenizer)](https://www.npmjs.com/package/ai-tokenizer) [![npm downloads](https://img.shields.io/npm/dm/ai-tokenizer)](https://www.npmjs.com/package/ai-tokenizer)

A faster than tiktoken tokenizer with first-class support for Vercel's AI SDK.

  • Supports the AI SDK tool and message schema
  • No WASM; highly portable; 5-7x faster than tiktoken WASM
  • >=97% accuracy for top models (GPT-5, Claude Sonnet, Gemini):
Model ~500 tokens ~5k tokens ~50k tokens
openai/gpt-5 99.16% 99.43% 99.47%
anthropic/claude-opus-4.5 98.48% 98.56% 99.79%
google/gemini-3-pro-preview 98.70% 98.77% 98.91%

[Try it on the website:](https://coder.github.io/ai-tokenizer/)

[![Demo](https://raw.githubusercontent.com/coder/ai-tokenizer/main/demo.png)](https://coder.github.io/ai-tokenizer/)

Usage

Install:

bun install ai-tokenizer

Estimate tokens with the AI SDK:

import Tokenizer, { models } from "ai-tokenizer";
import { count } from "ai-tokenizer/sdk";
import * as encoding from "ai-tokenizer/encoding";

// Find the respective model.
const model = models["openai/gpt-5"];
const tokenizer = new Tokenizer(encoding[model.encoding]);
const result = count({
  tokenizer,
  model,
  // Every message is counted separately
  messages,
  // Tool descriptions and input schemas are counted
  tools,
})

// {
//   total: 150,
//   messages: [
//     {
//       total: 120,
//       content: [
//         { type: "text", total: 100 },
//         { type: "tool-call", total: 20, input: 15 }
//       ]
//     }
//   ],
//   tools: {
//     total: 30,
//     definitions: {