Token Usage & Cost Tracking
Track token consumption per model and session. Set daily budgets to control spending. Check stats from Telegram with /cost.
How It Works
- Every LLM call records input and output tokens to the
token_usageSQLite table - Each record includes: model name, session ID, token counts, and timestamp
- Optionally, set a daily token budget that blocks LLM calls once exceeded
- Budget resets automatically at midnight UTC
Configuration
| Key | Type | Default | Description |
|---|---|---|---|
daily_token_budget | integer | null | Maximum total tokens (input + output) per day. Null = unlimited. |
config.toml
[state]
daily_token_budget = 1000000 # 1M tokens per dayBudget Scope
The daily budget is global โ it counts all tokens across all sessions and models. When exceeded, LLM calls return an error until midnight UTC.
Telegram /cost Command
Send /cost in Telegram to view usage statistics:
text
Token usage (last 24h):
Input: 12,450 tokens
Output: 8,230 tokens
Token usage (last 7d):
Input: 87,320 tokens
Output: 52,180 tokens
Top models (7d):
gemini-3-flash-preview: 98,400 tokens
gemini-3-pro-preview: 41,100 tokensDatabase Schema
| Key | Type | Default | Description |
|---|---|---|---|
id | INTEGER PK | auto | Auto-incrementing primary key |
session_id | TEXT | โ | Which user/chat session made the call |
model | TEXT | โ | Which LLM model was used |
input_tokens | INTEGER | โ | Tokens sent to the model |
output_tokens | INTEGER | โ | Tokens generated by the model |
created_at | TEXT | now | UTC timestamp of the call |
What’s Tracked
- Input tokens (context + user message) per LLM call
- Output tokens (model response) per LLM call
- Model name for per-model breakdowns
- Session ID for per-user tracking
- Timestamp for time-windowed queries (24h, 7d)