https://github.com/rollecode/open-webui-simple-cost-tracker
A minimalist cost tracking function that tracks token usage and costs per model
https://github.com/rollecode/open-webui-simple-cost-tracker
ai open-webui openai openai-api openai-functions
Last synced: 27 days ago
JSON representation
A minimalist cost tracking function that tracks token usage and costs per model
- Host: GitHub
- URL: https://github.com/rollecode/open-webui-simple-cost-tracker
- Owner: rollecode
- Created: 2025-07-08T14:12:20.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-08-14T10:34:34.000Z (10 months ago)
- Last Synced: 2026-05-02T13:33:31.274Z (28 days ago)
- Topics: ai, open-webui, openai, openai-api, openai-functions
- Language: Python
- Homepage:
- Size: 95.7 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# 💰 Open WebUI Simple Cost Tracker
### Minimalist cost tracking function for [Open WebUI](https://github.com/open-webui/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.
## ✨ What it does
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
## 🚀 Features
- 📊 **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.)
## 📋 Installation
1. Download `simple_cost_tracker.py`
2. In Open WebUI, go to **Admin Panel > Functions**
3. Click **Import Function** and upload the file
4. Enable the function
## ⚙️ Configuration
The function includes pre-configured costs for popular models. Update the **Model Costs JSON** valve to add or modify pricing:
```json
{
"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.
## 💡 Usage
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)
```
## 📁 Data Storage
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
## 🛠️ Technical Details
- **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)
## 🆚 Comparison
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**