AI Provider Tracker
AI Provider Tracker is a Python library for tracking AI provider usage and estimating per-generation costs across heterogeneous providers.
It is designed for apps that already call providers such as FAL.AI and OpenRouter, but need a centralized way to:
- normalize usage metadata
- calculate request/generation costs
- store raw request/response payloads for auditability
- persist optional local analytics in SQLite
- use bundled pricing snapshots without calling pricing APIs at runtime
Installation
pip install ai-provider-tracker
Optional FastAPI dependencies for the legacy model registry API:
pip install "ai-provider-tracker[api]"
Cost Tracking
Use your provider SDK as usual, then pass the request and response to the tracker.
from ai_provider_tracker import CostTracker
tracker = CostTracker()
event = tracker.track_generation(
provider="fal",
model="fal-ai/flux/dev",
request={"prompt": "A cyberpunk city", "num_images": 2},
response={"images": [{"url": "a"}, {"url": "b"}]},
)
print(event.cost.total) # 0.050
print(event.cost.source) # public_snapshot
print(event.cost.confidence) # high
print(event.cost.breakdown)
Enable local SQLite persistence:
tracker = CostTracker(sqlite_path="ai_usage.sqlite")
This stores generation events with normalized usage, cost breakdown, raw request, raw response, and metadata.
OpenRouter
For OpenRouter, provider-reported usage cost is preferred when present:
event = tracker.track_generation(
provider="openrouter",
model="anthropic/claude-sonnet-4.5",
request={"messages": [{"role": "user", "content": "Hello"}]},
response={
"usage": {
"prompt_tokens": 1200,
"completion_tokens": 800,
"cost": "0.015",
}
},
)
print(event.cost.total) # provider-reported cost
print(event.cost.source) # provider_reported
If usage.cost is not present, the tracker falls back to token-based calculation using the bundled pricing catalog when possible.
Pricing Catalog
The package ships with a bundled JSON pricing catalog:
ai_provider_tracker/data/pricing_catalog.json
Runtime requests do not call pricing APIs. Pricing sync is handled by:
python scripts/sync_pricing_catalog.py
The GitHub Actions workflow .github/workflows/pricing_sync.yml runs daily and commits the catalog only when prices actually change.
Legacy Model Registry
This package still includes the original OpenRouter model registry APIs:
from ai_provider_tracker import LLMIndexSync
client = LLMIndexSync(mode="json")
models = client.get_cheapest(limit=5)
The old import path remains available temporarily:
from openrouter_insights import CostTracker
New code should use:
from ai_provider_tracker import CostTracker
Accuracy Contract
Cost values are intended for product analytics, internal attribution, and budget monitoring.
- FAL.AI costs are locally estimated from pricing snapshots and normalized request/response metadata.
- OpenRouter costs use provider-reported cost when available.
- Public bundled pricing is a reference snapshot, not a guarantee of account-specific billing.
For invoice-grade accounting, reconcile against provider billing/usage APIs.
License
MIT
Metadata
Release files for ai-provider-tracker 0.7.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ai_provider_tracker-0.7.5.tar.gz | 21.9 kB | Without provenance | Details for ai_provider_tracker-0.7.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ai_provider_tracker-0.7.5-py3-none-any.whl | Python 3 | none | any | Details for ai_provider_tracker-0.7.5-py3-none-any.whl |
Total release size: 53.5 kB
Release files / ai_provider_tracker-0.7.5.tar.gz
| Download URL | ai_provider_tracker-0.7.5.tar.gz |
|---|---|
| Size | 21.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d1e3968c06df11aba743ed768f44b570b159038ecd2fb1c418705d67e37c208f
|
|
BLAKE2b-256 checksum How to use checksums |
bf6eb17d2cebbb7e5f2db90de24e63cb407a09b8e0b73e079541caa94b4df363
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.12.3 Linux/6.17.0-1013-azure
|
Release files / ai_provider_tracker-0.7.5-py3-none-any.whl
| Download URL | ai_provider_tracker-0.7.5-py3-none-any.whl |
|---|---|
| Size | 31.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f43dc5fd143adaa4539b709a93c41d7ec774a3ee79ec92a02d024ed2cf42b73e
|
|
BLAKE2b-256 checksum How to use checksums |
2583265c5bf7418424e1025d7c675454b46bfecca4feaba9d8392225ee09fbdc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.12.3 Linux/6.17.0-1013-azure
|
Security for ai-provider-tracker 0.7.5
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.