Metadata-Version: 2.5
Name: api-cost-tracker
Version: 0.2.3
Summary: Lightweight client for the Synth Insight Labs API cost tracker
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# api-cost-tracker

The client for the Synth Insight Labs API cost tracker. It records what every API
call costs to `https://api.synthinsightlabs.com` without ever breaking the call it
measures. Standard library only; macOS and Linux.

```python
from api_cost_tracker import track, track_tokens, log_call

response = client.messages.create(...)          # any provider SDK
track(response, "anthropic", project="my-project", caller="summarizer")

track_tokens("anthropic", "claude-haiku-4-5", 1200, 300, project="my-project")  # raw HTTP calls
log_call("vercel", service="blob", project="my-project")                       # non-AI APIs
```

- **Providers:** `anthropic`, `openai`, `xai`, `google`, `openrouter` (records
  OpenRouter's billed `usage.cost`).
- **Batch API calls:** pass `service="batches"` to `track()` or `track_tokens()`.
  The server then prices the row at the provider's batch rate (half price).
- **Never raises.** A record that can't be sent goes to an offline buffer at
  `~/.local/share/api_trust_tracker/buffer.db`, and each later successful call
  sends a few buffered rows too. A record that is lost anyway is logged at WARNING.
- **Silent in test suites.** While a pytest test runs, the client sends, buffers and
  drains nothing, so faking `_post_to_server` can't leak rows either way. A test of
  the real send path sets `API_COST_TRACKER_SEND_IN_TESTS=1` and points
  `api_cost_tracker.buffer.BUFFER_DB_PATH` at a temporary file. New in 0.2.3.
- **Configuration:** `COST_TRACKER_API_KEY` (required by the server) and
  `COST_TRACKER_URL` (default `https://api.synthinsightlabs.com`), from the
  environment.

Renamed from `api-trust-tracker` in 0.2.0. That package now only re-exports this
one, and the buffer keeps its old directory so both versions share it.
