Skip to content

ronilaukkarinen/open-webui-simple-cost-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

💰 Open WebUI Simple Cost Tracker

Minimalist cost tracking function for Open WebUI

Open WebUI Python Version

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:

{
  "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

About

A minimalist cost tracking function that tracks token usage and costs per model

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages