Metadata-Version: 2.4
Name: mintlyr
Version: 0.2.0
Summary: Track AI cost per feature and per user. Zero dependencies.
License: MIT
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# mintlyr (Python)

Track what each AI feature and each user costs. No dependencies; Python 3.9+.

```python
import mintlyr
from openai import OpenAI

mintlyr.init(api_key="ml_live_...")
client = OpenAI()

reply = mintlyr.track_ai(
    feature="summarize",
    provider="openai",
    user_id="user_123",  # hashed before it leaves your server
    call=lambda: client.chat.completions.create(model="gpt-5", messages=[...]),
)
```

Async: `await mintlyr.atrack_ai(feature=..., call=async_fn)`.

- Returns exactly what your call returns; errors from your call propagate unchanged.
- Tracking never raises into or blocks your code. Events are batched and sent in the background.
- In serverless functions or short scripts call `mintlyr.flush()` before exiting.
- `init(..., local_mode=True)` tracks nothing, useful in tests.
- **Hard budget caps:** create a budget rule with "hard stop" on in the dashboard. Once the feature's spend reaches the limit, `track_ai` does not call the provider. It runs your `fallback=` function if you pass one, otherwise it raises `mintlyr.BudgetExceededError`.
  The cap status is refreshed about every 30 seconds in the background, so spend can overshoot the limit by a short window. The very first call for a feature is always allowed, and if the budget check itself fails your call is never blocked.
- Works with OpenAI, Anthropic and Gemini response objects (or plain dicts).

Install: `pip install mintlyr`.
