Skip to main content

ai-token-pricing

Token economics for AI products. Compute your real blended token cost, validate that a subscription plan is profitable (SAFE / WARNING / UNSAFE), find the maximum quota you can safely include, and price overage so heavy users never erase your margin.

  • Zero dependencies — pure Python, Decimal money math, safe to vendor anywhere.
  • Blended cost from separate input/output prices and your real input:output ratio.
  • validate_plan() — the "never lose money" guard rail, accounting for payment and platform fees.
  • Max safe included quota + overage break-even price in one call.
  • CLI for quick checks without writing code.
  • Prefer a UI? Use the free calculator: https://tokenkit.tingstudioai.com/calculator

Install

pip install ai-token-pricing

Python 3.8+. No third-party dependencies.

Library API

blended_cost(input_per_m, output_per_m, io_ratio=4) -> Decimal

Blended backend cost per 1M tokens for a traffic mix.

Plan(price, included_tokens_m, overage_per_m)

A hybrid plan: fixed monthly fee, included quota (in millions of tokens), and an overage price per 1M.

validate_plan(plan, blended_cost_per_m, ...) -> PlanCheck

Parameter Default Meaning
payment_fee_pct 0.029 Payment processor share.
platform_fee_pct 0.0 Merchant-of-record cut.
target_margin 0.30 Minimum margin.
overage_markup 1.6 Required overage price / cost ratio.

Returns status (SAFE / WARNING / UNSAFE), max_safe_included_m, overage_margin_pct, break_even_overage_price, warnings.

CLI

ai-token-pricing tiers ai-token-pricing blended --input 0.20 --output 1.20 --ratio 4 ai-token-pricing validate --tier budget --price 19 --included 10 --overage 1.50 ai-token-pricing max-quota --price 19 --tier smart --platform-fee 5

The validate command exits non-zero on UNSAFE, so you can fail a deploy on a bad price change.

Free calculator

https://tokenkit.tingstudioai.com/calculator

Need the rest of the billing stack?

The production billing engine (Stripe Metered Billing, idempotent MeterEvents, retries, circuit breaker, fallback queue, webhook verification, weighted quotas, hard USD caps, rate limiting, anomaly throttling, audit log) ships as the paid AI SaaS Token Billing Kit.

License

MIT — see LICENSE. Independent project; not affiliated with Stripe, OpenAI, Anthropic, DeepSeek, or Google.

Metadata

Release files for ai-token-pricing 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ai-token-pricing 0.1.1
File Size Uploaded Provenance Actions
ai_token_pricing-0.1.1.tar.gz 11.1 kB With provenance Details for ai_token_pricing-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ai-token-pricing 0.1.1
File Interpreter ABI Platform Actions
ai_token_pricing-0.1.1-py3-none-any.whl Python 3 none any Details for ai_token_pricing-0.1.1-py3-none-any.whl

Total release size: 22.2 kB

Release files / ai_token_pricing-0.1.1.tar.gz

Download URL ai_token_pricing-0.1.1.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f8376181c8a6a119ed6cd6f2eb012cb8a4b076b051e2c5b4f2273b59ed7f2935
BLAKE2b-256 checksum
How to use checksums
0a9d27c79dea9a18e57fc40a8d991336451c246577d00ac6c95935ceca3b082d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / ai_token_pricing-0.1.1-py3-none-any.whl

Download URL ai_token_pricing-0.1.1-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8ed1b1850a10e852da0da4ace4d1719e33eb0d87d3563cd76784ba894964c9c
BLAKE2b-256 checksum
How to use checksums
7c4a861fb31c18d72f1776da5615b6e4c013ca814c817ce298c99a0be4fd119a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Security for ai-token-pricing 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ai_token_pricing-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page