Skip to main content

Realtime OpenRouter LLM API call cost estimator

Project description

mamood-llm-cost-estimator

Realtime OpenRouter LLM API call cost estimator for Python.

Features

  • Fetches live model pricing from OpenRouter.
  • Estimates input, cached input, output, and total call cost.
  • Works as both a Python library and a CLI.
  • Built and managed with uv.
  • Uses OpenRouter public /models endpoint for pricing (API key optional).

Install

uv add mamood-llm-cost-estimator

Or from source:

uv sync

Python usage

from mamood_llm_cost_estimator import OpenRouterClient, TokenUsage

client = OpenRouterClient(api_key="YOUR_OPENROUTER_API_KEY")
usage = TokenUsage(input_tokens=1500, output_tokens=700, cached_input_tokens=300)

cost = client.estimate_model_cost(model="openai/gpt-4o-mini", usage=usage)
print(cost.as_dict())

models = client.list_models()
first = models[0]
print(first.id, first.provider, first.context_window, first.input_price_per_million_usd)

CLI usage

mamood-cost \
  --model openai/gpt-4o-mini \
  --input-tokens 1500 \
  --output-tokens 700 \
  --cached-input-tokens 300 \
  --api-key "$OPENROUTER_API_KEY"

Dev setup

uv sync
uv run python -m mamood_llm_cost_estimator --help

Build & publish to PyPI

  1. Set your version in pyproject.toml.

  2. Build distributions:

    uv build
    
  3. Publish (token-based):

    uv publish --token <PYPI_TOKEN>
    

Project owner: Amirhossein Mahmoudi (@ammahmoudi)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mamood_llm_cost_estimator-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mamood_llm_cost_estimator-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file mamood_llm_cost_estimator-0.1.0.tar.gz.

File metadata

File hashes

Hashes for mamood_llm_cost_estimator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9dd06f1edaba34a2d16c4d1ccf111447ff813ba600abffe24b78956f7f7fd879
MD5 a0b84d94ede901068fe526911db9780b
BLAKE2b-256 5e06db7043de5b80f8797c456ec78db2d3517845377c408d123c2804698e3eb4

See more details on using hashes here.

File details

Details for the file mamood_llm_cost_estimator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mamood_llm_cost_estimator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 adc48b3b95c1b542174a242e623ccc9bc4c71f29b45a2531e84762a19687b0a0
MD5 29adb5ee701f2969f6ccf14cab106ce7
BLAKE2b-256 ca237fb42a3165df65ff7fc84514c0abf991ee0fae19334364dbde978cfc6ea6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page