Skip to main content
Glama

count_tokens

Estimate token counts for text or chat messages to fit into a model's context window. Supports multiple model families with per-message overhead.

Instructions

Estimate tokens in a string or chat-message array. Fast, dependency-free, within ~10-20% of true tokenizer counts on English prose. Pass a model name to pick the right per-family estimator (openai, anthropic, google, llama, default).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputYesString or array of chat messages.
modelNoOptional model name (e.g. "gpt-5", "claude-sonnet-4-6"). Picks the closest estimator family.
overheadNoPer-message overhead in tokens (default depends on model family, usually 4-6).
Behavior4/5

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

With no annotations, description carries full burden. It discloses it's fast, dependency-free, and within 10-20% accuracy. No side effects mentioned, but the tool is read-only by nature, so acceptable.

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?

Three short sentences, no fluff. Front-loaded with purpose, then efficiency claims, then model parameter guidance. Every sentence earns its place.

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

Completeness3/5

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

No output schema, so description should ideally state what is returned (likely a number). Missing that. 3 params covered well, but return value omission leaves a gap.

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 100%, but description adds value: clarifies model parameter example families, overhead default range, and input types. Enriches beyond schema without redundancy.

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?

Description starts with 'Estimate tokens in a string or chat-message array,' clearly stating the verb and resource. It also adds context on speed and accuracy, making the purpose unmistakable.

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?

No explicit guidance on when to use this tool over siblings (fit_messages, list_estimators). It implies usage by mentioning model selection, but lacks when-not-to-use or alternative scenarios.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MukundaKatta/agentfit-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server