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
/modelsendpoint 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
-
Set your version in
pyproject.toml. -
Build distributions:
uv build -
Publish (token-based):
uv publish --token <PYPI_TOKEN>
Project owner: Amirhossein Mahmoudi (@ammahmoudi)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mamood_llm_cost_estimator-0.1.0.tar.gz.
File metadata
- Download URL: mamood_llm_cost_estimator-0.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dd06f1edaba34a2d16c4d1ccf111447ff813ba600abffe24b78956f7f7fd879
|
|
| MD5 |
a0b84d94ede901068fe526911db9780b
|
|
| BLAKE2b-256 |
5e06db7043de5b80f8797c456ec78db2d3517845377c408d123c2804698e3eb4
|
File details
Details for the file mamood_llm_cost_estimator-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mamood_llm_cost_estimator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
adc48b3b95c1b542174a242e623ccc9bc4c71f29b45a2531e84762a19687b0a0
|
|
| MD5 |
29adb5ee701f2969f6ccf14cab106ce7
|
|
| BLAKE2b-256 |
ca237fb42a3165df65ff7fc84514c0abf991ee0fae19334364dbde978cfc6ea6
|