Skip to main content
Glama

Count tokens

ai_token_count
Read-onlyIdempotent

Count LLM tokens in text or files using OpenAI tiktoken tokenizers, and check whether the text fits common context windows (8k–1M).

Instructions

Count LLM tokens in a text or text file with the OpenAI tiktoken tokenizers ("o200k_base", default, used by GPT-4o and the o-series; or "cl100k_base", used by GPT-4/3.5 and text-embedding-3). Also returns characters and words, and whether the text fits in common context windows (8k, 32k, 128k, 200k, 1M: e.g. "fits in 200k: yes"). Claude's tokenizer is not public, so for Claude the count is an estimate (typically within ~10-20%; Claude usually needs a little more), returned as a rough range. Runs locally, no API calls. Give "text" or "path" (file path or base64). Large texts (many MB) take a few seconds.

Input Schema

NameRequiredDescriptionDefault
pathNoOr: a UTF-8 text/markdown file, as a local path or base64 (raw or a data: URI).
textNoThe text (inline).
encodingNoTokenizer: "o200k_base" (GPT-4o / o-series, default) or "cl100k_base" (GPT-4 / GPT-3.5 / text-embedding-3).o200k_base

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.7/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already establish that the tool is read-only, local, and idempotent. The description adds important behavior beyond that: no API calls, multi-second latency for large texts, approximate Claude token counts with a typical error range, and additional outputs such as characters, words, and context-window fit.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose and then layers on encoding choice, Claude estimation caveats, local execution, input form, and large-text latency. Despite being dense, every sentence contributes operational information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no output schema, the description still explains the return values: token count, characters, words, and context-window fit. It also covers estimation caveats for Claude and performance for large inputs, leaving little an agent needs to know before calling it.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is already 100%, but the description adds useful clarifications: text and path are alternatives, path may be a local path or base64, and encoding maps to specific model families with a default. It mostly reinforces the schema rather than introducing extensive new parameter semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb and resource: count LLM tokens in text or a text file, and names the tokenizer families used. It is clearly distinct from adjacent utilities such as text_word_count because it emphasizes LLM token counting, encoding choice, and context-window fit.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives clear usage context: provide text or a path, choose o200k_base for GPT-4o/o-series and cl100k_base for GPT-4/3.5, and expect an estimate for Claude. It does not explicitly name alternatives or say when not to use this tool, so it falls short of the highest usage-guidance tier.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools