Skip to main content
Glama

count_tokens

Count the exact number of tokens in a text string for a specific AI model.
Uses tiktoken for OpenAI models and estimates for others.

Args:
    text: The text to count tokens for
    model: The AI model to count tokens for. Options: gpt-4o, gpt-4o-mini, 
           gpt-4.1, claude-sonnet, claude-haiku, gemini-pro, gemini-flash,
           llama-4, deepseek-v3, mistral-large. Default: gpt-4o

Returns:
    Token count information including count, context window, and fit status

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes
modelNogpt-4o

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

TDQS

A4.6/5.0
Behavior4/5

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

No annotations are provided, so the description carries the burden of behavioral disclosure. It states that OpenAI models use tiktoken and others are estimates, and it details the return contents (count, context window, fit status). This goes beyond the schema and gives the agent useful expectations about accuracy and output.

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 efficiently structured: a one-sentence summary, a brief method note, and clear Args/Returns sections. Every sentence adds necessary information, and there is no repetition or filler, making it easy to parse quickly.

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 simple 2-parameter tool with an output schema, the description is complete. It covers the tool's purpose, the estimation method, all model options with defaults, and the nature of the return value. No critical gaps remain for an agent to invoke the tool correctly.

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

Parameters5/5

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

Schema coverage is 0% (the schema provides only types and a default), but the Args section fully describes both parameters. It explains what 'text' is, lists all 10 supported model options, specifies the default model, and clarifies behavior for each, fully compensating for missing schema descriptions.

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 opens with 'Count the exact number of tokens in a text string for a specific AI model', clearly identifying the verb (count) and resource (tokens for a specific model). It is distinct from the sibling conversion tools (e.g., convert_file, convert_url), which focus on format transformation, making purpose unambiguous.

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?

The description's clear focus on token counting makes the appropriate usage context obvious—an agent can immediately determine when token counting is needed. However, it does not explicitly state when not to use the tool or name alternatives, so it misses the top score for explicit exclusions.

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.

TDQS

A4.2/5.0
Disambiguation2/5

Several tools overlap: convert_url already supports ArXiv and YouTube, making convert_arxiv and convert_youtube redundant. convert_with_metadata duplicates convert_file/convert_url but adds a metadata header. Agents must read descriptions carefully to choose correctly.

Naming Consistency5/5

All tool names follow a consistent snake_case verb_noun pattern: convert_*, count_tokens, list_supported_formats, prepare_for_rag. No mixed conventions or vague verbs exist.

Tool Count5/5

9 tools is well-scoped for a document conversion service. Each tool has a distinct role (file, URL, batch, metadata, token counting, format listing, RAG preparation) without being bloated.

Completeness5/5

The domain of converting sources to Markdown is thoroughly covered: files, URLs, batch conversion, metadata, token counting, and RAG chunking. The only minor redundancy is the specialized source converters, but the core workflow is complete.

Resources