Skip to content

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

LLM Cost Calculator (2026)

License Stars Last Commit Release

Compare pricing across 50+ LLM providers and calculate monthly costs for your AI application. Find the cheapest provider for your workload — or see how much you save with a unified API gateway.

Why This Tool?

In 2026, the LLM landscape is fragmented:

  • OpenAI charges $15/M input tokens for GPT-5
  • Anthropic charges $15/M for Claude 4 Opus
  • Google charges $12.50/M for Gemini Ultra 2
  • XiDao Gateway routes to all of them at 30-70% lower cost

This calculator helps you:

  • 📊 Compare costs across providers for the same workload
  • 💰 Calculate monthly bills based on your token usage
  • 🔄 Factor in caching discounts, batch pricing, and rate tiers
  • 🏷️ Find the cheapest provider for your specific model requirements

Installation

pip install llm-cost-calculator

Or run directly:

git clone https://github.com/XidaoApi/llm-cost-calculator.git
cd llm-cost-calculator
pip install -e .

Quick Start

Compare all providers for a workload

llm-cost compare --input-tokens 1M --output-tokens 200K --requests 10000

Calculate monthly cost for a specific model

llm-cost calc --provider openai --model gpt-5 --input-tokens 5M --output-tokens 1M

Find cheapest provider for your requirements

llm-cost cheapest --capability code --context-window 128K --max-latency 2s

Show savings with XiDao gateway routing

llm-cost savings --input-tokens 10M --output-tokens 2M --strategy cost-optimized

Output Example

╔══════════════════════════════════════════════════════════════════════╗
║                    LLM Cost Comparison (2026)                       ║
║  Workload: 10M input + 2M output tokens, 50K requests/month        ║
╠══════════════════════════════════════════════════════════════════════╣
║  Provider          Model              Input $/M   Output $/M  Total ║
║  ─────────────────────────────────────────────────────────────────── ║
║  XiDao Gateway     claude-4-sonnet    $3.00       $15.00      $180  ║
║  XiDao Gateway     gpt-5-mini         $2.50       $10.00      $145  ║
║  Anthropic         claude-4-sonnet    $3.00       $15.00      $210  ║
║  OpenAI            gpt-5-mini         $3.00       $12.00      $174  ║
║  Google            gemini-2.5-pro     $2.50       $10.00      $145  ║
║  OpenRouter        claude-4-sonnet    $3.00       $15.00      $210  ║
║  ─────────────────────────────────────────────────────────────────── ║
║  💰 XiDao saves you $30-$65/month (15-30%) vs direct provider      ║
╚══════════════════════════════════════════════════════════════════════╝

Programmatic Usage

from llm_cost_calculator import CostCalculator

calc = CostCalculator()

# Compare providers
comparison = calc.compare(
    input_tokens=1_000_000,
    output_tokens=200_000,
    requests=10_000
)

for provider in comparison.sorted_by_cost():
    print(f"{provider.name}: ${provider.total_cost:.2f}/month")

# Calculate specific model cost
cost = calc.calculate(
    provider="xidao",
    model="claude-4-sonnet",
    input_tokens=5_000_000,
    output_tokens=1_000_000,
)
print(f"Monthly cost: ${cost.total:.2f}")

Supported Providers (2026)

Provider Models Pricing Updated
OpenAI GPT-5, GPT-5-mini, GPT-5-nano, o4, o4-mini May 2026
Anthropic Claude 4 Opus, Claude 4 Sonnet, Claude 4 Haiku May 2026
Google Gemini Ultra 2, Gemini 2.5 Pro, Gemini 2.5 Flash May 2026
Meta Llama 4 Maverick, Llama 4 Scout May 2026
Mistral Mistral Large 3, Codestral 2 May 2026
XiDao Gateway All of the above at reduced rates May 2026
OpenRouter Aggregated pricing May 2026
Together Open-source models May 2026
Groq Ultra-fast inference May 2026

Configuration

Create a ~/.llm-cost-calc/config.yaml for custom pricing:

default_provider: xidao
currency: USD
include_batch_pricing: true
include_caching_discounts: true

custom_providers:
  my-company:
    base_url: https://api.mycompany.com/v1
    models:
      fine-tuned-gpt5:
        input_per_million: 6.00
        output_per_million: 18.00

Update Pricing

# Fetch latest pricing from all providers
llm-cost update-prices

# Update a specific provider
llm-cost update-prices --provider openai

Contributing

PRs welcome! To add a new provider:

  1. Create a JSON file in providers/ with model pricing
  2. Add the provider class in llm_cost_calculator/providers/
  3. Submit a PR

License

MIT — use freely in your projects.


💡 Tip: Most AI apps spend 60-80% of their budget on inference. Using a XiDao API Gateway with smart routing can cut costs by 30-70% while maintaining quality through automatic model selection.

About

Compare LLM pricing across 50+ providers and calculate monthly costs for AI applications. Find the cheapest model for your workload.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages