Skip to main content

fiscallm

Limit AI usage by subscription plan, and track the AI cost of each user of your app against their subscription revenue from RevenueCat, Stripe or any billing system. Zero dependencies, Python 3.9+.

The SDK never sits in the path of your AI calls: tracking only queues an event, a background thread sends batches, and it never raises. Prompts and responses are never sent, only token counts.

Pricing a new app? The free pricing planner gives the margin per plan, what a heavy user costs, a monthly AI limit per plan and the free tier you can afford.

pip install fiscallm
import os
from fiscallm import Meter

meter = Meter(api_key=os.environ["FISCALLM_KEY"])  # one per process

# user_id: the same ID your billing knows the user by (RevenueCat app user ID,
# or metadata.user_id on the Stripe subscription).
res = openai_client.chat.completions.create(model=model, messages=messages)
meter.track_openai(res, user_id=user_id, feature="chat")

meter.track_anthropic(message, user_id=user_id)
meter.track_gemini(result, user_id=user_id)

# Streams (sync or async): iterate the returned stream.
stream = meter.track_stream(
    openai_client.chat.completions.create(model=model, messages=messages, stream=True,
                                          stream_options={"include_usage": True}),
    user_id=user_id,
)

# Priced per unit (FiscaLLM knows the price): minutes, seconds, characters, images
meter.track(user_id=user_id, provider="openai", model="whisper-1", units=12.5, unit="minute")
meter.track(user_id=user_id, provider="google", model="veo-3.1-fast-generate-preview",
            units=8, unit="second", variant="1080p")

# Anything else: the exact cost
meter.track(user_id=user_id, provider="fal", model="flux-pro", cost_usd=0.05)

# Not on RevenueCat or Stripe? Report payments yourself:
meter.track_revenue(id=invoice_id, user_id=user_id, type="renewal", amount_usd=9.99, fee_pct=0.15)

# Pay-per-job apps (credits held, then charged or returned): tag the job's
# calls, report the outcome, and the Jobs page shows the cost of refunded
# or never-resolved jobs per user. Track a failed job's cost too if the
# provider still billed it.
meter.track_job(job_id=job_id, user_id=user_id, status="pending")
meter.track(user_id=user_id, provider="fal", model="veo-3", units=15, unit="second", job_id=job_id)
meter.track_job(job_id=job_id, user_id=user_id, status="captured")   # or "refunded"

# Serverless (AWS Lambda, Cloud Functions): before returning
meter.flush()          # or: await meter.aflush()

Limits by plan

Give each plan its own AI allowance on the app's Limits page (for example free: 10 AI calls a day; pro_monthly: 500 a month; paid: $8 of AI a month). FiscaLLM knows each user's plan from RevenueCat or Stripe. Ask before each AI call:

r = meter.check(user_id)            # await meter.acheck(user_id) in async code
if not r.allow:
    return paywall(plan=r.plan, resets_at=r.limits[0].resets_at if r.limits else None)

res = client.chat.completions.create(model=model, messages=messages)
meter.track_openai(res, user_id=user_id)
remaining = r.limits[0].remaining - 1 if r.limits else None   # "3 left today"

Each entry of r.limits has period ("day", "month" or "total"), unit ("requests" or "usd"), limit, used, remaining and resets_at. Your own plan names: meter.check(user_id, plan="team"). The answer is cached for 5 seconds, and each tracked call is counted against it at once. Docs

OpenAI-compatible APIs work with meter.track_openai(res, user_id=user_id, provider="groq").

Docs: https://fiscallm.com/docs

Metadata

Release files for fiscallm 0.7.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 fiscallm 0.7.1
File Size Uploaded Provenance Actions
fiscallm-0.7.1.tar.gz 15.9 kB Without provenance Details for fiscallm-0.7.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fiscallm 0.7.1
File Interpreter ABI Platform Actions
fiscallm-0.7.1-py3-none-any.whl Python 3 none any Details for fiscallm-0.7.1-py3-none-any.whl

Total release size: 28.9 kB

Release files / fiscallm-0.7.1.tar.gz

Download URL fiscallm-0.7.1.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
db4eeb731707295d8e6c24e5790bc6fc9e641aa0277086c30c2bda632a05219d
BLAKE2b-256 checksum
How to use checksums
3ae6e705f2aace49ab2c43100407d0a3c36c054752516b2a70f8d2c043e78506
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Release files / fiscallm-0.7.1-py3-none-any.whl

Download URL fiscallm-0.7.1-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7669dcd25f4552cc96cb8ea56a37b5965f1fe07a82de63da20db9571697463dd
BLAKE2b-256 checksum
How to use checksums
8c310b47fee2056874f7ad9cce547529419bb3b0a8b4c41f97197f6b4d3dc38e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Security for fiscallm 0.7.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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