Skip to main content
Glama

Estimate Multi Model Token Cost and Financial ROI

estimate_token_cost
Read-onlyIdempotent

Calculate exact token counts, compare LLM API billing costs across model providers, and estimate cumulative ROI savings from text, token counts, or a repository workspace.

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.

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "estimate_token_cost"
  }
}

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.6/5.0
Behavior5/5

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

Annotations already declare readOnly, idempotent, non-destructive and closed-world, but the description goes further with details annotations cannot carry: 100% offline local pricing table, zero credentials/auth, sub-5ms latency, deterministic pricing tables, and graceful handling of empty input. That is exactly the supplemental behavior context the dimension rewards.

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?

Well front-loaded with labeled sections and scannable bullets, so the agent can find behavior and usage fast. Slightly padded: the long sibling-differentiation clause in sentence one repeats what the 'When NOT to use' bullet already says, and the Returns line overlaps with the existing output schema.

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 4-parameter, zero-required tool with a full output schema and rich annotations, nothing consequential is missing. Inputs, behavioral envelope (offline, no auth, fast), error handling, and alternatives are all covered, so an agent could invoke it correctly on a first attempt.

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% and the description's parameter block largely restates the schema text rather than adding new meaning. It does reinforce the allowed values for 'export_agent_rules' ('cursorrules', 'clinerules', 'markdown', or empty), but offers no precedence rules for when both 'text' and 'tokens' are supplied, which is the one ambiguity worth resolving.

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 opening sentence names specific verbs and resources: exact token counts, comparative API billing costs across model families, and cumulative ROI savings. It explicitly contrasts with 'build_project_context' and 'prune_code_snippet' on the axis of financial/token metrics versus context construction or pruning, so an agent can route without opening a 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?

There is an explicit 'When to use' list (token evaluation, monthly spend forecasting, exporting .cursorrules/.clinerules) and an explicit 'When NOT to use' that names the exact sibling tools to use instead. No inference is required to pick between this and its neighbors.

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