Skip to main content

Calculate LLM token costs from llmlite pricing data

Project description

llmcalc

PyPI version Python versions CI License

llmcalc is a typed Python library and CLI for estimating LLM token costs.

Install

pip install llmcalc

What It Does

  • Resolves model pricing from an upstream pricing source.
  • Calculates input, output, and total costs with deterministic decimal rounding.
  • Provides a small Python API and a CLI.
  • Caches pricing data locally (default TTL: 43200 seconds).

Cost Formula

total = (input_tokens * input_price_per_token) + (output_tokens * output_price_per_token)

Pricing is pulled from llmlite model pricing data and cached locally.

Python Quickstart

from llmcalc import cost

result = cost(
    model="gpt-5.1",
    input_tokens=1200,
    output_tokens=800,
)
if result is not None:
    print(result.total_cost, result.currency)

You can also calculate from usage-style objects via usage(...). Async variants are available as cost_async(...) and usage_async(...).

CLI Quickstart

# cost quote from token counts
llmcalc quote --model gpt-5.1 --input 1200 --output 800

# inspect per-token pricing for one model
llmcalc model --model gpt-5.1 --json

# clear local cache
llmcalc cache clear

# show version
llmcalc --version
llmcalc -v

Configuration

  • LLMCALC_CACHE_TIMEOUT: cache TTL in seconds (default 43200)
  • LLMCALC_PRICING_URL: override pricing source URL
  • LLMCALC_CURRENCY: fallback currency label if upstream omits currency

Maintainers

Contributor workflows and release validation live in AGENTS.md.

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

llmcalc-0.1.1.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

llmcalc-0.1.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file llmcalc-0.1.1.tar.gz.

File metadata

  • Download URL: llmcalc-0.1.1.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for llmcalc-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e5a04ab9e886ef741785d7a6a8f05740217dd4243ce45637ce62a9be35c66a19
MD5 66fabae58b0af6c765b84f8d85e745c4
BLAKE2b-256 4faa94348c9c3197fb00b79607eb68c9250c14a9b42ef6412aab72cafed43e34

See more details on using hashes here.

File details

Details for the file llmcalc-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: llmcalc-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for llmcalc-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c0085d0c0f056669799f92373e1b52f43ff96657c09caab517ec5ace70efdf78
MD5 5d4db16beacaa5bbbe791aef315ffeee
BLAKE2b-256 cf5a71055bddb24a21a6f4f7dbe0e136dd4c8f979d979a8afaaf4e6599f27419

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