Skip to main content
Glama

estimate_token_cost

Calculate exact token counts and estimated USD costs across LLM providers for text or project directories before sending prompts to commercial APIs.

Instructions

Calculates exact token count and estimated API prompting cost (USD) across major LLM providers (OpenAI GPT-4o, Claude 3.7 Sonnet, Groq, NVIDIA NIM, and Ollama $0) for a given text or directory.

Behavior:

  • Read-only: Mathematical cost projection; does NOT invoke provider APIs or incur financial billing.

  • Idempotent: Produces exact calculations for identical token counts.

  • 100% Offline: Uses local pricing tables without external HTTP queries.

Usage Guidelines:

  • When to use: Estimate prompt token volume and dollar costs before sending large codebase context to commercial LLM APIs.

  • Sibling Routing: To track team monthly/annual cumulative ROI savings and compression metrics over time, use 'get_token_savings_metrics'.

Returns: Markdown table comparing per-million token rates and total estimated costs across major models.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textNoOptional raw text to estimate. If empty, analyzes context generated from project_root.
project_rootNoProject directory to scan if text is empty (default: current directory)..
reduction_modeNoReduction tier ('ultra', 'balanced', 'none') applied when scanning project_root.ultra

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed3 schema fields changedv0.1.1
    • addedInput schema / properties / project_root / description
      Added value: +"Project directory to scan if text is empty (default: current directory)."
    • addedInput schema / properties / reduction_mode / description
      Added value: +"Reduction tier ('ultra', 'balanced', 'none') applied when scanning project_root."
    • addedInput schema / properties / text / description
      Added value: +"Optional raw text to estimate. If empty, analyzes context generated from project_root."
  2. First observedv0.1.0

TDQS

A4.6/5.0
Behavior5/5

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

With no annotations, the description carries the full burden and does so well: it declares read-only status ('does NOT invoke provider APIs or incur financial billing'), idempotency, and 100% offline operation with local pricing tables. It also states the return shape (a Markdown comparison table) and the $0 Ollama case, covering the safety and behavior profile an agent needs.

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 purpose, then cleanly sectioned into Behavior, Usage Guidelines, and Returns. The labeled sections make it easy to scan, though the multi-line formatting is slightly heavier than strictly necessary for a three-parameter tool.

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 tool with no annotations, this covers everything needed: what it computes, that it is offline/safe/non-billing, when to use it, the sibling alternative, and a brief note on returns (output schema exists, so return detail is not required). Nothing an agent needs to call it correctly is 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?

Schema description coverage is 100%, so the schema already documents all three parameters, giving a baseline of 3. The description adds only a light gloss ('for a given text or directory') and does not explain reduction_mode ('ultra', 'balanced', 'none') beyond what the schema already provides.

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?

States a specific verb+resource ('Calculates exact token count and estimated API prompting cost') and scopes it to named providers (OpenAI GPT-4o, Claude 3.7 Sonnet, Groq, NVIDIA NIM, Ollama). It also distinguishes itself from the sibling get_token_savings_metrics, so an agent can route without opening either schema.

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

Usage Guidelines5/5

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

Includes an explicit 'When to use' condition (estimating prompt/cost before sending large codebase context to commercial APIs) and an explicit 'Sibling Routing' exclusion pointing to get_token_savings_metrics for cumulative ROI tracking. Both the trigger and the alternative are named directly.

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