Skip to main content
Glama

estimate_token_cost

Read-onlyIdempotent

Calculate exact token counts and compare API billing costs across model families to forecast LLM expenses and ROI savings.

Instructions

Calculates exact token counts, comparative API billing costs across major model families, and cumulative financial ROI savings, distinguishing from 'build_project_context' and 'prune_code_snippet' by evaluating financial costs and token metrics rather than constructing context trees or pruning code.

Parameters:

  • text (str, optional, default=''): Raw text string to count tokens and calculate cost for.

  • project_root (str, optional, default='.'): Root directory of the repository to calculate workspace ROI savings for.

  • tokens (int, optional, default=0): Optional raw token count to calculate cost directly.

  • export_agent_rules (str, optional, default=''): Optional format to export agent rules: 'cursorrules', 'clinerules', 'markdown', or empty for cost estimation only.

Behavior:

  • Read-only: Calculates metrics from text or token counts without disk modifications.

  • Idempotent: Deterministic pricing calculations based on standard provider pricing tables.

  • 100% Offline: Local pricing lookup table; zero network calls.

  • Auth & Rate Limits: Zero authentication or credentials required; execution latency <5ms.

  • Error Handling: Handles empty input gracefully by returning default workspace token estimations.

Usage Guidelines:

  • When to use: Evaluate token consumption, forecast monthly LLM API expenditures, or export agent rule configuration files (.cursorrules, .clinerules).

  • When NOT to use: Do not use for actively reducing token consumption by pruning repository code into AST signatures (use 'build_project_context' or 'prune_code_snippet' instead).

Returns: Markdown comparison table detailing input/output token counts, estimated USD costs per model provider, and percentage token reduction ROI.

Input Schema

NameRequiredDescriptionDefault
textNoRaw text string to count tokens and calculate cost for.
tokensNoOptional raw token count to calculate cost directly.
project_rootNoRoot directory of the repository to calculate workspace ROI savings for..
export_agent_rulesNoOptional format to export agent rules: 'cursorrules', 'clinerules', 'markdown', or empty for cost estimation only.

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed7 schema fields changedv7.3.2
    • addedInput schema / properties / export_agent_rules
      Added value: +{
      +  "default": "",
      +  "description": "Optional format to export agent rules: 'cursorrules', 'clinerules', 'markdown', or empty for cost estimation only.",
      +  "title": "Export Agent Rules",
      +  "type": "string"
      +}
    • changedInput schema / properties / project_root / description
      Previous value: -"Project directory to scan if text is empty (default: current directory)."New value: +"Root directory of the repository to calculate workspace ROI savings for."
    • removedInput schema / properties / reduction_mode
      Removed value: -{
      -  "default": "ultra",
      -  "description": "Reduction tier ('ultra', 'balanced', 'none') applied when scanning project_root.",
      -  "title": "Reduction Mode",
      -  "type": "string"
      -}
    • changedInput schema / properties / text / description
      Previous value: -"Optional raw text to estimate. If empty, analyzes context generated from project_root."New value: +"Raw text string to count tokens and calculate cost for."
    • addedInput schema / properties / tokens
      Added value: +{
      +  "default": 0,
      +  "description": "Optional raw token count to calculate cost directly.",
      +  "title": "Tokens",
      +  "type": "integer"
      +}
    • changedInput schema / title
      Previous value: -"_legacy_estimate_token_costArguments"New value: +"estimate_token_costArguments"
    • changedOutput schema / title
      Previous value: -"_legacy_estimate_token_costOutput"New value: +"estimate_token_costOutput"
  2. Changed7 schema fields changedv7.0.1
    • removedInput schema / properties / export_agent_rules
      Removed value: -{
      -  "default": "",
      -  "description": "Optional format to export agent rules: 'cursorrules', 'clinerules', 'markdown', or empty for cost estimation only.",
      -  "title": "Export Agent Rules",
      -  "type": "string"
      -}
    • changedInput schema / properties / project_root / description
      Previous value: -"Root directory of the repository to calculate workspace ROI savings for."New value: +"Project directory to scan if text is empty (default: current directory)."
    • addedInput schema / properties / reduction_mode
      Added value: +{
      +  "default": "ultra",
      +  "description": "Reduction tier ('ultra', 'balanced', 'none') applied when scanning project_root.",
      +  "title": "Reduction Mode",
      +  "type": "string"
      +}
    • changedInput schema / properties / text / description
      Previous value: -"Raw text string to count tokens and calculate cost for."New value: +"Optional raw text to estimate. If empty, analyzes context generated from project_root."
    • removedInput schema / properties / tokens
      Removed value: -{
      -  "default": 0,
      -  "description": "Optional raw token count to calculate cost directly.",
      -  "title": "Tokens",
      -  "type": "integer"
      -}
    • changedInput schema / title
      Previous value: -"estimate_token_costArguments"New value: +"_legacy_estimate_token_costArguments"
    • changedOutput schema / title
      Previous value: -"estimate_token_costOutput"New value: +"_legacy_estimate_token_costOutput"
  3. Changed5 schema fields changedv7.0.0
    • addedInput schema / properties / export_agent_rules
      Added value: +{
      +  "default": "",
      +  "description": "Optional format to export agent rules: 'cursorrules', 'clinerules', 'markdown', or empty for cost estimation only.",
      +  "title": "Export Agent Rules",
      +  "type": "string"
      +}
    • changedInput schema / properties / project_root / description
      Previous value: -"Project directory to scan if text is empty (default: current directory)."New value: +"Root directory of the repository to calculate workspace ROI savings for."
    • removedInput schema / properties / reduction_mode
      Removed value: -{
      -  "default": "ultra",
      -  "description": "Reduction tier ('ultra', 'balanced', 'none') applied when scanning project_root.",
      -  "title": "Reduction Mode",
      -  "type": "string"
      -}
    • changedInput schema / properties / text / description
      Previous value: -"Optional raw text to estimate. If empty, analyzes context generated from project_root."New value: +"Raw text string to count tokens and calculate cost for."
    • addedInput schema / properties / tokens
      Added value: +{
      +  "default": 0,
      +  "description": "Optional raw token count to calculate cost directly.",
      +  "title": "Tokens",
      +  "type": "integer"
      +}
  4. 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."
  5. First observedv0.1.0

TDQS

A4.4/5.0
Behavior4/5

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

Annotations already cover readOnly, idempotent, non-destructive and closed-world, but the description adds genuinely new traits: fully offline local pricing table, no auth/credentials, <5ms latency, deterministic pricing, and graceful handling of empty input. It does partly restate read-only/idempotent, keeping it below a 5.

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

Conciseness3/5

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

Front-loaded purpose sentence is strong, but the body duplicates annotation data (read-only, idempotent) and repeats every parameter already documented in the schema. The Behavior/Returns sections are useful but the entry as a whole is longer than needed.

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?

Covers purpose, inputs, behavior, error handling and return format, which is thorough for a zero-required-param read-only tool. The 'Returns' section partially duplicates the existing output schema, but nothing an agent needs to invoke it is missing.

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%, so baseline is 3, but the description adds real value by enumerating the accepted values for export_agent_rules ('cursorrules', 'clinerules', 'markdown') — the schema declares no enum for that field. It also clarifies that project_root drives ROI savings specifically.

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 precise verbs and resources — token counting, comparative API billing cost estimation, and cumulative ROI — and explicitly distinguishes itself from 'build_project_context' and 'prune_code_snippet' by function rather than name alone.

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?

Provides an explicit 'When to use' list and a 'When NOT to use' clause that routes the agent to two named alternatives for token-reduction tasks. The decision boundary is unambiguous.

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