Skip to main content
Glama

tokens count

tokens_count
Read-only

Count tokens before you call a model: exact OpenAI counts (o200k for gpt-4o / 4.1 / o-series / gpt-5, cl100k for gpt-4 / 3.5) plus close estimates for Claude, Llama and Gemini, with chat-message overhead. Up to 2 million characters. Costs $0.002 USDC per call (x402).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textNo
messagesNoOr a chat messages JSON array

Schema Changelog

Changes observed during successful MCP inspections.

  1. Added

TDQS

A4.3/5.0
Behavior5/5

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

Annotations already establish readOnlyHint=true and openWorldHint=true, so the safety profile is covered; the description adds substantial context beyond that: exactness per model family, a hard input ceiling ('Up to 2 million characters'), chat-message overhead accounting, and an explicit per-call price with the x402 payment scheme. Price and input limits are exactly the operational facts an agent needs before invoking.

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

Conciseness4/5

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

Front-loaded with the core action, then layered with model coverage, limits, and cost in a compact block with no filler sentences. It is dense — a single colon-and-slash-laden run-on — but every clause carries distinct decision-relevant information, so nothing is wasted.

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

Completeness4/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 covers the key pre-call facts: accuracy per model family, input size limit, and cost. The remaining gap is the return shape (a single count versus a per-model breakdown) and whether text and messages are mutually exclusive, but for a two-parameter utility the definition is otherwise complete.

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?

Schema coverage is 50%: 'messages' carries a description while 'text' is bare. The description partially compensates by referencing chat-message overhead and the 2M-character ceiling, indirectly clarifying the text-vs-messages distinction, but it never defines the two parameters or says whether both may be supplied together. With names self-describing and half the schema documented, baseline 3 is appropriate.

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?

Starts with a specific verb+resource ('Count tokens') and immediately scopes it with model-specific detail (o200k for gpt-4o/4.1/o-series/gpt-5, cl100k for gpt-4/3.5, estimates for Claude/Llama/Gemini). This is unmistakably distinct from siblings like chat_completions, embed, or embeddings, which generate or vectorize rather than count.

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 phrase 'before you call a model' gives a clear triggering context: pre-flight cost/context budgeting ahead of a chat or completion call. However, it names no alternatives and states no exclusions (e.g., when to prefer a provider's own tokenizer or when the estimate is unsafe), so guidance is contextual but not comparative.

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