feat: add hide_zero_spend parameter to litellm_cost()

Adds optional hide_zero_spend parameter (default False) to filter out
models with bash.00 spend from the per-model breakdown. Useful when
free-tier or subscription models (e.g. Ollama Cloud) dominate the
breakdown with high token counts but zero cost.

- Updated litellm_cost() signature with hide_zero_spend parameter
- Added filtering logic in model line builder
- Added hidden model count summary line
- Updated README with parameter documentation
- Bumped version to 1.2.0
This commit is contained in:
rin.kagamine committed 2026-06-13 16:21:49 -04:00
1 parent 51da313e3f
commit 6adcd79c1a
2 files changed
+14 -1

No files matched your search

+5
View File
@@ -10,6 +10,11 @@ Check LiteLLM proxy health and authentication status. Returns which models are h
### `litellm_cost`
Get LiteLLM cost breakdown for a date range. Returns per-model and per-day spend, token counts, cache hit rate, and request stats.
**Parameters:**
- `start_date` (str, required): Start date in YYYY-MM-DD format
- `end_date` (str, required): End date in YYYY-MM-DD format
- `hide_zero_spend` (bool, default false): Hide models with $0.00 spend. Useful when free-tier or subscription models (e.g. Ollama Cloud) dominate the breakdown with high token counts but zero cost.
### `litellm_history`
Get recent LiteLLM request history. Returns the most recent N requests with model, call type, status, duration, token counts, cache hit %, and per-request cost. Useful for understanding which models are being called and how much individual requests cost.
+9 -1
View File
@@ -5,7 +5,7 @@ author_url: https://rin.captcouch.xyz
description: Check LiteLLM proxy health + auth status and get cost breakdowns with configurable timerange. Two functions, that's it.
required_open_webui_version: 0.4.0
requirements: requests
version: 1.1.0
version: 1.2.0
licence: MIT
"""
@@ -119,11 +119,13 @@ class Tools:
self,
start_date: str,
end_date: str,
hide_zero_spend: bool = False,
) -> str:
"""
Get LiteLLM cost breakdown for a date range.
:param start_date: Start date in YYYY-MM-DD format (e.g. "2026-06-01")
:param end_date: End date in YYYY-MM-DD format (e.g. "2026-06-04")
:param hide_zero_spend: Hide models with $0.00 spend (default False). Useful when free-tier or subscription models (e.g. Ollama Cloud) dominate the breakdown with high token counts but zero cost.
Returns formatted cost report with per-model and per-day breakdowns, token counts, cache hit rate, and request stats.
"""
if not self.valves.litellm_master_key:
@@ -205,8 +207,12 @@ class Tools:
# Build model lines sorted by spend
model_lines = []
hidden_count = 0
for model_name in sorted(model_totals, key=lambda k: model_totals[k]["spend"], reverse=True):
mt = model_totals[model_name]
if hide_zero_spend and mt["spend"] == 0:
hidden_count += 1
continue
# Strip common provider prefixes for readability
display = model_name
for prefix in ("gemini/", "openai/", "anthropic/", "mistral/", "cohere/"):
@@ -237,6 +243,8 @@ class Tools:
lines.append("By Model:")
lines.append(f' {"Model":25s} {"Spend":>7s} | {"Requests":>14s} | {"Tokens":>10s}')
lines.extend(model_lines)
if hidden_count > 0:
lines.append(f" ... ({hidden_count} model(s) with $0.00 spend hidden)")
lines.append("")
lines.append("By Date:")
lines.extend(date_lines)