Spend Tracking
How SpendLil calculates and tracks your AI costs at three levels of granularity.
SpendLil tracks spend at three levels: per-request detail, daily counters for alerting, and monthly summaries for dashboard charts.
How Cost Is Calculated
On every proxied request, SpendLil extracts token counts from the provider's response body and calculates cost using the model pricing table.
| Provider | Input Token Field | Output Token Field |
|---|---|---|
| OpenAI | response.usage.prompt_tokens | response.usage.completion_tokens |
| Anthropic | response.usage.input_tokens | response.usage.output_tokens |
| response.usageMetadata.promptTokenCount | response.usageMetadata.candidatesTokenCount |
Cost = (input tokens × input price) + (output tokens × output price), converted from USD to your account currency at the configured exchange rate (default: 0.79 GBP/USD).
Three Levels of Tracking
1. Usage Records (per-request)
Every proxied request creates a usage record with full detail: account, key, provider, model, tokens in/out, estimated cost, latency, and status code. These records have a 90-day TTL by default (configurable) and power the usage explorer in the dashboard.
2. Daily Spend (atomic counters)
On each request, SpendLil atomically increments a daily spend counter for your account. This counter is checked against your threshold rules to fire alerts. Because it's atomically updated, it's always accurate — even under high concurrency.
3. Spend Summaries (monthly roll-ups)
A background process periodically aggregates usage records into monthly summaries per provider. These summaries include total requests, total tokens, total cost, and a model breakdown. They power the dashboard charts and never expire.
Currency
All costs are displayed in your account currency (GBP by default). The exchange rate is configurable in your account settings. Live exchange rate support is planned for a future release.
Data Retention
Usage records auto-expire after 90 days (configurable per account). Monthly summaries are retained indefinitely. Daily spend counters expire after 90 days.