Skip to main content
Glama

Count tokens

count_tokens
Read-onlyIdempotent

Count tokens for text in o200k_base and cl100k_base side by side, plus approximate Claude/Gemini/Llama counts with method notes. OpenAI counts (o200k_base, cl100k_base) are exact for those tokenizers. Claude, Gemini and Llama counts are APPROXIMATE (proxy encoding; real tokenizers differ, often by 10-20%, and newer Claude tokenizers by ~30% or more). Cost estimates use a dated price table (prices_as_of 2026-10-27) and are estimates, not live billing. Stateless: text is not stored or logged; no URL fetching. Max input is 256 KB. A single unbroken run of characters near that cap may hit a CPU timeout (503); normal text at the cap is supported.

Input Schema

NameRequiredDescriptionDefault
textYesText (≤256 KB). URLs are not fetched.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.3/5.0
Behavior5/5

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

Annotations already declare readOnlyHint, idempotentHint, destructiveHint false, and openWorldHint false, but the description adds substantial behavioral context beyond them: statelessness, no URL fetching, 256 KB input cap, possible 503 on pathological unbroken runs near the cap, exact vs approximate tokenizer caveats with variance estimates, and a dated cost-estimate caveat. These details materially help an agent invoke the tool correctly.

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 adds precise caveats about exactness, approximations, cost estimates, statelessness, size limits, and timeout behavior. Every sentence provides useful operational information without repetition.

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?

For a stateless, read-only token-counting tool with one fully described parameter and no output schema, the description covers what an agent needs: what is counted, which tokenizers are exact vs approximate, cost-estimate caveats, storage behavior, input limit, and a known failure mode. No critical context appears missing.

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

Parameters3/5

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

There is only one parameter, text, and schema description coverage is 100%, so the schema already carries parameter semantics. The description reinforces the 256 KB cap and says URLs are not fetched, but that information is also present in the schema, so it does not add significant meaning beyond structured data.

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 tokens for provided text across named tokenizers (o200k_base and cl100k_base) with additional approximate model counts. It clearly distinguishes exact OpenAI counts from approximate Claude/Gemini/Llama counts, so an agent can tell what the tool is for without opening the schema.

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

Usage Guidelines3/5

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

Usage is implied by the capability description: use this for token counting across multiple tokenizer families. However, it does not explicitly say when to use this tool versus siblings such as estimate_cost, chunk_text, or truncate_to_budget, nor does it state exclusions or alternative-selection guidance.

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

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources