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,6 +10,11 @@ Check LiteLLM proxy health and authentication status. Returns which models are h
|
|||||||
### `litellm_cost`
|
### `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.
|
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`
|
### `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.
|
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.
|
||||||
|
|
||||||
|
|||||||
+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.
|
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
|
required_open_webui_version: 0.4.0
|
||||||
requirements: requests
|
requirements: requests
|
||||||
version: 1.1.0
|
version: 1.2.0
|
||||||
licence: MIT
|
licence: MIT
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -119,11 +119,13 @@ class Tools:
|
|||||||
self,
|
self,
|
||||||
start_date: str,
|
start_date: str,
|
||||||
end_date: str,
|
end_date: str,
|
||||||
|
hide_zero_spend: bool = False,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""
|
"""
|
||||||
Get LiteLLM cost breakdown for a date range.
|
Get LiteLLM cost breakdown for a date range.
|
||||||
:param start_date: Start date in YYYY-MM-DD format (e.g. "2026-06-01")
|
: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 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.
|
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:
|
if not self.valves.litellm_master_key:
|
||||||
@@ -205,8 +207,12 @@ class Tools:
|
|||||||
|
|
||||||
# Build model lines sorted by spend
|
# Build model lines sorted by spend
|
||||||
model_lines = []
|
model_lines = []
|
||||||
|
hidden_count = 0
|
||||||
for model_name in sorted(model_totals, key=lambda k: model_totals[k]["spend"], reverse=True):
|
for model_name in sorted(model_totals, key=lambda k: model_totals[k]["spend"], reverse=True):
|
||||||
mt = model_totals[model_name]
|
mt = model_totals[model_name]
|
||||||
|
if hide_zero_spend and mt["spend"] == 0:
|
||||||
|
hidden_count += 1
|
||||||
|
continue
|
||||||
# Strip common provider prefixes for readability
|
# Strip common provider prefixes for readability
|
||||||
display = model_name
|
display = model_name
|
||||||
for prefix in ("gemini/", "openai/", "anthropic/", "mistral/", "cohere/"):
|
for prefix in ("gemini/", "openai/", "anthropic/", "mistral/", "cohere/"):
|
||||||
@@ -237,6 +243,8 @@ class Tools:
|
|||||||
lines.append("By Model:")
|
lines.append("By Model:")
|
||||||
lines.append(f' {"Model":25s} {"Spend":>7s} | {"Requests":>14s} | {"Tokens":>10s}')
|
lines.append(f' {"Model":25s} {"Spend":>7s} | {"Requests":>14s} | {"Tokens":>10s}')
|
||||||
lines.extend(model_lines)
|
lines.extend(model_lines)
|
||||||
|
if hidden_count > 0:
|
||||||
|
lines.append(f" ... ({hidden_count} model(s) with $0.00 spend hidden)")
|
||||||
lines.append("")
|
lines.append("")
|
||||||
lines.append("By Date:")
|
lines.append("By Date:")
|
||||||
lines.extend(date_lines)
|
lines.extend(date_lines)
|
||||||
@@ -406,4 +414,4 @@ class Tools:
|
|||||||
f"{recent_prompt:,} prompt + {recent_completion:,} completion tokens | "
|
f"{recent_prompt:,} prompt + {recent_completion:,} completion tokens | "
|
||||||
f"{recent_failed} failed")
|
f"{recent_failed} failed")
|
||||||
|
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
Reference in new issue
Block a user