Skip to main content

Real-time reasoning-token cost estimation for batched LLM jobs.

Project description

costscope

Real-time reasoning-token cost estimation for batched LLM jobs.

Sample a handful of calls, project the total cost with a confidence interval, confirm before spending the rest. Works with litellm for real API calls or a built-in synthetic backend for tests and demos.

Install

pip install -e .             # core
pip install -e '.[litellm]'  # with litellm backend
pip install -e '.[dev]'      # with pytest

Requires Python 3.10+.

Usage

from costscope import CostEstimator

with CostEstimator(model="o1", total_calls=500, sample_size=20) as ce:
    for prompt in prompts:
        response = ce.completion(messages=[{"role": "user", "content": prompt}])
        ...

The first 20 calls are billed normally and used to build a per-call cost distribution. After that, you'll see a 95% confidence interval over the projected total and a Proceed? [y/N] prompt — decline and subsequent .completion() calls raise EstimationCancelled.

Skip the prompt

  • auto_confirm=True — always proceed
  • threshold_usd=10.0 — auto-proceed when the upper bound is under the threshold
  • confirm_fn=... — supply your own confirmation callback

Synthetic mode

For tests, demos, and dev loops where real API calls would cost money:

from costscope import CostEstimator, SyntheticConfig

cfg = SyntheticConfig(input_median=800, output_median=300, reasoning_median=2000, seed=42)

with CostEstimator(model="o1", total_calls=500, synthetic=True, synthetic_config=cfg) as ce:
    ...

See examples/basic.py for a full runnable example.

Supported models (built-in pricing)

OpenAI o-series (o1, o3, o3-mini, ...), GPT-4o, Claude 4.x (Opus, Sonnet, Haiku). For other models, supply prices via SyntheticConfig or use the litellm-backed mode.

Tests

pytest

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

costscope-0.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

costscope-0.1.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: costscope-0.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for costscope-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6158ef1328e5c11fe2829831af05b20b5b242d80c529964ae4f5e04edf775efb
MD5 9841aabb6004588b97a935800e99e6b6
BLAKE2b-256 ca9c9b11758b37b9fbecb3d2a6b59183b8a2923f0d2b3791cc7500e11c08b4fc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: costscope-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for costscope-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7bf4ba1c41ffb45e9bf5d9151b21c0432c061e944a09d3c6322cd039a66c7a7
MD5 372ff3f6083a514a6e58de0ed054d860
BLAKE2b-256 f635c4df303f3f3c308c6ae9644496932101525cad8b265e90025e891cd90764

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