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:
1 parent
51da313e3f
commit
6adcd79c1a
2 files changed
+15
-2
No files matched your search
+10
-2
@@ -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)
|
||||
@@ -406,4 +414,4 @@ class Tools:
|
||||
f"{recent_prompt:,} prompt + {recent_completion:,} completion tokens | "
|
||||
f"{recent_failed} failed")
|
||||
|
||||
return "\n".join(lines)
|
||||
return "\n".join(lines)
|
||||
Reference in new issue
Block a user