Minimalist cost tracking function for Open WebUI
A simple, lightweight cost tracking function that monitors token usage and calculates costs for different AI models in Open WebUI. Track your monthly and daily spending with minimal configuration.
Simple Cost Tracker automatically monitors your AI conversations and provides real-time cost information including:
- Monthly cost tracking - Automatically resets each month
- Daily cost tracking - Shows today's spending
- Per-message costs - Individual message cost breakdown
- Token usage - Input and output token counts
- Multi-provider support - Works with OpenAI, Anthropic, Gemini, and more
- 📊 Real-time cost tracking with status messages
- 🗓️ Automatic monthly/daily reset - No manual maintenance
- 🔧 Easy configuration via JSON valve
- 💾 Persistent storage in simple JSON file
- 🎯 Accurate token estimation including memories and system prompts
- 🏷️ Provider prefix support (openai., anthropic., gemini., etc.)
- Download
simple_cost_tracker.py
- In Open WebUI, go to Admin Panel > Functions
- Click Import Function and upload the file
- Enable the function
The function includes pre-configured costs for popular models. Update the Model Costs JSON valve to add or modify pricing:
{
"openai.gpt-4.1-mini": {"input": 0.40, "output": 1.6},
"anthropic.claude-3-5-haiku-latest": {"input": 0.80, "output": 4.0},
"google.gemini-2.5-flash": {"input": 0.30, "output": 2.50}
}
Important: Use the exact model name as shown in Settings > Models. Include connection prefixes if you use them.
For initial costs, edit cost_tracker_data.json
file manually, costs will add up as you use the function.
Once enabled, the cost tracker automatically displays status messages after each AI response:
0.0052 € this message, 0.47 € today, 13.20 € this month. 11746 tokens used (11313 in, 433 out)
Costs are stored in cost_tracker_data.json
with automatic:
- Monthly reset on the 1st of each month
- Daily reset at midnight
- Persistent tracking across sessions
- Input token estimation includes memories, system prompts, and full context
- Output token estimation based on assistant response content
- Costs calculated using standard pricing per 1M tokens (EUR)
- Unknown models default to 0 cost (for local models)
Unlike complex cost trackers that require API keys and external connections, Simple Cost Tracker:
- ✅ No API keys required
- ✅ No external dependencies
- ✅ Automatic operation
- ✅ Minimal configuration
- ✅ Local storage only