estimate_token_cost
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
| Name | Required | Description | Default |
|---|---|---|---|
| text | No | Raw text string to count tokens and calculate cost for. | |
| tokens | No | Optional raw token count to calculate cost directly. | |
| project_root | No | Root directory of the repository to calculate workspace ROI savings for. | . |
| export_agent_rules | No | Optional format to export agent rules: 'cursorrules', 'clinerules', 'markdown', or empty for cost estimation only. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |