MCPcopy Index your code
hub / github.com/anthropics/anthropic-tokenizer-typescript

github.com/anthropics/anthropic-tokenizer-typescript @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
3 symbols 11 edges 5 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Anthropic TypeScript Tokenizer

NPM version

⚠️ This package can be used to count tokens for Anthropic's older models. As of the Claude 3 models, this algorithm is no longer accurate, but can be used as a very rough approximation. We suggest that you rely on usage in the response body wherever possible.

Installation

npm install --save @anthropic-ai/tokenizer
# or
yarn add @anthropic-ai/tokenizer

Usage

import { countTokens } from '@anthropic-ai/tokenizer';

function main() {
  const text = 'hello world!';
  const tokens = countTokens(text);
  console.log(`'${text}' is ${tokens} tokens`);
}
main();

Status

This package is in beta. Its internals and interfaces are not stable and subject to change without a major semver bump; please reach out if you rely on any undocumented behavior.

We are keen for your feedback; please email us at support@anthropic.com or open an issue with questions, bugs, or suggestions.

Requirements

The following runtimes are supported:

  • Node.js version 12 or higher.
  • Deno v1.28.0 or higher (experimental). Use import { countTokens } from "npm:@anthropic-ai/tokenizer".

If you are interested in other runtime environments, please open or upvote an issue on GitHub.

Core symbols most depended-on inside this repo

countTokens
called by 5
index.ts
getTokenizer
called by 1
index.ts
main
called by 1
examples/demo.ts

Shape

Function 3

Languages

TypeScript100%

Modules by API surface

index.ts2 symbols
examples/demo.ts1 symbols

For agents

$ claude mcp add anthropic-tokenizer-typescript \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact